@@ -23,229 +23,229 @@ |
||
23 | 23 | |
24 | 24 | abstract class TaskBase implements ITask |
25 | 25 | { |
26 | - /** @var SiteConfiguration */ |
|
27 | - private $siteConfiguration; |
|
28 | - /** @var IEmailHelper */ |
|
29 | - private $emailHelper; |
|
30 | - /** @var HttpHelper */ |
|
31 | - private $httpHelper; |
|
32 | - /** @var WikiTextHelper */ |
|
33 | - private $wikiTextHelper; |
|
34 | - /** @var ILocationProvider */ |
|
35 | - private $locationProvider; |
|
36 | - /** @var IXffTrustProvider */ |
|
37 | - private $xffTrustProvider; |
|
38 | - /** @var IRDnsProvider */ |
|
39 | - private $rdnsProvider; |
|
40 | - /** @var IAntiSpoofProvider */ |
|
41 | - private $antiSpoofProvider; |
|
42 | - /** @var IOAuthProtocolHelper */ |
|
43 | - private $oauthHelper; |
|
44 | - /** @var PdoDatabase */ |
|
45 | - private $database; |
|
46 | - /** @var IrcNotificationHelper */ |
|
47 | - private $notificationHelper; |
|
48 | - /** @var TorExitProvider */ |
|
49 | - private $torExitProvider; |
|
50 | - |
|
51 | - /** |
|
52 | - * @return IEmailHelper |
|
53 | - */ |
|
54 | - final public function getEmailHelper() |
|
55 | - { |
|
56 | - return $this->emailHelper; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * @param IEmailHelper $emailHelper |
|
61 | - */ |
|
62 | - final public function setEmailHelper($emailHelper) |
|
63 | - { |
|
64 | - $this->emailHelper = $emailHelper; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * @return HttpHelper |
|
69 | - */ |
|
70 | - final public function getHttpHelper() |
|
71 | - { |
|
72 | - return $this->httpHelper; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * @param HttpHelper $httpHelper |
|
77 | - */ |
|
78 | - final public function setHttpHelper($httpHelper) |
|
79 | - { |
|
80 | - $this->httpHelper = $httpHelper; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * @return WikiTextHelper |
|
85 | - */ |
|
86 | - final public function getWikiTextHelper() |
|
87 | - { |
|
88 | - return $this->wikiTextHelper; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @param WikiTextHelper $wikiTextHelper |
|
93 | - */ |
|
94 | - final public function setWikiTextHelper($wikiTextHelper) |
|
95 | - { |
|
96 | - $this->wikiTextHelper = $wikiTextHelper; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @return ILocationProvider |
|
101 | - */ |
|
102 | - final public function getLocationProvider() |
|
103 | - { |
|
104 | - return $this->locationProvider; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @param ILocationProvider $locationProvider |
|
109 | - */ |
|
110 | - final public function setLocationProvider(ILocationProvider $locationProvider) |
|
111 | - { |
|
112 | - $this->locationProvider = $locationProvider; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * @return IXffTrustProvider |
|
117 | - */ |
|
118 | - final public function getXffTrustProvider() |
|
119 | - { |
|
120 | - return $this->xffTrustProvider; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * @param IXffTrustProvider $xffTrustProvider |
|
125 | - */ |
|
126 | - final public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider) |
|
127 | - { |
|
128 | - $this->xffTrustProvider = $xffTrustProvider; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * @return IRDnsProvider |
|
133 | - */ |
|
134 | - final public function getRdnsProvider() |
|
135 | - { |
|
136 | - return $this->rdnsProvider; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @param IRDnsProvider $rdnsProvider |
|
141 | - */ |
|
142 | - public function setRdnsProvider($rdnsProvider) |
|
143 | - { |
|
144 | - $this->rdnsProvider = $rdnsProvider; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @return IAntiSpoofProvider |
|
149 | - */ |
|
150 | - public function getAntiSpoofProvider() |
|
151 | - { |
|
152 | - return $this->antiSpoofProvider; |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * @param IAntiSpoofProvider $antiSpoofProvider |
|
157 | - */ |
|
158 | - public function setAntiSpoofProvider($antiSpoofProvider) |
|
159 | - { |
|
160 | - $this->antiSpoofProvider = $antiSpoofProvider; |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * @return PdoDatabase |
|
165 | - */ |
|
166 | - final public function getDatabase() |
|
167 | - { |
|
168 | - return $this->database; |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @param PdoDatabase $database |
|
173 | - */ |
|
174 | - final public function setDatabase($database) |
|
175 | - { |
|
176 | - $this->database = $database; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * @return IOAuthProtocolHelper |
|
181 | - */ |
|
182 | - public function getOAuthProtocolHelper() |
|
183 | - { |
|
184 | - return $this->oauthHelper; |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * @param IOAuthProtocolHelper $oauthProtocolHelper |
|
189 | - */ |
|
190 | - public function setOAuthProtocolHelper($oauthProtocolHelper) |
|
191 | - { |
|
192 | - $this->oauthHelper = $oauthProtocolHelper; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * @return void |
|
197 | - */ |
|
198 | - abstract public function execute(); |
|
199 | - |
|
200 | - /** |
|
201 | - * @return IrcNotificationHelper |
|
202 | - */ |
|
203 | - public function getNotificationHelper() |
|
204 | - { |
|
205 | - return $this->notificationHelper; |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * @param IrcNotificationHelper $notificationHelper |
|
210 | - */ |
|
211 | - public function setNotificationHelper($notificationHelper) |
|
212 | - { |
|
213 | - $this->notificationHelper = $notificationHelper; |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * @return TorExitProvider |
|
218 | - */ |
|
219 | - public function getTorExitProvider() |
|
220 | - { |
|
221 | - return $this->torExitProvider; |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * @param TorExitProvider $torExitProvider |
|
226 | - */ |
|
227 | - public function setTorExitProvider($torExitProvider) |
|
228 | - { |
|
229 | - $this->torExitProvider = $torExitProvider; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * Gets the site configuration object |
|
234 | - * |
|
235 | - * @return SiteConfiguration |
|
236 | - */ |
|
237 | - final protected function getSiteConfiguration() |
|
238 | - { |
|
239 | - return $this->siteConfiguration; |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * Sets the site configuration object for this page |
|
244 | - * |
|
245 | - * @param SiteConfiguration $configuration |
|
246 | - */ |
|
247 | - final public function setSiteConfiguration($configuration) |
|
248 | - { |
|
249 | - $this->siteConfiguration = $configuration; |
|
250 | - } |
|
26 | + /** @var SiteConfiguration */ |
|
27 | + private $siteConfiguration; |
|
28 | + /** @var IEmailHelper */ |
|
29 | + private $emailHelper; |
|
30 | + /** @var HttpHelper */ |
|
31 | + private $httpHelper; |
|
32 | + /** @var WikiTextHelper */ |
|
33 | + private $wikiTextHelper; |
|
34 | + /** @var ILocationProvider */ |
|
35 | + private $locationProvider; |
|
36 | + /** @var IXffTrustProvider */ |
|
37 | + private $xffTrustProvider; |
|
38 | + /** @var IRDnsProvider */ |
|
39 | + private $rdnsProvider; |
|
40 | + /** @var IAntiSpoofProvider */ |
|
41 | + private $antiSpoofProvider; |
|
42 | + /** @var IOAuthProtocolHelper */ |
|
43 | + private $oauthHelper; |
|
44 | + /** @var PdoDatabase */ |
|
45 | + private $database; |
|
46 | + /** @var IrcNotificationHelper */ |
|
47 | + private $notificationHelper; |
|
48 | + /** @var TorExitProvider */ |
|
49 | + private $torExitProvider; |
|
50 | + |
|
51 | + /** |
|
52 | + * @return IEmailHelper |
|
53 | + */ |
|
54 | + final public function getEmailHelper() |
|
55 | + { |
|
56 | + return $this->emailHelper; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * @param IEmailHelper $emailHelper |
|
61 | + */ |
|
62 | + final public function setEmailHelper($emailHelper) |
|
63 | + { |
|
64 | + $this->emailHelper = $emailHelper; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * @return HttpHelper |
|
69 | + */ |
|
70 | + final public function getHttpHelper() |
|
71 | + { |
|
72 | + return $this->httpHelper; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * @param HttpHelper $httpHelper |
|
77 | + */ |
|
78 | + final public function setHttpHelper($httpHelper) |
|
79 | + { |
|
80 | + $this->httpHelper = $httpHelper; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * @return WikiTextHelper |
|
85 | + */ |
|
86 | + final public function getWikiTextHelper() |
|
87 | + { |
|
88 | + return $this->wikiTextHelper; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @param WikiTextHelper $wikiTextHelper |
|
93 | + */ |
|
94 | + final public function setWikiTextHelper($wikiTextHelper) |
|
95 | + { |
|
96 | + $this->wikiTextHelper = $wikiTextHelper; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @return ILocationProvider |
|
101 | + */ |
|
102 | + final public function getLocationProvider() |
|
103 | + { |
|
104 | + return $this->locationProvider; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @param ILocationProvider $locationProvider |
|
109 | + */ |
|
110 | + final public function setLocationProvider(ILocationProvider $locationProvider) |
|
111 | + { |
|
112 | + $this->locationProvider = $locationProvider; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * @return IXffTrustProvider |
|
117 | + */ |
|
118 | + final public function getXffTrustProvider() |
|
119 | + { |
|
120 | + return $this->xffTrustProvider; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * @param IXffTrustProvider $xffTrustProvider |
|
125 | + */ |
|
126 | + final public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider) |
|
127 | + { |
|
128 | + $this->xffTrustProvider = $xffTrustProvider; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * @return IRDnsProvider |
|
133 | + */ |
|
134 | + final public function getRdnsProvider() |
|
135 | + { |
|
136 | + return $this->rdnsProvider; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @param IRDnsProvider $rdnsProvider |
|
141 | + */ |
|
142 | + public function setRdnsProvider($rdnsProvider) |
|
143 | + { |
|
144 | + $this->rdnsProvider = $rdnsProvider; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @return IAntiSpoofProvider |
|
149 | + */ |
|
150 | + public function getAntiSpoofProvider() |
|
151 | + { |
|
152 | + return $this->antiSpoofProvider; |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * @param IAntiSpoofProvider $antiSpoofProvider |
|
157 | + */ |
|
158 | + public function setAntiSpoofProvider($antiSpoofProvider) |
|
159 | + { |
|
160 | + $this->antiSpoofProvider = $antiSpoofProvider; |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * @return PdoDatabase |
|
165 | + */ |
|
166 | + final public function getDatabase() |
|
167 | + { |
|
168 | + return $this->database; |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @param PdoDatabase $database |
|
173 | + */ |
|
174 | + final public function setDatabase($database) |
|
175 | + { |
|
176 | + $this->database = $database; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * @return IOAuthProtocolHelper |
|
181 | + */ |
|
182 | + public function getOAuthProtocolHelper() |
|
183 | + { |
|
184 | + return $this->oauthHelper; |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * @param IOAuthProtocolHelper $oauthProtocolHelper |
|
189 | + */ |
|
190 | + public function setOAuthProtocolHelper($oauthProtocolHelper) |
|
191 | + { |
|
192 | + $this->oauthHelper = $oauthProtocolHelper; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * @return void |
|
197 | + */ |
|
198 | + abstract public function execute(); |
|
199 | + |
|
200 | + /** |
|
201 | + * @return IrcNotificationHelper |
|
202 | + */ |
|
203 | + public function getNotificationHelper() |
|
204 | + { |
|
205 | + return $this->notificationHelper; |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * @param IrcNotificationHelper $notificationHelper |
|
210 | + */ |
|
211 | + public function setNotificationHelper($notificationHelper) |
|
212 | + { |
|
213 | + $this->notificationHelper = $notificationHelper; |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * @return TorExitProvider |
|
218 | + */ |
|
219 | + public function getTorExitProvider() |
|
220 | + { |
|
221 | + return $this->torExitProvider; |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * @param TorExitProvider $torExitProvider |
|
226 | + */ |
|
227 | + public function setTorExitProvider($torExitProvider) |
|
228 | + { |
|
229 | + $this->torExitProvider = $torExitProvider; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * Gets the site configuration object |
|
234 | + * |
|
235 | + * @return SiteConfiguration |
|
236 | + */ |
|
237 | + final protected function getSiteConfiguration() |
|
238 | + { |
|
239 | + return $this->siteConfiguration; |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * Sets the site configuration object for this page |
|
244 | + * |
|
245 | + * @param SiteConfiguration $configuration |
|
246 | + */ |
|
247 | + final public function setSiteConfiguration($configuration) |
|
248 | + { |
|
249 | + $this->siteConfiguration = $configuration; |
|
250 | + } |
|
251 | 251 | } |
252 | 252 | \ No newline at end of file |
@@ -13,97 +13,97 @@ |
||
13 | 13 | |
14 | 14 | abstract class PagedInternalPageBase extends InternalPageBase |
15 | 15 | { |
16 | - /** @var SearchHelperBase */ |
|
17 | - private $searchHelper; |
|
18 | - private $page; |
|
19 | - private $limit; |
|
20 | - |
|
21 | - /** |
|
22 | - * Sets up the pager with the current page, current limit, and total number of records. |
|
23 | - * |
|
24 | - * @param int $count |
|
25 | - * @param array $formParameters |
|
26 | - */ |
|
27 | - protected function setupPageData($count, $formParameters) |
|
28 | - { |
|
29 | - $page = $this->page; |
|
30 | - $limit = $this->limit; |
|
31 | - |
|
32 | - // The number of pages on the pager to show. Must be odd |
|
33 | - $pageLimit = 9; |
|
34 | - |
|
35 | - $pageData = array( |
|
36 | - // Can the user go to the previous page? |
|
37 | - 'canprev' => $page != 1, |
|
38 | - // Can the user go to the next page? |
|
39 | - 'cannext' => ($page * $limit) < $count, |
|
40 | - // Maximum page number |
|
41 | - 'maxpage' => max(1, ceil($count / $limit)), |
|
42 | - // Limit to the number of pages to display |
|
43 | - 'pagelimit' => $pageLimit, |
|
44 | - ); |
|
45 | - |
|
46 | - // number of pages either side of the current to show |
|
47 | - $pageMargin = (($pageLimit - 1) / 2); |
|
48 | - |
|
49 | - // Calculate the number of pages either side to show - this is for situations like: |
|
50 | - // [1] [2] [[3]] [4] [5] [6] [7] [8] [9] - where you can't just use the page margin calculated |
|
51 | - $pageData['lowpage'] = max(1, $page - $pageMargin); |
|
52 | - $pageData['hipage'] = min($pageData['maxpage'], $page + $pageMargin); |
|
53 | - $pageCount = ($pageData['hipage'] - $pageData['lowpage']) + 1; |
|
54 | - |
|
55 | - if ($pageCount < $pageLimit) { |
|
56 | - if ($pageData['lowpage'] == 1 && $pageData['hipage'] < $pageData['maxpage']) { |
|
57 | - $pageData['hipage'] = min($pageLimit, $pageData['maxpage']); |
|
58 | - } |
|
59 | - elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) { |
|
60 | - $pageData['lowpage'] = max(1, $pageData['maxpage'] - $pageLimit + 1); |
|
61 | - } |
|
62 | - } |
|
63 | - |
|
64 | - // Put the range of pages into the page data |
|
65 | - $pageData['pages'] = range($pageData['lowpage'], $pageData['hipage']); |
|
66 | - |
|
67 | - $this->assign("pagedata", $pageData); |
|
68 | - |
|
69 | - $this->assign("limit", $limit); |
|
70 | - $this->assign("page", $page); |
|
71 | - |
|
72 | - $this->setupFormParameters($formParameters); |
|
73 | - } |
|
74 | - |
|
75 | - protected function setSearchHelper(SearchHelperBase $searchHelper) |
|
76 | - { |
|
77 | - $this->searchHelper = $searchHelper; |
|
78 | - } |
|
79 | - |
|
80 | - protected function setupLimits() |
|
81 | - { |
|
82 | - $limit = WebRequest::getInt('limit'); |
|
83 | - if ($limit === null) { |
|
84 | - $limit = 100; |
|
85 | - } |
|
86 | - |
|
87 | - $page = WebRequest::getInt('page'); |
|
88 | - if ($page === null) { |
|
89 | - $page = 1; |
|
90 | - } |
|
91 | - |
|
92 | - $offset = ($page - 1) * $limit; |
|
93 | - |
|
94 | - $this->searchHelper->limit($limit, $offset); |
|
95 | - |
|
96 | - $this->page = $page; |
|
97 | - $this->limit = $limit; |
|
98 | - } |
|
99 | - |
|
100 | - private function setupFormParameters($formParameters) |
|
101 | - { |
|
102 | - $formParameters['limit'] = $this->limit; |
|
103 | - $this->assign('searchParamsUrl', http_build_query($formParameters, '', '&')); |
|
104 | - |
|
105 | - foreach ($formParameters as $key => $value) { |
|
106 | - $this->assign($key, $value); |
|
107 | - } |
|
108 | - } |
|
16 | + /** @var SearchHelperBase */ |
|
17 | + private $searchHelper; |
|
18 | + private $page; |
|
19 | + private $limit; |
|
20 | + |
|
21 | + /** |
|
22 | + * Sets up the pager with the current page, current limit, and total number of records. |
|
23 | + * |
|
24 | + * @param int $count |
|
25 | + * @param array $formParameters |
|
26 | + */ |
|
27 | + protected function setupPageData($count, $formParameters) |
|
28 | + { |
|
29 | + $page = $this->page; |
|
30 | + $limit = $this->limit; |
|
31 | + |
|
32 | + // The number of pages on the pager to show. Must be odd |
|
33 | + $pageLimit = 9; |
|
34 | + |
|
35 | + $pageData = array( |
|
36 | + // Can the user go to the previous page? |
|
37 | + 'canprev' => $page != 1, |
|
38 | + // Can the user go to the next page? |
|
39 | + 'cannext' => ($page * $limit) < $count, |
|
40 | + // Maximum page number |
|
41 | + 'maxpage' => max(1, ceil($count / $limit)), |
|
42 | + // Limit to the number of pages to display |
|
43 | + 'pagelimit' => $pageLimit, |
|
44 | + ); |
|
45 | + |
|
46 | + // number of pages either side of the current to show |
|
47 | + $pageMargin = (($pageLimit - 1) / 2); |
|
48 | + |
|
49 | + // Calculate the number of pages either side to show - this is for situations like: |
|
50 | + // [1] [2] [[3]] [4] [5] [6] [7] [8] [9] - where you can't just use the page margin calculated |
|
51 | + $pageData['lowpage'] = max(1, $page - $pageMargin); |
|
52 | + $pageData['hipage'] = min($pageData['maxpage'], $page + $pageMargin); |
|
53 | + $pageCount = ($pageData['hipage'] - $pageData['lowpage']) + 1; |
|
54 | + |
|
55 | + if ($pageCount < $pageLimit) { |
|
56 | + if ($pageData['lowpage'] == 1 && $pageData['hipage'] < $pageData['maxpage']) { |
|
57 | + $pageData['hipage'] = min($pageLimit, $pageData['maxpage']); |
|
58 | + } |
|
59 | + elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) { |
|
60 | + $pageData['lowpage'] = max(1, $pageData['maxpage'] - $pageLimit + 1); |
|
61 | + } |
|
62 | + } |
|
63 | + |
|
64 | + // Put the range of pages into the page data |
|
65 | + $pageData['pages'] = range($pageData['lowpage'], $pageData['hipage']); |
|
66 | + |
|
67 | + $this->assign("pagedata", $pageData); |
|
68 | + |
|
69 | + $this->assign("limit", $limit); |
|
70 | + $this->assign("page", $page); |
|
71 | + |
|
72 | + $this->setupFormParameters($formParameters); |
|
73 | + } |
|
74 | + |
|
75 | + protected function setSearchHelper(SearchHelperBase $searchHelper) |
|
76 | + { |
|
77 | + $this->searchHelper = $searchHelper; |
|
78 | + } |
|
79 | + |
|
80 | + protected function setupLimits() |
|
81 | + { |
|
82 | + $limit = WebRequest::getInt('limit'); |
|
83 | + if ($limit === null) { |
|
84 | + $limit = 100; |
|
85 | + } |
|
86 | + |
|
87 | + $page = WebRequest::getInt('page'); |
|
88 | + if ($page === null) { |
|
89 | + $page = 1; |
|
90 | + } |
|
91 | + |
|
92 | + $offset = ($page - 1) * $limit; |
|
93 | + |
|
94 | + $this->searchHelper->limit($limit, $offset); |
|
95 | + |
|
96 | + $this->page = $page; |
|
97 | + $this->limit = $limit; |
|
98 | + } |
|
99 | + |
|
100 | + private function setupFormParameters($formParameters) |
|
101 | + { |
|
102 | + $formParameters['limit'] = $this->limit; |
|
103 | + $this->assign('searchParamsUrl', http_build_query($formParameters, '', '&')); |
|
104 | + |
|
105 | + foreach ($formParameters as $key => $value) { |
|
106 | + $this->assign($key, $value); |
|
107 | + } |
|
108 | + } |
|
109 | 109 | } |
@@ -102,7 +102,7 @@ |
||
102 | 102 | $formParameters['limit'] = $this->limit; |
103 | 103 | $this->assign('searchParamsUrl', http_build_query($formParameters, '', '&')); |
104 | 104 | |
105 | - foreach ($formParameters as $key => $value) { |
|
105 | + foreach ($formParameters as $key => $value) { |
|
106 | 106 | $this->assign($key, $value); |
107 | 107 | } |
108 | 108 | } |
@@ -55,8 +55,7 @@ discard block |
||
55 | 55 | if ($pageCount < $pageLimit) { |
56 | 56 | if ($pageData['lowpage'] == 1 && $pageData['hipage'] < $pageData['maxpage']) { |
57 | 57 | $pageData['hipage'] = min($pageLimit, $pageData['maxpage']); |
58 | - } |
|
59 | - elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) { |
|
58 | + } elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) { |
|
60 | 59 | $pageData['lowpage'] = max(1, $pageData['maxpage'] - $pageLimit + 1); |
61 | 60 | } |
62 | 61 | } |
@@ -102,7 +101,7 @@ discard block |
||
102 | 101 | $formParameters['limit'] = $this->limit; |
103 | 102 | $this->assign('searchParamsUrl', http_build_query($formParameters, '', '&')); |
104 | 103 | |
105 | - foreach ($formParameters as $key => $value) { |
|
104 | + foreach ($formParameters as $key => $value) { |
|
106 | 105 | $this->assign($key, $value); |
107 | 106 | } |
108 | 107 | } |
@@ -23,149 +23,149 @@ |
||
23 | 23 | |
24 | 24 | interface ITask |
25 | 25 | { |
26 | - /** |
|
27 | - * @return IEmailHelper |
|
28 | - */ |
|
29 | - public function getEmailHelper(); |
|
30 | - |
|
31 | - /** |
|
32 | - * @param IEmailHelper $emailHelper |
|
33 | - * |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public function setEmailHelper($emailHelper); |
|
37 | - |
|
38 | - /** |
|
39 | - * @return HttpHelper |
|
40 | - */ |
|
41 | - public function getHttpHelper(); |
|
42 | - |
|
43 | - /** |
|
44 | - * @param HttpHelper $httpHelper |
|
45 | - * |
|
46 | - * @return void |
|
47 | - */ |
|
48 | - public function setHttpHelper($httpHelper); |
|
49 | - |
|
50 | - /** |
|
51 | - * @return WikiTextHelper |
|
52 | - */ |
|
53 | - public function getWikiTextHelper(); |
|
54 | - |
|
55 | - /** |
|
56 | - * @param WikiTextHelper $wikiTextHelper |
|
57 | - * |
|
58 | - * @return void |
|
59 | - */ |
|
60 | - public function setWikiTextHelper($wikiTextHelper); |
|
61 | - |
|
62 | - /** |
|
63 | - * @return ILocationProvider |
|
64 | - */ |
|
65 | - public function getLocationProvider(); |
|
66 | - |
|
67 | - /** |
|
68 | - * @param ILocationProvider $locationProvider |
|
69 | - * |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - public function setLocationProvider(ILocationProvider $locationProvider); |
|
73 | - |
|
74 | - /** |
|
75 | - * @return IXffTrustProvider |
|
76 | - */ |
|
77 | - public function getXffTrustProvider(); |
|
78 | - |
|
79 | - /** |
|
80 | - * @param IXffTrustProvider $xffTrustProvider |
|
81 | - * |
|
82 | - * @return void |
|
83 | - */ |
|
84 | - public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider); |
|
85 | - |
|
86 | - /** |
|
87 | - * @return IRDnsProvider |
|
88 | - */ |
|
89 | - public function getRdnsProvider(); |
|
90 | - |
|
91 | - /** |
|
92 | - * @param IRDnsProvider $rdnsProvider |
|
93 | - * |
|
94 | - * @return void |
|
95 | - */ |
|
96 | - public function setRdnsProvider($rdnsProvider); |
|
97 | - |
|
98 | - /** |
|
99 | - * @return IAntiSpoofProvider |
|
100 | - */ |
|
101 | - public function getAntiSpoofProvider(); |
|
102 | - |
|
103 | - /** |
|
104 | - * @param IAntiSpoofProvider $antiSpoofProvider |
|
105 | - * |
|
106 | - * @return void |
|
107 | - */ |
|
108 | - public function setAntiSpoofProvider($antiSpoofProvider); |
|
109 | - |
|
110 | - /** |
|
111 | - * @return PdoDatabase |
|
112 | - */ |
|
113 | - public function getDatabase(); |
|
114 | - |
|
115 | - /** |
|
116 | - * @param PdoDatabase $database |
|
117 | - * |
|
118 | - * @return void |
|
119 | - */ |
|
120 | - public function setDatabase($database); |
|
121 | - |
|
122 | - /** |
|
123 | - * @return IOAuthProtocolHelper |
|
124 | - */ |
|
125 | - public function getOAuthProtocolHelper(); |
|
126 | - |
|
127 | - /** |
|
128 | - * @param IOAuthProtocolHelper $oauthProtocolHelper |
|
129 | - * |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - public function setOAuthProtocolHelper($oauthProtocolHelper); |
|
133 | - |
|
134 | - /** |
|
135 | - * @return void |
|
136 | - */ |
|
137 | - public function execute(); |
|
138 | - |
|
139 | - /** |
|
140 | - * Sets the site configuration object for this page |
|
141 | - * |
|
142 | - * @param SiteConfiguration $configuration |
|
143 | - * |
|
144 | - * @return void |
|
145 | - */ |
|
146 | - public function setSiteConfiguration($configuration); |
|
147 | - |
|
148 | - /** |
|
149 | - * @return IrcNotificationHelper |
|
150 | - */ |
|
151 | - public function getNotificationHelper(); |
|
152 | - |
|
153 | - /** |
|
154 | - * @param IrcNotificationHelper $notificationHelper |
|
155 | - * |
|
156 | - * @return void |
|
157 | - */ |
|
158 | - public function setNotificationHelper($notificationHelper); |
|
159 | - |
|
160 | - /** |
|
161 | - * @return TorExitProvider |
|
162 | - */ |
|
163 | - public function getTorExitProvider(); |
|
164 | - |
|
165 | - /** |
|
166 | - * @param TorExitProvider $torExitProvider |
|
167 | - * |
|
168 | - * @return void |
|
169 | - */ |
|
170 | - public function setTorExitProvider($torExitProvider); |
|
26 | + /** |
|
27 | + * @return IEmailHelper |
|
28 | + */ |
|
29 | + public function getEmailHelper(); |
|
30 | + |
|
31 | + /** |
|
32 | + * @param IEmailHelper $emailHelper |
|
33 | + * |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public function setEmailHelper($emailHelper); |
|
37 | + |
|
38 | + /** |
|
39 | + * @return HttpHelper |
|
40 | + */ |
|
41 | + public function getHttpHelper(); |
|
42 | + |
|
43 | + /** |
|
44 | + * @param HttpHelper $httpHelper |
|
45 | + * |
|
46 | + * @return void |
|
47 | + */ |
|
48 | + public function setHttpHelper($httpHelper); |
|
49 | + |
|
50 | + /** |
|
51 | + * @return WikiTextHelper |
|
52 | + */ |
|
53 | + public function getWikiTextHelper(); |
|
54 | + |
|
55 | + /** |
|
56 | + * @param WikiTextHelper $wikiTextHelper |
|
57 | + * |
|
58 | + * @return void |
|
59 | + */ |
|
60 | + public function setWikiTextHelper($wikiTextHelper); |
|
61 | + |
|
62 | + /** |
|
63 | + * @return ILocationProvider |
|
64 | + */ |
|
65 | + public function getLocationProvider(); |
|
66 | + |
|
67 | + /** |
|
68 | + * @param ILocationProvider $locationProvider |
|
69 | + * |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + public function setLocationProvider(ILocationProvider $locationProvider); |
|
73 | + |
|
74 | + /** |
|
75 | + * @return IXffTrustProvider |
|
76 | + */ |
|
77 | + public function getXffTrustProvider(); |
|
78 | + |
|
79 | + /** |
|
80 | + * @param IXffTrustProvider $xffTrustProvider |
|
81 | + * |
|
82 | + * @return void |
|
83 | + */ |
|
84 | + public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider); |
|
85 | + |
|
86 | + /** |
|
87 | + * @return IRDnsProvider |
|
88 | + */ |
|
89 | + public function getRdnsProvider(); |
|
90 | + |
|
91 | + /** |
|
92 | + * @param IRDnsProvider $rdnsProvider |
|
93 | + * |
|
94 | + * @return void |
|
95 | + */ |
|
96 | + public function setRdnsProvider($rdnsProvider); |
|
97 | + |
|
98 | + /** |
|
99 | + * @return IAntiSpoofProvider |
|
100 | + */ |
|
101 | + public function getAntiSpoofProvider(); |
|
102 | + |
|
103 | + /** |
|
104 | + * @param IAntiSpoofProvider $antiSpoofProvider |
|
105 | + * |
|
106 | + * @return void |
|
107 | + */ |
|
108 | + public function setAntiSpoofProvider($antiSpoofProvider); |
|
109 | + |
|
110 | + /** |
|
111 | + * @return PdoDatabase |
|
112 | + */ |
|
113 | + public function getDatabase(); |
|
114 | + |
|
115 | + /** |
|
116 | + * @param PdoDatabase $database |
|
117 | + * |
|
118 | + * @return void |
|
119 | + */ |
|
120 | + public function setDatabase($database); |
|
121 | + |
|
122 | + /** |
|
123 | + * @return IOAuthProtocolHelper |
|
124 | + */ |
|
125 | + public function getOAuthProtocolHelper(); |
|
126 | + |
|
127 | + /** |
|
128 | + * @param IOAuthProtocolHelper $oauthProtocolHelper |
|
129 | + * |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + public function setOAuthProtocolHelper($oauthProtocolHelper); |
|
133 | + |
|
134 | + /** |
|
135 | + * @return void |
|
136 | + */ |
|
137 | + public function execute(); |
|
138 | + |
|
139 | + /** |
|
140 | + * Sets the site configuration object for this page |
|
141 | + * |
|
142 | + * @param SiteConfiguration $configuration |
|
143 | + * |
|
144 | + * @return void |
|
145 | + */ |
|
146 | + public function setSiteConfiguration($configuration); |
|
147 | + |
|
148 | + /** |
|
149 | + * @return IrcNotificationHelper |
|
150 | + */ |
|
151 | + public function getNotificationHelper(); |
|
152 | + |
|
153 | + /** |
|
154 | + * @param IrcNotificationHelper $notificationHelper |
|
155 | + * |
|
156 | + * @return void |
|
157 | + */ |
|
158 | + public function setNotificationHelper($notificationHelper); |
|
159 | + |
|
160 | + /** |
|
161 | + * @return TorExitProvider |
|
162 | + */ |
|
163 | + public function getTorExitProvider(); |
|
164 | + |
|
165 | + /** |
|
166 | + * @param TorExitProvider $torExitProvider |
|
167 | + * |
|
168 | + * @return void |
|
169 | + */ |
|
170 | + public function setTorExitProvider($torExitProvider); |
|
171 | 171 | } |
172 | 172 | \ No newline at end of file |
@@ -17,77 +17,77 @@ |
||
17 | 17 | |
18 | 18 | abstract class XmlApiPageBase extends ApiPageBase implements IXmlApiAction |
19 | 19 | { |
20 | - /** |
|
21 | - * API result document |
|
22 | - * @var DOMDocument |
|
23 | - */ |
|
24 | - protected $document; |
|
25 | - |
|
26 | - public function __construct() |
|
27 | - { |
|
28 | - $this->document = new DOMDocument('1.0'); |
|
29 | - } |
|
30 | - |
|
31 | - /** |
|
32 | - * Main function for this page, when no specific actions are called. |
|
33 | - * |
|
34 | - * @throws ApiException |
|
35 | - * @return void |
|
36 | - */ |
|
37 | - final protected function main() |
|
38 | - { |
|
39 | - if (headers_sent()) { |
|
40 | - throw new ApiException('Headers have already been sent - this indicates a bug in the application!'); |
|
41 | - } |
|
42 | - |
|
43 | - header("Content-Type: text/xml"); |
|
44 | - |
|
45 | - // javascript access control |
|
46 | - $httpOrigin = WebRequest::origin(); |
|
47 | - |
|
48 | - if ($httpOrigin !== null) { |
|
49 | - $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
|
50 | - |
|
51 | - if (in_array($httpOrigin, $CORSallowed)) { |
|
52 | - header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
53 | - } |
|
54 | - } |
|
55 | - |
|
56 | - $responseData = $this->runApiPage(); |
|
57 | - |
|
58 | - ob_end_clean(); |
|
59 | - print($responseData); |
|
60 | - ob_start(); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Method that runs API action |
|
65 | - * |
|
66 | - * @param DOMElement $apiDocument |
|
67 | - * |
|
68 | - * @return DOMElement |
|
69 | - */ |
|
70 | - abstract public function executeApiAction(DOMElement $apiDocument); |
|
71 | - |
|
72 | - /** |
|
73 | - * @return string |
|
74 | - */ |
|
75 | - final public function runApiPage() |
|
76 | - { |
|
77 | - $apiDocument = $this->document->createElement("api"); |
|
78 | - |
|
79 | - try { |
|
80 | - $apiDocument = $this->executeApiAction($apiDocument); |
|
81 | - } |
|
82 | - /** @noinspection PhpRedundantCatchClauseInspection */ |
|
83 | - catch (ApiException $ex) { |
|
84 | - $exception = $this->document->createElement("error"); |
|
85 | - $exception->setAttribute("message", $ex->getMessage()); |
|
86 | - $apiDocument->appendChild($exception); |
|
87 | - } |
|
88 | - |
|
89 | - $this->document->appendChild($apiDocument); |
|
90 | - |
|
91 | - return $this->document->saveXML(); |
|
92 | - } |
|
20 | + /** |
|
21 | + * API result document |
|
22 | + * @var DOMDocument |
|
23 | + */ |
|
24 | + protected $document; |
|
25 | + |
|
26 | + public function __construct() |
|
27 | + { |
|
28 | + $this->document = new DOMDocument('1.0'); |
|
29 | + } |
|
30 | + |
|
31 | + /** |
|
32 | + * Main function for this page, when no specific actions are called. |
|
33 | + * |
|
34 | + * @throws ApiException |
|
35 | + * @return void |
|
36 | + */ |
|
37 | + final protected function main() |
|
38 | + { |
|
39 | + if (headers_sent()) { |
|
40 | + throw new ApiException('Headers have already been sent - this indicates a bug in the application!'); |
|
41 | + } |
|
42 | + |
|
43 | + header("Content-Type: text/xml"); |
|
44 | + |
|
45 | + // javascript access control |
|
46 | + $httpOrigin = WebRequest::origin(); |
|
47 | + |
|
48 | + if ($httpOrigin !== null) { |
|
49 | + $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
|
50 | + |
|
51 | + if (in_array($httpOrigin, $CORSallowed)) { |
|
52 | + header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
53 | + } |
|
54 | + } |
|
55 | + |
|
56 | + $responseData = $this->runApiPage(); |
|
57 | + |
|
58 | + ob_end_clean(); |
|
59 | + print($responseData); |
|
60 | + ob_start(); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Method that runs API action |
|
65 | + * |
|
66 | + * @param DOMElement $apiDocument |
|
67 | + * |
|
68 | + * @return DOMElement |
|
69 | + */ |
|
70 | + abstract public function executeApiAction(DOMElement $apiDocument); |
|
71 | + |
|
72 | + /** |
|
73 | + * @return string |
|
74 | + */ |
|
75 | + final public function runApiPage() |
|
76 | + { |
|
77 | + $apiDocument = $this->document->createElement("api"); |
|
78 | + |
|
79 | + try { |
|
80 | + $apiDocument = $this->executeApiAction($apiDocument); |
|
81 | + } |
|
82 | + /** @noinspection PhpRedundantCatchClauseInspection */ |
|
83 | + catch (ApiException $ex) { |
|
84 | + $exception = $this->document->createElement("error"); |
|
85 | + $exception->setAttribute("message", $ex->getMessage()); |
|
86 | + $apiDocument->appendChild($exception); |
|
87 | + } |
|
88 | + |
|
89 | + $this->document->appendChild($apiDocument); |
|
90 | + |
|
91 | + return $this->document->saveXML(); |
|
92 | + } |
|
93 | 93 | } |
@@ -14,68 +14,68 @@ |
||
14 | 14 | |
15 | 15 | abstract class JsonApiPageBase extends ApiPageBase implements IJsonApiAction |
16 | 16 | { |
17 | - /** |
|
18 | - * Main function for this page, when no specific actions are called. |
|
19 | - * |
|
20 | - * @return void |
|
21 | - * @throws ApiException |
|
22 | - */ |
|
23 | - final protected function main() |
|
24 | - { |
|
25 | - if (headers_sent()) { |
|
26 | - throw new ApiException('Headers have already been sent - this indicates a bug in the application!'); |
|
27 | - } |
|
17 | + /** |
|
18 | + * Main function for this page, when no specific actions are called. |
|
19 | + * |
|
20 | + * @return void |
|
21 | + * @throws ApiException |
|
22 | + */ |
|
23 | + final protected function main() |
|
24 | + { |
|
25 | + if (headers_sent()) { |
|
26 | + throw new ApiException('Headers have already been sent - this indicates a bug in the application!'); |
|
27 | + } |
|
28 | 28 | |
29 | - // javascript access control |
|
30 | - $httpOrigin = WebRequest::origin(); |
|
29 | + // javascript access control |
|
30 | + $httpOrigin = WebRequest::origin(); |
|
31 | 31 | |
32 | - if ($httpOrigin !== null) { |
|
33 | - $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
|
32 | + if ($httpOrigin !== null) { |
|
33 | + $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
|
34 | 34 | |
35 | - if (in_array($httpOrigin, $CORSallowed)) { |
|
36 | - header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
37 | - } |
|
38 | - } |
|
35 | + if (in_array($httpOrigin, $CORSallowed)) { |
|
36 | + header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
37 | + } |
|
38 | + } |
|
39 | 39 | |
40 | - $responseData = $this->runApiPage(); |
|
40 | + $responseData = $this->runApiPage(); |
|
41 | 41 | |
42 | - ob_end_clean(); |
|
43 | - print($responseData); |
|
44 | - ob_start(); |
|
45 | - } |
|
42 | + ob_end_clean(); |
|
43 | + print($responseData); |
|
44 | + ob_start(); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Method that runs API action |
|
49 | - * |
|
50 | - * @return object|array The modified API document |
|
51 | - */ |
|
52 | - public abstract function executeApiAction(); |
|
47 | + /** |
|
48 | + * Method that runs API action |
|
49 | + * |
|
50 | + * @return object|array The modified API document |
|
51 | + */ |
|
52 | + public abstract function executeApiAction(); |
|
53 | 53 | |
54 | - /** |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - final public function runApiPage() |
|
58 | - { |
|
59 | - try { |
|
60 | - $apiDocument = $this->executeApiAction(); |
|
61 | - } |
|
62 | - /** @noinspection PhpRedundantCatchClauseInspection */ |
|
63 | - catch (ApiException $ex) { |
|
64 | - $apiDocument = [ |
|
65 | - 'error' => $ex->getMessage(), |
|
66 | - ]; |
|
67 | - } |
|
54 | + /** |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + final public function runApiPage() |
|
58 | + { |
|
59 | + try { |
|
60 | + $apiDocument = $this->executeApiAction(); |
|
61 | + } |
|
62 | + /** @noinspection PhpRedundantCatchClauseInspection */ |
|
63 | + catch (ApiException $ex) { |
|
64 | + $apiDocument = [ |
|
65 | + 'error' => $ex->getMessage(), |
|
66 | + ]; |
|
67 | + } |
|
68 | 68 | |
69 | - $data = json_encode($apiDocument, JSON_UNESCAPED_UNICODE); |
|
69 | + $data = json_encode($apiDocument, JSON_UNESCAPED_UNICODE); |
|
70 | 70 | |
71 | - $targetVar = WebRequest::getString('targetVariable'); |
|
72 | - if ($targetVar !== null && preg_match('/^[a-z]+$/', $targetVar)) { |
|
73 | - $data = $targetVar . ' = ' . $data . ';'; |
|
74 | - header("Content-Type: text/javascript"); |
|
75 | - } else { |
|
76 | - header("Content-Type: application/json"); |
|
77 | - } |
|
71 | + $targetVar = WebRequest::getString('targetVariable'); |
|
72 | + if ($targetVar !== null && preg_match('/^[a-z]+$/', $targetVar)) { |
|
73 | + $data = $targetVar . ' = ' . $data . ';'; |
|
74 | + header("Content-Type: text/javascript"); |
|
75 | + } else { |
|
76 | + header("Content-Type: application/json"); |
|
77 | + } |
|
78 | 78 | |
79 | - return $data; |
|
80 | - } |
|
79 | + return $data; |
|
80 | + } |
|
81 | 81 | } |
@@ -21,118 +21,118 @@ |
||
21 | 21 | |
22 | 22 | class RunJobQueueTask extends ConsoleTaskBase |
23 | 23 | { |
24 | - private $taskList = array( |
|
25 | - WelcomeUserTask::class, |
|
26 | - BotCreationTask::class, |
|
27 | - UserCreationTask::class |
|
28 | - ); |
|
29 | - |
|
30 | - public function execute() |
|
31 | - { |
|
32 | - $database = $this->getDatabase(); |
|
33 | - |
|
34 | - // ensure we're running inside a tx here. |
|
35 | - if (!$database->hasActiveTransaction()) { |
|
36 | - $database->beginTransaction(); |
|
37 | - } |
|
38 | - |
|
39 | - $sql = 'SELECT * FROM jobqueue WHERE status = :status ORDER BY enqueue LIMIT :lim'; |
|
40 | - $statement = $database->prepare($sql); |
|
41 | - $statement->execute(array(':status' => JobQueue::STATUS_READY, ':lim' => 10)); |
|
42 | - /** @var JobQueue[] $queuedJobs */ |
|
43 | - $queuedJobs = $statement->fetchAll(PDO::FETCH_CLASS, JobQueue::class); |
|
44 | - |
|
45 | - // mark all the jobs as running, and commit the txn so we're not holding onto long-running transactions. |
|
46 | - // We'll re-lock the row when we get to it. |
|
47 | - foreach ($queuedJobs as $job) { |
|
48 | - $job->setDatabase($database); |
|
49 | - $job->setStatus(JobQueue::STATUS_WAITING); |
|
50 | - $job->setError(null); |
|
51 | - $job->setAcknowledged(null); |
|
52 | - $job->save(); |
|
53 | - } |
|
54 | - |
|
55 | - $database->commit(); |
|
56 | - |
|
57 | - set_error_handler(array(RunJobQueueTask::class, 'errorHandler'), E_ALL); |
|
58 | - |
|
59 | - foreach ($queuedJobs as $job) { |
|
60 | - try { |
|
61 | - // refresh from the database |
|
62 | - /** @var JobQueue $job */ |
|
63 | - $job = JobQueue::getById($job->getId(), $database); |
|
64 | - |
|
65 | - if ($job->getStatus() !== JobQueue::STATUS_WAITING) { |
|
66 | - continue; |
|
67 | - } |
|
68 | - |
|
69 | - $database->beginTransaction(); |
|
70 | - $job->setStatus(JobQueue::STATUS_RUNNING); |
|
71 | - $job->save(); |
|
72 | - $database->commit(); |
|
73 | - |
|
74 | - $database->beginTransaction(); |
|
75 | - |
|
76 | - // re-lock the job |
|
77 | - $job->setStatus(JobQueue::STATUS_RUNNING); |
|
78 | - $job->save(); |
|
79 | - |
|
80 | - // validate we're allowed to run the requested task (whitelist) |
|
81 | - if (!in_array($job->getTask(), $this->taskList)) { |
|
82 | - throw new ApplicationLogicException('Job task not registered'); |
|
83 | - } |
|
84 | - |
|
85 | - // Create a task. |
|
86 | - $taskName = $job->getTask(); |
|
87 | - |
|
88 | - if(!class_exists($taskName)) { |
|
89 | - throw new ApplicationLogicException('Job task does not exist'); |
|
90 | - } |
|
91 | - |
|
92 | - /** @var BackgroundTaskBase $task */ |
|
93 | - $task = new $taskName; |
|
94 | - |
|
95 | - $this->setupTask($task, $job); |
|
96 | - $task->run(); |
|
97 | - } |
|
98 | - catch (Exception $ex) { |
|
99 | - $database->rollBack(); |
|
100 | - $database->beginTransaction(); |
|
101 | - |
|
102 | - /** @var JobQueue $job */ |
|
103 | - $job = JobQueue::getById($job->getId(), $database); |
|
104 | - $job->setDatabase($database); |
|
105 | - $job->setStatus(JobQueue::STATUS_FAILED); |
|
106 | - $job->setError($ex->getMessage()); |
|
107 | - $job->setAcknowledged(0); |
|
108 | - $job->save(); |
|
109 | - |
|
110 | - Logger::backgroundJobIssue($this->getDatabase(), $job); |
|
111 | - |
|
112 | - $database->commit(); |
|
113 | - } |
|
114 | - finally { |
|
115 | - $database->commit(); |
|
116 | - } |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @param BackgroundTaskBase $task |
|
122 | - * @param JobQueue $job |
|
123 | - */ |
|
124 | - private function setupTask(BackgroundTaskBase $task, JobQueue $job) |
|
125 | - { |
|
126 | - $task->setJob($job); |
|
127 | - $task->setDatabase($this->getDatabase()); |
|
128 | - $task->setHttpHelper($this->getHttpHelper()); |
|
129 | - $task->setOauthProtocolHelper($this->getOAuthProtocolHelper()); |
|
130 | - $task->setEmailHelper($this->getEmailHelper()); |
|
131 | - $task->setSiteConfiguration($this->getSiteConfiguration()); |
|
132 | - $task->setNotificationHelper($this->getNotificationHelper()); |
|
133 | - } |
|
134 | - |
|
135 | - public static function errorHandler($errno, $errstr, $errfile, $errline) { |
|
136 | - throw new Exception($errfile . "@" . $errline . ": " . $errstr); |
|
137 | - } |
|
24 | + private $taskList = array( |
|
25 | + WelcomeUserTask::class, |
|
26 | + BotCreationTask::class, |
|
27 | + UserCreationTask::class |
|
28 | + ); |
|
29 | + |
|
30 | + public function execute() |
|
31 | + { |
|
32 | + $database = $this->getDatabase(); |
|
33 | + |
|
34 | + // ensure we're running inside a tx here. |
|
35 | + if (!$database->hasActiveTransaction()) { |
|
36 | + $database->beginTransaction(); |
|
37 | + } |
|
38 | + |
|
39 | + $sql = 'SELECT * FROM jobqueue WHERE status = :status ORDER BY enqueue LIMIT :lim'; |
|
40 | + $statement = $database->prepare($sql); |
|
41 | + $statement->execute(array(':status' => JobQueue::STATUS_READY, ':lim' => 10)); |
|
42 | + /** @var JobQueue[] $queuedJobs */ |
|
43 | + $queuedJobs = $statement->fetchAll(PDO::FETCH_CLASS, JobQueue::class); |
|
44 | + |
|
45 | + // mark all the jobs as running, and commit the txn so we're not holding onto long-running transactions. |
|
46 | + // We'll re-lock the row when we get to it. |
|
47 | + foreach ($queuedJobs as $job) { |
|
48 | + $job->setDatabase($database); |
|
49 | + $job->setStatus(JobQueue::STATUS_WAITING); |
|
50 | + $job->setError(null); |
|
51 | + $job->setAcknowledged(null); |
|
52 | + $job->save(); |
|
53 | + } |
|
54 | + |
|
55 | + $database->commit(); |
|
56 | + |
|
57 | + set_error_handler(array(RunJobQueueTask::class, 'errorHandler'), E_ALL); |
|
58 | + |
|
59 | + foreach ($queuedJobs as $job) { |
|
60 | + try { |
|
61 | + // refresh from the database |
|
62 | + /** @var JobQueue $job */ |
|
63 | + $job = JobQueue::getById($job->getId(), $database); |
|
64 | + |
|
65 | + if ($job->getStatus() !== JobQueue::STATUS_WAITING) { |
|
66 | + continue; |
|
67 | + } |
|
68 | + |
|
69 | + $database->beginTransaction(); |
|
70 | + $job->setStatus(JobQueue::STATUS_RUNNING); |
|
71 | + $job->save(); |
|
72 | + $database->commit(); |
|
73 | + |
|
74 | + $database->beginTransaction(); |
|
75 | + |
|
76 | + // re-lock the job |
|
77 | + $job->setStatus(JobQueue::STATUS_RUNNING); |
|
78 | + $job->save(); |
|
79 | + |
|
80 | + // validate we're allowed to run the requested task (whitelist) |
|
81 | + if (!in_array($job->getTask(), $this->taskList)) { |
|
82 | + throw new ApplicationLogicException('Job task not registered'); |
|
83 | + } |
|
84 | + |
|
85 | + // Create a task. |
|
86 | + $taskName = $job->getTask(); |
|
87 | + |
|
88 | + if(!class_exists($taskName)) { |
|
89 | + throw new ApplicationLogicException('Job task does not exist'); |
|
90 | + } |
|
91 | + |
|
92 | + /** @var BackgroundTaskBase $task */ |
|
93 | + $task = new $taskName; |
|
94 | + |
|
95 | + $this->setupTask($task, $job); |
|
96 | + $task->run(); |
|
97 | + } |
|
98 | + catch (Exception $ex) { |
|
99 | + $database->rollBack(); |
|
100 | + $database->beginTransaction(); |
|
101 | + |
|
102 | + /** @var JobQueue $job */ |
|
103 | + $job = JobQueue::getById($job->getId(), $database); |
|
104 | + $job->setDatabase($database); |
|
105 | + $job->setStatus(JobQueue::STATUS_FAILED); |
|
106 | + $job->setError($ex->getMessage()); |
|
107 | + $job->setAcknowledged(0); |
|
108 | + $job->save(); |
|
109 | + |
|
110 | + Logger::backgroundJobIssue($this->getDatabase(), $job); |
|
111 | + |
|
112 | + $database->commit(); |
|
113 | + } |
|
114 | + finally { |
|
115 | + $database->commit(); |
|
116 | + } |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @param BackgroundTaskBase $task |
|
122 | + * @param JobQueue $job |
|
123 | + */ |
|
124 | + private function setupTask(BackgroundTaskBase $task, JobQueue $job) |
|
125 | + { |
|
126 | + $task->setJob($job); |
|
127 | + $task->setDatabase($this->getDatabase()); |
|
128 | + $task->setHttpHelper($this->getHttpHelper()); |
|
129 | + $task->setOauthProtocolHelper($this->getOAuthProtocolHelper()); |
|
130 | + $task->setEmailHelper($this->getEmailHelper()); |
|
131 | + $task->setSiteConfiguration($this->getSiteConfiguration()); |
|
132 | + $task->setNotificationHelper($this->getNotificationHelper()); |
|
133 | + } |
|
134 | + |
|
135 | + public static function errorHandler($errno, $errstr, $errfile, $errline) { |
|
136 | + throw new Exception($errfile . "@" . $errline . ": " . $errstr); |
|
137 | + } |
|
138 | 138 | } |
@@ -85,7 +85,7 @@ |
||
85 | 85 | // Create a task. |
86 | 86 | $taskName = $job->getTask(); |
87 | 87 | |
88 | - if(!class_exists($taskName)) { |
|
88 | + if (!class_exists($taskName)) { |
|
89 | 89 | throw new ApplicationLogicException('Job task does not exist'); |
90 | 90 | } |
91 | 91 |
@@ -132,7 +132,8 @@ |
||
132 | 132 | $task->setNotificationHelper($this->getNotificationHelper()); |
133 | 133 | } |
134 | 134 | |
135 | - public static function errorHandler($errno, $errstr, $errfile, $errline) { |
|
135 | + public static function errorHandler($errno, $errstr, $errfile, $errline) |
|
136 | + { |
|
136 | 137 | throw new Exception($errfile . "@" . $errline . ": " . $errstr); |
137 | 138 | } |
138 | 139 | } |
@@ -17,35 +17,35 @@ |
||
17 | 17 | |
18 | 18 | class RefreshOAuthDataTask extends ConsoleTaskBase |
19 | 19 | { |
20 | - public function execute() |
|
21 | - { |
|
22 | - $database = $this->getDatabase(); |
|
23 | - |
|
24 | - $idList = $database |
|
25 | - ->query('SELECT user FROM oauthtoken WHERE type = \'access\' AND expiry IS NULL') |
|
26 | - ->fetchAll(PDO::FETCH_COLUMN); |
|
27 | - |
|
28 | - if (count($idList) > 0) { |
|
29 | - /** @var User[] $users */ |
|
30 | - $users = UserSearchHelper::get($database)->inIds($idList)->fetch(); |
|
31 | - |
|
32 | - $expiredStatement = $database |
|
33 | - ->prepare('UPDATE oauthtoken SET expiry = CURRENT_TIMESTAMP() WHERE user = :u AND type = \'access\''); |
|
34 | - |
|
35 | - foreach ($users as $u) { |
|
36 | - $oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(), |
|
37 | - $this->getSiteConfiguration()); |
|
38 | - |
|
39 | - try { |
|
40 | - $oauth->refreshIdentity(); |
|
41 | - } |
|
42 | - catch (OAuthException $ex) { |
|
43 | - $expiredStatement->execute(array(':u' => $u->getId())); |
|
44 | - } |
|
45 | - } |
|
46 | - } |
|
47 | - |
|
48 | - $this->getDatabase() |
|
49 | - ->exec('DELETE FROM oauthtoken WHERE expiry IS NOT NULL AND expiry < NOW() AND type = \'request\''); |
|
50 | - } |
|
20 | + public function execute() |
|
21 | + { |
|
22 | + $database = $this->getDatabase(); |
|
23 | + |
|
24 | + $idList = $database |
|
25 | + ->query('SELECT user FROM oauthtoken WHERE type = \'access\' AND expiry IS NULL') |
|
26 | + ->fetchAll(PDO::FETCH_COLUMN); |
|
27 | + |
|
28 | + if (count($idList) > 0) { |
|
29 | + /** @var User[] $users */ |
|
30 | + $users = UserSearchHelper::get($database)->inIds($idList)->fetch(); |
|
31 | + |
|
32 | + $expiredStatement = $database |
|
33 | + ->prepare('UPDATE oauthtoken SET expiry = CURRENT_TIMESTAMP() WHERE user = :u AND type = \'access\''); |
|
34 | + |
|
35 | + foreach ($users as $u) { |
|
36 | + $oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(), |
|
37 | + $this->getSiteConfiguration()); |
|
38 | + |
|
39 | + try { |
|
40 | + $oauth->refreshIdentity(); |
|
41 | + } |
|
42 | + catch (OAuthException $ex) { |
|
43 | + $expiredStatement->execute(array(':u' => $u->getId())); |
|
44 | + } |
|
45 | + } |
|
46 | + } |
|
47 | + |
|
48 | + $this->getDatabase() |
|
49 | + ->exec('DELETE FROM oauthtoken WHERE expiry IS NOT NULL AND expiry < NOW() AND type = \'request\''); |
|
50 | + } |
|
51 | 51 | } |
52 | 52 | \ No newline at end of file |
@@ -14,19 +14,19 @@ |
||
14 | 14 | |
15 | 15 | class ClearOAuthDataTask extends ConsoleTaskBase |
16 | 16 | { |
17 | - public function execute() |
|
18 | - { |
|
19 | - $database = $this->getDatabase(); |
|
17 | + public function execute() |
|
18 | + { |
|
19 | + $database = $this->getDatabase(); |
|
20 | 20 | |
21 | - $users = UserSearchHelper::get($database)->inIds( |
|
22 | - $database->query('SELECT user FROM oauthtoken WHERE type = \'access\'')->fetchColumn()); |
|
21 | + $users = UserSearchHelper::get($database)->inIds( |
|
22 | + $database->query('SELECT user FROM oauthtoken WHERE type = \'access\'')->fetchColumn()); |
|
23 | 23 | |
24 | - foreach ($users as $u){ |
|
25 | - $oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
26 | - $oauth->detach(); |
|
27 | - } |
|
24 | + foreach ($users as $u){ |
|
25 | + $oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
26 | + $oauth->detach(); |
|
27 | + } |
|
28 | 28 | |
29 | - $database->exec('DELETE FROM oauthtoken'); |
|
30 | - $database->exec('DELETE FROM oauthidentity'); |
|
31 | - } |
|
29 | + $database->exec('DELETE FROM oauthtoken'); |
|
30 | + $database->exec('DELETE FROM oauthidentity'); |
|
31 | + } |
|
32 | 32 | } |
33 | 33 | \ No newline at end of file |
@@ -21,7 +21,7 @@ |
||
21 | 21 | $users = UserSearchHelper::get($database)->inIds( |
22 | 22 | $database->query('SELECT user FROM oauthtoken WHERE type = \'access\'')->fetchColumn()); |
23 | 23 | |
24 | - foreach ($users as $u){ |
|
24 | + foreach ($users as $u) { |
|
25 | 25 | $oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
26 | 26 | $oauth->detach(); |
27 | 27 | } |
@@ -21,7 +21,7 @@ |
||
21 | 21 | $users = UserSearchHelper::get($database)->inIds( |
22 | 22 | $database->query('SELECT user FROM oauthtoken WHERE type = \'access\'')->fetchColumn()); |
23 | 23 | |
24 | - foreach ($users as $u){ |
|
24 | + foreach ($users as $u) { |
|
25 | 25 | $oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
26 | 26 | $oauth->detach(); |
27 | 27 | } |
@@ -13,26 +13,26 @@ |
||
13 | 13 | |
14 | 14 | class RegenerateStylesheetsTask extends ConsoleTaskBase |
15 | 15 | { |
16 | - const RESOURCES_GENERATED = 'resources/generated'; |
|
16 | + const RESOURCES_GENERATED = 'resources/generated'; |
|
17 | 17 | |
18 | - public function execute() |
|
19 | - { |
|
20 | - $scss = new Compiler(); |
|
21 | - $scss->setImportPaths('resources/scss'); |
|
18 | + public function execute() |
|
19 | + { |
|
20 | + $scss = new Compiler(); |
|
21 | + $scss->setImportPaths('resources/scss'); |
|
22 | 22 | |
23 | - if (!$this->getSiteConfiguration()->getDebuggingTraceEnabled()) { |
|
24 | - $scss->setFormatter('ScssPhp\\ScssPhp\\Formatter\\Compressed'); |
|
25 | - $scss->setSourceMap(Compiler::SOURCE_MAP_INLINE); |
|
26 | - } |
|
23 | + if (!$this->getSiteConfiguration()->getDebuggingTraceEnabled()) { |
|
24 | + $scss->setFormatter('ScssPhp\\ScssPhp\\Formatter\\Compressed'); |
|
25 | + $scss->setSourceMap(Compiler::SOURCE_MAP_INLINE); |
|
26 | + } |
|
27 | 27 | |
28 | - if (!is_dir(self::RESOURCES_GENERATED)) { |
|
29 | - mkdir(self::RESOURCES_GENERATED); |
|
30 | - } |
|
28 | + if (!is_dir(self::RESOURCES_GENERATED)) { |
|
29 | + mkdir(self::RESOURCES_GENERATED); |
|
30 | + } |
|
31 | 31 | |
32 | - foreach (['bootstrap-main', 'bootstrap-alt'] as $file) { |
|
33 | - file_put_contents( |
|
34 | - self::RESOURCES_GENERATED . '/' . $file . '.css', |
|
35 | - $scss->compile('/*! Do not edit this auto-generated file! */ @import "' . $file . '";')); |
|
36 | - } |
|
37 | - } |
|
32 | + foreach (['bootstrap-main', 'bootstrap-alt'] as $file) { |
|
33 | + file_put_contents( |
|
34 | + self::RESOURCES_GENERATED . '/' . $file . '.css', |
|
35 | + $scss->compile('/*! Do not edit this auto-generated file! */ @import "' . $file . '";')); |
|
36 | + } |
|
37 | + } |
|
38 | 38 | } |