@@ -2,129 +2,129 @@ discard block |
||
2 | 2 | |
3 | 3 | class SectionIO extends SS_Object implements Flushable |
4 | 4 | { |
5 | - private static $flush_on_dev_build = true; |
|
6 | - |
|
7 | - private static $sitetree_flush_strategy = 'smart'; |
|
8 | - |
|
9 | - private static $api_url = 'https://aperture.section.io/api/v1'; |
|
10 | - private static $account_id = ''; |
|
11 | - private static $application_id = ''; |
|
12 | - private static $environment_name = ''; |
|
13 | - private static $proxy_name = ''; |
|
14 | - private static $username = ''; |
|
15 | - private static $password = ''; |
|
16 | - private static $verify_ssl = true; |
|
17 | - private static $async = true; |
|
5 | + private static $flush_on_dev_build = true; |
|
6 | + |
|
7 | + private static $sitetree_flush_strategy = 'smart'; |
|
8 | + |
|
9 | + private static $api_url = 'https://aperture.section.io/api/v1'; |
|
10 | + private static $account_id = ''; |
|
11 | + private static $application_id = ''; |
|
12 | + private static $environment_name = ''; |
|
13 | + private static $proxy_name = ''; |
|
14 | + private static $username = ''; |
|
15 | + private static $password = ''; |
|
16 | + private static $verify_ssl = true; |
|
17 | + private static $async = true; |
|
18 | 18 | |
19 | - const SITETREE_STRATEGY_SINGLE = 'single'; |
|
20 | - const SITETREE_STRATEGY_PARENTS = 'parents'; |
|
21 | - const SITETREE_STRATEGY_ALL = 'all'; |
|
22 | - const SITETREE_STRATEGY_SMART = 'smart'; |
|
23 | - const SITETREE_STRATEGY_EVERYTING = 'everything'; |
|
19 | + const SITETREE_STRATEGY_SINGLE = 'single'; |
|
20 | + const SITETREE_STRATEGY_PARENTS = 'parents'; |
|
21 | + const SITETREE_STRATEGY_ALL = 'all'; |
|
22 | + const SITETREE_STRATEGY_SMART = 'smart'; |
|
23 | + const SITETREE_STRATEGY_EVERYTING = 'everything'; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Implementation of Flushable::flush() |
|
27 | - * Is triggered on dev/build and ?flush=1. |
|
28 | - */ |
|
29 | - public static function flush() |
|
30 | - { |
|
31 | - if (Config::inst()->get('SectionIO', 'flush_on_dev_build')) { |
|
32 | - return static::flushAll(); |
|
33 | - } |
|
34 | - |
|
35 | - return; |
|
36 | - } |
|
37 | - |
|
38 | - public static function flushAll() |
|
39 | - { |
|
40 | - $exp = 'obj.http.x-url ~ /'; |
|
41 | - |
|
42 | - return static::performFlush($exp); |
|
43 | - } |
|
44 | - |
|
45 | - public static function flushImage($imageID) |
|
46 | - { |
|
47 | - $image = Image::get()->byID($imageID); |
|
48 | - if ($image && $image->exists()) { |
|
49 | - $exp = 'obj.http.x-url ~ "^/'.preg_quote($image->getFilename()).'$"'; // image itself |
|
50 | - $exp .= ' || obj.http.x-url ~ "^/'.preg_quote($image->Parent()->getFilename()) |
|
51 | - .'_resampled/(.*)\-'.preg_quote($image->Name).'$"'; // resampled versions |
|
52 | - return static::performFlush($exp); |
|
53 | - } |
|
54 | - |
|
55 | - return false; |
|
56 | - } |
|
57 | - |
|
58 | - public static function flushFile($fileID) |
|
59 | - { |
|
60 | - $file = File::get()->byID($fileID); |
|
61 | - if ($file && $file->exists()) { |
|
62 | - $exp = 'obj.http.x-url ~ "^/'.preg_quote($file->getFilename()).'$"'; |
|
63 | - return static::performFlush($exp); |
|
64 | - } |
|
65 | - |
|
66 | - return false; |
|
67 | - } |
|
68 | - |
|
69 | - public static function flushSiteTree($sitetreeID, $smartStrategy = null) |
|
70 | - { |
|
71 | - $sitetree = SiteTree::get()->byID($sitetreeID); |
|
72 | - if ($sitetree && $sitetree->exists()) { |
|
73 | - // get strategy config |
|
74 | - $strategy = Config::inst()->get('SectionIO', 'sitetree_flush_strategy'); |
|
75 | - // set smart strategy if set |
|
76 | - if ($strategy == SectionIO::SITETREE_STRATEGY_SMART && $smartStrategy) { |
|
77 | - $strategy = $smartStrategy; |
|
78 | - } |
|
79 | - switch ($strategy) { |
|
80 | - |
|
81 | - case SectionIO::SITETREE_STRATEGY_SINGLE: |
|
82 | - $exp = 'obj.http.content-type ~ "'.preg_quote('text/html').'"'; |
|
83 | - $exp .= ' && obj.http.x-url ~ "^'.preg_quote($sitetree->Link()).'$"'; |
|
84 | - break; |
|
85 | - |
|
86 | - case SectionIO::SITETREE_STRATEGY_PARENTS: |
|
87 | - $exp = 'obj.http.content-type ~ "'.preg_quote('text/html').'"'; |
|
88 | - $exp .= ' && (obj.http.x-url ~ "^'.preg_quote($sitetree->Link()).'$"'; |
|
89 | - $parent = $sitetree->getParent(); |
|
90 | - while ($parent && $parent->exists()) { |
|
91 | - $exp .= ' || obj.http.x-url ~ "^'.preg_quote($parent->Link()).'$"'; |
|
92 | - $parent = $parent->getParent(); |
|
93 | - } |
|
94 | - $exp .= ')'; |
|
95 | - break; |
|
96 | - |
|
97 | - case SectionIO::SITETREE_STRATEGY_ALL: |
|
98 | - $exp = 'obj.http.content-type ~ "'.preg_quote('text/html').'"'; |
|
99 | - break; |
|
100 | - |
|
101 | - case 'everyting': // compatibility, old typo |
|
102 | - case SectionIO::SITETREE_STRATEGY_EVERYTING: |
|
103 | - default: |
|
104 | - $exp = 'obj.http.x-url ~ /'; |
|
105 | - break; |
|
106 | - |
|
107 | - } |
|
108 | - |
|
109 | - return static::performFlush($exp); |
|
110 | - } |
|
111 | - |
|
112 | - return false; |
|
113 | - } |
|
25 | + /** |
|
26 | + * Implementation of Flushable::flush() |
|
27 | + * Is triggered on dev/build and ?flush=1. |
|
28 | + */ |
|
29 | + public static function flush() |
|
30 | + { |
|
31 | + if (Config::inst()->get('SectionIO', 'flush_on_dev_build')) { |
|
32 | + return static::flushAll(); |
|
33 | + } |
|
34 | + |
|
35 | + return; |
|
36 | + } |
|
37 | + |
|
38 | + public static function flushAll() |
|
39 | + { |
|
40 | + $exp = 'obj.http.x-url ~ /'; |
|
41 | + |
|
42 | + return static::performFlush($exp); |
|
43 | + } |
|
44 | + |
|
45 | + public static function flushImage($imageID) |
|
46 | + { |
|
47 | + $image = Image::get()->byID($imageID); |
|
48 | + if ($image && $image->exists()) { |
|
49 | + $exp = 'obj.http.x-url ~ "^/'.preg_quote($image->getFilename()).'$"'; // image itself |
|
50 | + $exp .= ' || obj.http.x-url ~ "^/'.preg_quote($image->Parent()->getFilename()) |
|
51 | + .'_resampled/(.*)\-'.preg_quote($image->Name).'$"'; // resampled versions |
|
52 | + return static::performFlush($exp); |
|
53 | + } |
|
54 | + |
|
55 | + return false; |
|
56 | + } |
|
57 | + |
|
58 | + public static function flushFile($fileID) |
|
59 | + { |
|
60 | + $file = File::get()->byID($fileID); |
|
61 | + if ($file && $file->exists()) { |
|
62 | + $exp = 'obj.http.x-url ~ "^/'.preg_quote($file->getFilename()).'$"'; |
|
63 | + return static::performFlush($exp); |
|
64 | + } |
|
65 | + |
|
66 | + return false; |
|
67 | + } |
|
68 | + |
|
69 | + public static function flushSiteTree($sitetreeID, $smartStrategy = null) |
|
70 | + { |
|
71 | + $sitetree = SiteTree::get()->byID($sitetreeID); |
|
72 | + if ($sitetree && $sitetree->exists()) { |
|
73 | + // get strategy config |
|
74 | + $strategy = Config::inst()->get('SectionIO', 'sitetree_flush_strategy'); |
|
75 | + // set smart strategy if set |
|
76 | + if ($strategy == SectionIO::SITETREE_STRATEGY_SMART && $smartStrategy) { |
|
77 | + $strategy = $smartStrategy; |
|
78 | + } |
|
79 | + switch ($strategy) { |
|
80 | + |
|
81 | + case SectionIO::SITETREE_STRATEGY_SINGLE: |
|
82 | + $exp = 'obj.http.content-type ~ "'.preg_quote('text/html').'"'; |
|
83 | + $exp .= ' && obj.http.x-url ~ "^'.preg_quote($sitetree->Link()).'$"'; |
|
84 | + break; |
|
85 | + |
|
86 | + case SectionIO::SITETREE_STRATEGY_PARENTS: |
|
87 | + $exp = 'obj.http.content-type ~ "'.preg_quote('text/html').'"'; |
|
88 | + $exp .= ' && (obj.http.x-url ~ "^'.preg_quote($sitetree->Link()).'$"'; |
|
89 | + $parent = $sitetree->getParent(); |
|
90 | + while ($parent && $parent->exists()) { |
|
91 | + $exp .= ' || obj.http.x-url ~ "^'.preg_quote($parent->Link()).'$"'; |
|
92 | + $parent = $parent->getParent(); |
|
93 | + } |
|
94 | + $exp .= ')'; |
|
95 | + break; |
|
96 | + |
|
97 | + case SectionIO::SITETREE_STRATEGY_ALL: |
|
98 | + $exp = 'obj.http.content-type ~ "'.preg_quote('text/html').'"'; |
|
99 | + break; |
|
100 | + |
|
101 | + case 'everyting': // compatibility, old typo |
|
102 | + case SectionIO::SITETREE_STRATEGY_EVERYTING: |
|
103 | + default: |
|
104 | + $exp = 'obj.http.x-url ~ /'; |
|
105 | + break; |
|
106 | + |
|
107 | + } |
|
108 | + |
|
109 | + return static::performFlush($exp); |
|
110 | + } |
|
111 | + |
|
112 | + return false; |
|
113 | + } |
|
114 | 114 | |
115 | - public static function flushURL($url) { |
|
116 | - if ($url) { |
|
117 | - $exp = 'obj.http.x-url ~ "^'.preg_quote($url).'$"'; |
|
118 | - return static::performFlush($exp); |
|
119 | - } |
|
120 | - return false; |
|
121 | - } |
|
122 | - |
|
123 | - protected static function performFlush($banExpression) |
|
124 | - { |
|
125 | - $success = true; |
|
126 | - $urls = static::getUrls(); |
|
127 | - // config loaded successfully |
|
115 | + public static function flushURL($url) { |
|
116 | + if ($url) { |
|
117 | + $exp = 'obj.http.x-url ~ "^'.preg_quote($url).'$"'; |
|
118 | + return static::performFlush($exp); |
|
119 | + } |
|
120 | + return false; |
|
121 | + } |
|
122 | + |
|
123 | + protected static function performFlush($banExpression) |
|
124 | + { |
|
125 | + $success = true; |
|
126 | + $urls = static::getUrls(); |
|
127 | + // config loaded successfully |
|
128 | 128 | if (static::checkConfig()) { |
129 | 129 | if (count($urls) > 0) { |
130 | 130 | foreach ($urls as $url) { |
@@ -153,127 +153,127 @@ discard block |
||
153 | 153 | } |
154 | 154 | } |
155 | 155 | |
156 | - return $success; |
|
157 | - } |
|
158 | - |
|
159 | - protected static function getService($url, $banExpression) |
|
160 | - { |
|
161 | - // prepare API call |
|
162 | - $service = new RestfulService( |
|
163 | - $url, |
|
164 | - 0 // expiry time 0: do not cache the API call |
|
165 | - ); |
|
166 | - // set basic auth |
|
167 | - $username = Config::inst()->get('SectionIO', 'username'); |
|
168 | - $password = Config::inst()->get('SectionIO', 'password'); |
|
169 | - $service->basicAuth($username, $password); |
|
170 | - // set query string (ban expression) |
|
171 | - $service->setQueryString(array( |
|
172 | - 'banExpression' => $banExpression, |
|
173 | - 'async' => Config::inst()->get('SectionIO', 'async') ? 'true' : 'false', |
|
174 | - )); |
|
175 | - |
|
176 | - return $service; |
|
177 | - } |
|
178 | - |
|
179 | - protected static function getOptions() |
|
180 | - { |
|
181 | - // prepare curl options for ssl verification |
|
182 | - if (Config::inst()->get('SectionIO', 'verify_ssl')) { |
|
183 | - return array( |
|
184 | - CURLOPT_SSL_VERIFYPEER => 0, |
|
185 | - CURLOPT_SSL_VERIFYHOST => 0, |
|
186 | - ); |
|
187 | - } |
|
188 | - return array(); |
|
189 | - } |
|
190 | - |
|
191 | - protected static function getHeaders() |
|
192 | - { |
|
193 | - $headers = array( |
|
194 | - 'Content-Type: application/json', |
|
195 | - 'Accept: application/json', |
|
196 | - ); |
|
197 | - |
|
198 | - return $headers; |
|
199 | - } |
|
200 | - |
|
201 | - protected static function getUrls() |
|
202 | - { |
|
203 | - $urls = array(); |
|
204 | - |
|
205 | - if (static::checkConfig()) { |
|
206 | - $api_url = Config::inst()->get('SectionIO', 'api_url'); |
|
207 | - $account_id = Config::inst()->get('SectionIO', 'account_id'); |
|
208 | - $application_id = Config::inst()->get('SectionIO', 'application_id'); |
|
209 | - $application_ids = array(); |
|
210 | - if (is_string($application_id)) { |
|
211 | - $application_ids = preg_split("/[\s,]+/", $application_id); |
|
212 | - } elseif (is_array($application_id)) { |
|
213 | - $application_ids = $application_id; |
|
214 | - } |
|
215 | - $environment_name = Config::inst()->get('SectionIO', 'environment_name'); |
|
216 | - $proxy_name = Config::inst()->get('SectionIO', 'proxy_name'); |
|
217 | - |
|
218 | - foreach ($application_ids as $appid) { |
|
219 | - // build API URL: /account/{accountId}/application/{applicationId}/environment/{environmentName}/proxy/{proxyName}/state |
|
220 | - $urls[] = Controller::join_links( |
|
221 | - $api_url, |
|
222 | - 'account', |
|
223 | - $account_id, |
|
224 | - 'application', |
|
225 | - $appid, |
|
226 | - 'environment', |
|
227 | - $environment_name, |
|
228 | - 'proxy', |
|
229 | - $proxy_name, |
|
230 | - 'state' |
|
231 | - ); |
|
232 | - } |
|
233 | - } |
|
234 | - |
|
235 | - return $urls; |
|
236 | - } |
|
237 | - |
|
238 | - protected static function checkConfig() |
|
239 | - { |
|
240 | - $missing = array(); |
|
241 | - // check config |
|
242 | - $api_url = Config::inst()->get('SectionIO', 'api_url'); |
|
243 | - if (!isset($api_url) || strlen($api_url) < 1) { |
|
244 | - $missing[] = 'SectionIO.api_url'; |
|
245 | - } |
|
246 | - $account_id = Config::inst()->get('SectionIO', 'account_id'); |
|
247 | - if (!isset($account_id) || strlen($account_id) < 1) { |
|
248 | - $missing[] = 'SectionIO.account_id'; |
|
249 | - } |
|
250 | - $application_id = Config::inst()->get('SectionIO', 'application_id'); |
|
251 | - if (!isset($application_id) || (!is_array($application_id) && strlen((string) $application_id) < 1)) { |
|
252 | - $missing[] = 'SectionIO.application_id'; |
|
253 | - } |
|
254 | - $environment_name = Config::inst()->get('SectionIO', 'environment_name'); |
|
255 | - if (!isset($environment_name) || strlen($environment_name) < 1) { |
|
256 | - $missing[] = 'SectionIO.environment_name'; |
|
257 | - } |
|
258 | - $proxy_name = Config::inst()->get('SectionIO', 'proxy_name'); |
|
259 | - if (!isset($proxy_name) || strlen($proxy_name) < 1) { |
|
260 | - $missing[] = 'SectionIO.proxy_name'; |
|
261 | - } |
|
262 | - $username = Config::inst()->get('SectionIO', 'username'); |
|
263 | - if (!isset($username) || strlen($username) < 1) { |
|
264 | - $missing[] = 'SectionIO.username'; |
|
265 | - } |
|
266 | - $password = Config::inst()->get('SectionIO', 'password'); |
|
267 | - if (!isset($password) || strlen($password) < 1) { |
|
268 | - $missing[] = 'SectionIO.password'; |
|
269 | - } |
|
156 | + return $success; |
|
157 | + } |
|
158 | + |
|
159 | + protected static function getService($url, $banExpression) |
|
160 | + { |
|
161 | + // prepare API call |
|
162 | + $service = new RestfulService( |
|
163 | + $url, |
|
164 | + 0 // expiry time 0: do not cache the API call |
|
165 | + ); |
|
166 | + // set basic auth |
|
167 | + $username = Config::inst()->get('SectionIO', 'username'); |
|
168 | + $password = Config::inst()->get('SectionIO', 'password'); |
|
169 | + $service->basicAuth($username, $password); |
|
170 | + // set query string (ban expression) |
|
171 | + $service->setQueryString(array( |
|
172 | + 'banExpression' => $banExpression, |
|
173 | + 'async' => Config::inst()->get('SectionIO', 'async') ? 'true' : 'false', |
|
174 | + )); |
|
175 | + |
|
176 | + return $service; |
|
177 | + } |
|
178 | + |
|
179 | + protected static function getOptions() |
|
180 | + { |
|
181 | + // prepare curl options for ssl verification |
|
182 | + if (Config::inst()->get('SectionIO', 'verify_ssl')) { |
|
183 | + return array( |
|
184 | + CURLOPT_SSL_VERIFYPEER => 0, |
|
185 | + CURLOPT_SSL_VERIFYHOST => 0, |
|
186 | + ); |
|
187 | + } |
|
188 | + return array(); |
|
189 | + } |
|
190 | + |
|
191 | + protected static function getHeaders() |
|
192 | + { |
|
193 | + $headers = array( |
|
194 | + 'Content-Type: application/json', |
|
195 | + 'Accept: application/json', |
|
196 | + ); |
|
197 | + |
|
198 | + return $headers; |
|
199 | + } |
|
200 | + |
|
201 | + protected static function getUrls() |
|
202 | + { |
|
203 | + $urls = array(); |
|
204 | + |
|
205 | + if (static::checkConfig()) { |
|
206 | + $api_url = Config::inst()->get('SectionIO', 'api_url'); |
|
207 | + $account_id = Config::inst()->get('SectionIO', 'account_id'); |
|
208 | + $application_id = Config::inst()->get('SectionIO', 'application_id'); |
|
209 | + $application_ids = array(); |
|
210 | + if (is_string($application_id)) { |
|
211 | + $application_ids = preg_split("/[\s,]+/", $application_id); |
|
212 | + } elseif (is_array($application_id)) { |
|
213 | + $application_ids = $application_id; |
|
214 | + } |
|
215 | + $environment_name = Config::inst()->get('SectionIO', 'environment_name'); |
|
216 | + $proxy_name = Config::inst()->get('SectionIO', 'proxy_name'); |
|
217 | + |
|
218 | + foreach ($application_ids as $appid) { |
|
219 | + // build API URL: /account/{accountId}/application/{applicationId}/environment/{environmentName}/proxy/{proxyName}/state |
|
220 | + $urls[] = Controller::join_links( |
|
221 | + $api_url, |
|
222 | + 'account', |
|
223 | + $account_id, |
|
224 | + 'application', |
|
225 | + $appid, |
|
226 | + 'environment', |
|
227 | + $environment_name, |
|
228 | + 'proxy', |
|
229 | + $proxy_name, |
|
230 | + 'state' |
|
231 | + ); |
|
232 | + } |
|
233 | + } |
|
234 | + |
|
235 | + return $urls; |
|
236 | + } |
|
237 | + |
|
238 | + protected static function checkConfig() |
|
239 | + { |
|
240 | + $missing = array(); |
|
241 | + // check config |
|
242 | + $api_url = Config::inst()->get('SectionIO', 'api_url'); |
|
243 | + if (!isset($api_url) || strlen($api_url) < 1) { |
|
244 | + $missing[] = 'SectionIO.api_url'; |
|
245 | + } |
|
246 | + $account_id = Config::inst()->get('SectionIO', 'account_id'); |
|
247 | + if (!isset($account_id) || strlen($account_id) < 1) { |
|
248 | + $missing[] = 'SectionIO.account_id'; |
|
249 | + } |
|
250 | + $application_id = Config::inst()->get('SectionIO', 'application_id'); |
|
251 | + if (!isset($application_id) || (!is_array($application_id) && strlen((string) $application_id) < 1)) { |
|
252 | + $missing[] = 'SectionIO.application_id'; |
|
253 | + } |
|
254 | + $environment_name = Config::inst()->get('SectionIO', 'environment_name'); |
|
255 | + if (!isset($environment_name) || strlen($environment_name) < 1) { |
|
256 | + $missing[] = 'SectionIO.environment_name'; |
|
257 | + } |
|
258 | + $proxy_name = Config::inst()->get('SectionIO', 'proxy_name'); |
|
259 | + if (!isset($proxy_name) || strlen($proxy_name) < 1) { |
|
260 | + $missing[] = 'SectionIO.proxy_name'; |
|
261 | + } |
|
262 | + $username = Config::inst()->get('SectionIO', 'username'); |
|
263 | + if (!isset($username) || strlen($username) < 1) { |
|
264 | + $missing[] = 'SectionIO.username'; |
|
265 | + } |
|
266 | + $password = Config::inst()->get('SectionIO', 'password'); |
|
267 | + if (!isset($password) || strlen($password) < 1) { |
|
268 | + $missing[] = 'SectionIO.password'; |
|
269 | + } |
|
270 | 270 | |
271 | - if (count($missing) > 0) { |
|
271 | + if (count($missing) > 0) { |
|
272 | 272 | if (!Director::isDev()) { |
273 | 273 | SS_Log::log('SectionIO:: config parameters missing: ' . implode(', ', $missing), SS_Log::WARN); |
274 | 274 | } |
275 | - return false; |
|
276 | - } |
|
277 | - return true; |
|
278 | - } |
|
275 | + return false; |
|
276 | + } |
|
277 | + return true; |
|
278 | + } |
|
279 | 279 | } |
@@ -46,9 +46,9 @@ discard block |
||
46 | 46 | { |
47 | 47 | $image = Image::get()->byID($imageID); |
48 | 48 | if ($image && $image->exists()) { |
49 | - $exp = 'obj.http.x-url ~ "^/'.preg_quote($image->getFilename()).'$"'; // image itself |
|
50 | - $exp .= ' || obj.http.x-url ~ "^/'.preg_quote($image->Parent()->getFilename()) |
|
51 | - .'_resampled/(.*)\-'.preg_quote($image->Name).'$"'; // resampled versions |
|
49 | + $exp = 'obj.http.x-url ~ "^/' . preg_quote($image->getFilename()) . '$"'; // image itself |
|
50 | + $exp .= ' || obj.http.x-url ~ "^/' . preg_quote($image->Parent()->getFilename()) |
|
51 | + .'_resampled/(.*)\-' . preg_quote($image->Name) . '$"'; // resampled versions |
|
52 | 52 | return static::performFlush($exp); |
53 | 53 | } |
54 | 54 | |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | { |
60 | 60 | $file = File::get()->byID($fileID); |
61 | 61 | if ($file && $file->exists()) { |
62 | - $exp = 'obj.http.x-url ~ "^/'.preg_quote($file->getFilename()).'$"'; |
|
62 | + $exp = 'obj.http.x-url ~ "^/' . preg_quote($file->getFilename()) . '$"'; |
|
63 | 63 | return static::performFlush($exp); |
64 | 64 | } |
65 | 65 | |
@@ -79,23 +79,23 @@ discard block |
||
79 | 79 | switch ($strategy) { |
80 | 80 | |
81 | 81 | case SectionIO::SITETREE_STRATEGY_SINGLE: |
82 | - $exp = 'obj.http.content-type ~ "'.preg_quote('text/html').'"'; |
|
83 | - $exp .= ' && obj.http.x-url ~ "^'.preg_quote($sitetree->Link()).'$"'; |
|
82 | + $exp = 'obj.http.content-type ~ "' . preg_quote('text/html') . '"'; |
|
83 | + $exp .= ' && obj.http.x-url ~ "^' . preg_quote($sitetree->Link()) . '$"'; |
|
84 | 84 | break; |
85 | 85 | |
86 | 86 | case SectionIO::SITETREE_STRATEGY_PARENTS: |
87 | - $exp = 'obj.http.content-type ~ "'.preg_quote('text/html').'"'; |
|
88 | - $exp .= ' && (obj.http.x-url ~ "^'.preg_quote($sitetree->Link()).'$"'; |
|
87 | + $exp = 'obj.http.content-type ~ "' . preg_quote('text/html') . '"'; |
|
88 | + $exp .= ' && (obj.http.x-url ~ "^' . preg_quote($sitetree->Link()) . '$"'; |
|
89 | 89 | $parent = $sitetree->getParent(); |
90 | 90 | while ($parent && $parent->exists()) { |
91 | - $exp .= ' || obj.http.x-url ~ "^'.preg_quote($parent->Link()).'$"'; |
|
91 | + $exp .= ' || obj.http.x-url ~ "^' . preg_quote($parent->Link()) . '$"'; |
|
92 | 92 | $parent = $parent->getParent(); |
93 | 93 | } |
94 | 94 | $exp .= ')'; |
95 | 95 | break; |
96 | 96 | |
97 | 97 | case SectionIO::SITETREE_STRATEGY_ALL: |
98 | - $exp = 'obj.http.content-type ~ "'.preg_quote('text/html').'"'; |
|
98 | + $exp = 'obj.http.content-type ~ "' . preg_quote('text/html') . '"'; |
|
99 | 99 | break; |
100 | 100 | |
101 | 101 | case 'everyting': // compatibility, old typo |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | |
115 | 115 | public static function flushURL($url) { |
116 | 116 | if ($url) { |
117 | - $exp = 'obj.http.x-url ~ "^'.preg_quote($url).'$"'; |
|
117 | + $exp = 'obj.http.x-url ~ "^' . preg_quote($url) . '$"'; |
|
118 | 118 | return static::performFlush($exp); |
119 | 119 | } |
120 | 120 | return false; |
@@ -142,10 +142,10 @@ discard block |
||
142 | 142 | $conn = $service->request(null, 'POST', null, $headers, $options); |
143 | 143 | |
144 | 144 | if ($conn->isError()) { |
145 | - SS_Log::log('SectionIO::performFlush :: '.$conn->getStatusCode().' : '.$conn->getStatusDescription().' : '.$url, SS_Log::ERR); |
|
145 | + SS_Log::log('SectionIO::performFlush :: ' . $conn->getStatusCode() . ' : ' . $conn->getStatusDescription() . ' : ' . $url, SS_Log::ERR); |
|
146 | 146 | $success = $success && false; |
147 | 147 | } else { |
148 | - SS_Log::log('SectionIO::performFlush :: ban successful. url: '.$url."; ban expression: '".$banExpression."'", SS_Log::NOTICE); |
|
148 | + SS_Log::log('SectionIO::performFlush :: ban successful. url: ' . $url . "; ban expression: '" . $banExpression . "'", SS_Log::NOTICE); |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | } else { |
@@ -2,30 +2,30 @@ |
||
2 | 2 | |
3 | 3 | class SectionIOSiteTreeExtension extends SiteTreeExtension |
4 | 4 | { |
5 | - public function onAfterPublish(&$original) |
|
6 | - { |
|
7 | - $strategy = SectionIO::SITETREE_STRATEGY_SINGLE; |
|
8 | - if ( |
|
9 | - $this->owner->URLSegment != $original->URLSegment || // the slug has been altered |
|
10 | - $this->owner->MenuTitle != $original->MenuTitle || // the navigation label has been altered |
|
11 | - $this->owner->Title != $original->Title // the title has been altered |
|
12 | - ) { |
|
13 | - $strategy = SectionIO::SITETREE_STRATEGY_ALL; |
|
14 | - } else if ( |
|
15 | - $this->owner->getParent() |
|
16 | - ) { |
|
17 | - $strategy = SectionIO::SITETREE_STRATEGY_PARENTS; |
|
18 | - } |
|
5 | + public function onAfterPublish(&$original) |
|
6 | + { |
|
7 | + $strategy = SectionIO::SITETREE_STRATEGY_SINGLE; |
|
8 | + if ( |
|
9 | + $this->owner->URLSegment != $original->URLSegment || // the slug has been altered |
|
10 | + $this->owner->MenuTitle != $original->MenuTitle || // the navigation label has been altered |
|
11 | + $this->owner->Title != $original->Title // the title has been altered |
|
12 | + ) { |
|
13 | + $strategy = SectionIO::SITETREE_STRATEGY_ALL; |
|
14 | + } else if ( |
|
15 | + $this->owner->getParent() |
|
16 | + ) { |
|
17 | + $strategy = SectionIO::SITETREE_STRATEGY_PARENTS; |
|
18 | + } |
|
19 | 19 | |
20 | - SectionIO::flushSiteTree($this->owner->ID, $strategy); |
|
20 | + SectionIO::flushSiteTree($this->owner->ID, $strategy); |
|
21 | 21 | |
22 | - parent::onAfterPublish($original); |
|
23 | - } |
|
22 | + parent::onAfterPublish($original); |
|
23 | + } |
|
24 | 24 | |
25 | - public function onAfterUnpublish() |
|
26 | - { |
|
27 | - SectionIO::flushAll(); |
|
25 | + public function onAfterUnpublish() |
|
26 | + { |
|
27 | + SectionIO::flushAll(); |
|
28 | 28 | |
29 | - parent::onBeforeUnpublish(); |
|
30 | - } |
|
29 | + parent::onBeforeUnpublish(); |
|
30 | + } |
|
31 | 31 | } |