@@ -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 | } |
@@ -14,30 +14,30 @@ discard block |
||
14 | 14 | |
15 | 15 | class PrecacheGeolocationTask extends ConsoleTaskBase |
16 | 16 | { |
17 | - public function execute() |
|
18 | - { |
|
19 | - $database = $this->getDatabase(); |
|
20 | - $locationProvider = $this->getLocationProvider(); |
|
17 | + public function execute() |
|
18 | + { |
|
19 | + $database = $this->getDatabase(); |
|
20 | + $locationProvider = $this->getLocationProvider(); |
|
21 | 21 | |
22 | - while (true) { |
|
23 | - echo "Beginning txn\n"; |
|
24 | - $database->beginTransaction(); |
|
22 | + while (true) { |
|
23 | + echo "Beginning txn\n"; |
|
24 | + $database->beginTransaction(); |
|
25 | 25 | |
26 | - try { |
|
27 | - echo ". Fetching data...\n"; |
|
26 | + try { |
|
27 | + echo ". Fetching data...\n"; |
|
28 | 28 | |
29 | - // fetch a bunch of un-geolocated IPs from the database. |
|
30 | - // Note we have to parse the forwardedip field in the database so we can test against the geolocation |
|
31 | - // table. |
|
32 | - // |
|
33 | - // This guarantees we get ten unlocated IPs back, unless there actually aren't 10 available. |
|
34 | - // |
|
35 | - // Alternatives include downloading a small set of forwarded IPs, splitting it in PHP, constructing an |
|
36 | - // IN() clause dynamically, sending that back to the database to check if there are geolocation entries, |
|
37 | - // then repeating until we have 10 to process - and the fact that we'd have to potentially retrieve all |
|
38 | - // IPs from the database before we find any at all. This way keeps all of that legwork in the database, |
|
39 | - // at the cost of a more complex query. |
|
40 | - $statement = $database->query(<<<SQL |
|
29 | + // fetch a bunch of un-geolocated IPs from the database. |
|
30 | + // Note we have to parse the forwardedip field in the database so we can test against the geolocation |
|
31 | + // table. |
|
32 | + // |
|
33 | + // This guarantees we get ten unlocated IPs back, unless there actually aren't 10 available. |
|
34 | + // |
|
35 | + // Alternatives include downloading a small set of forwarded IPs, splitting it in PHP, constructing an |
|
36 | + // IN() clause dynamically, sending that back to the database to check if there are geolocation entries, |
|
37 | + // then repeating until we have 10 to process - and the fact that we'd have to potentially retrieve all |
|
38 | + // IPs from the database before we find any at all. This way keeps all of that legwork in the database, |
|
39 | + // at the cost of a more complex query. |
|
40 | + $statement = $database->query(<<<SQL |
|
41 | 41 | SELECT /* PrecacheGeolocationTask */ p.prox |
42 | 42 | FROM ( |
43 | 43 | SELECT trim(substring_index(substring_index(r.forwardedip, ',', n.n), ',', -1)) prox |
@@ -54,42 +54,42 @@ discard block |
||
54 | 54 | WHERE NOT EXISTS (SELECT 1 FROM geolocation g WHERE g.address = p.prox FOR UPDATE) |
55 | 55 | LIMIT 10; |
56 | 56 | SQL |
57 | - ); |
|
57 | + ); |
|
58 | 58 | |
59 | - $missingIps = $statement->fetchAll(PDO::FETCH_COLUMN); |
|
59 | + $missingIps = $statement->fetchAll(PDO::FETCH_COLUMN); |
|
60 | 60 | |
61 | - $count = count($missingIps); |
|
62 | - if ($count === 0) { |
|
63 | - echo ". Found nothing to do.\n"; |
|
64 | - break; |
|
65 | - } |
|
61 | + $count = count($missingIps); |
|
62 | + if ($count === 0) { |
|
63 | + echo ". Found nothing to do.\n"; |
|
64 | + break; |
|
65 | + } |
|
66 | 66 | |
67 | - echo ". Picked {$count} IP addresses\n"; |
|
67 | + echo ". Picked {$count} IP addresses\n"; |
|
68 | 68 | |
69 | - foreach ($missingIps as $ip) { |
|
70 | - echo ". . Getting location for {$ip}...\n"; |
|
71 | - $data = json_encode($locationProvider->getIpLocation($ip)); |
|
72 | - echo ". . . {$data}\n"; |
|
73 | - } |
|
69 | + foreach ($missingIps as $ip) { |
|
70 | + echo ". . Getting location for {$ip}...\n"; |
|
71 | + $data = json_encode($locationProvider->getIpLocation($ip)); |
|
72 | + echo ". . . {$data}\n"; |
|
73 | + } |
|
74 | 74 | |
75 | - echo ". IP location fetch complete.\n"; |
|
76 | - $database->commit(); |
|
77 | - echo ". Committed txn.\n"; |
|
78 | - } |
|
79 | - catch (Exception $ex) { |
|
80 | - echo ". Encountered exception: " . $ex->getMessage() . "\n"; |
|
81 | - $database->rollBack(); |
|
82 | - echo ". Rolled back txn\n"; |
|
83 | - throw $ex; |
|
84 | - } |
|
85 | - finally { |
|
86 | - if ($database->hasActiveTransaction()) { |
|
87 | - $database->rollBack(); |
|
88 | - echo ". Rolled back txn\n"; |
|
89 | - } |
|
90 | - } |
|
91 | - } |
|
75 | + echo ". IP location fetch complete.\n"; |
|
76 | + $database->commit(); |
|
77 | + echo ". Committed txn.\n"; |
|
78 | + } |
|
79 | + catch (Exception $ex) { |
|
80 | + echo ". Encountered exception: " . $ex->getMessage() . "\n"; |
|
81 | + $database->rollBack(); |
|
82 | + echo ". Rolled back txn\n"; |
|
83 | + throw $ex; |
|
84 | + } |
|
85 | + finally { |
|
86 | + if ($database->hasActiveTransaction()) { |
|
87 | + $database->rollBack(); |
|
88 | + echo ". Rolled back txn\n"; |
|
89 | + } |
|
90 | + } |
|
91 | + } |
|
92 | 92 | |
93 | - echo "Done.\n"; |
|
94 | - } |
|
93 | + echo "Done.\n"; |
|
94 | + } |
|
95 | 95 | } |
96 | 96 | \ No newline at end of file |