@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | $folderIDs = $this->allFixtureIDs('Folder'); |
36 | 36 | foreach ($folderIDs as $folderID) { |
37 | 37 | $folder = DataObject::get_by_id('Folder', $folderID); |
38 | - if (!file_exists(BASE_PATH."/$folder->Filename")) { |
|
39 | - mkdir(BASE_PATH."/$folder->Filename"); |
|
38 | + if (!file_exists(BASE_PATH . "/$folder->Filename")) { |
|
39 | + mkdir(BASE_PATH . "/$folder->Filename"); |
|
40 | 40 | } |
41 | 41 | } |
42 | 42 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $imageIDs = $this->allFixtureIDs('Image'); |
45 | 45 | foreach ($imageIDs as $imageID) { |
46 | 46 | $image = DataObject::get_by_id('Image', $imageID); |
47 | - $filePath = BASE_PATH."/$image->Filename"; |
|
47 | + $filePath = BASE_PATH . "/$image->Filename"; |
|
48 | 48 | $sourcePath = str_replace('assets/SectionTest/', 'section-io/tests/testfiles/', $filePath); |
49 | 49 | if (!file_exists($filePath)) { |
50 | 50 | if (!copy($sourcePath, $filePath)) { |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | $fileIDs = $this->allFixtureIDs('File'); |
58 | 58 | foreach ($fileIDs as $fileID) { |
59 | 59 | $file = DataObject::get_by_id('File', $fileID); |
60 | - $filePath = BASE_PATH."/$file->Filename"; |
|
60 | + $filePath = BASE_PATH . "/$file->Filename"; |
|
61 | 61 | $sourcePath = str_replace('assets/SectionTest/', 'section-io/tests/testfiles/', $filePath); |
62 | 62 | if (!file_exists($filePath)) { |
63 | 63 | if (!copy($sourcePath, $filePath)) { |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | $imageIDs = $this->allFixtureIDs('Image'); |
83 | 83 | foreach ($imageIDs as $imageID) { |
84 | 84 | $image = DataObject::get_by_id('Image', $imageID); |
85 | - if ($image && file_exists(BASE_PATH."/$image->Filename")) { |
|
86 | - unlink(BASE_PATH."/$image->Filename"); |
|
85 | + if ($image && file_exists(BASE_PATH . "/$image->Filename")) { |
|
86 | + unlink(BASE_PATH . "/$image->Filename"); |
|
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
@@ -91,8 +91,8 @@ discard block |
||
91 | 91 | $fileIDs = $this->allFixtureIDs('File'); |
92 | 92 | foreach ($fileIDs as $fileID) { |
93 | 93 | $file = DataObject::get_by_id('File', $fileID); |
94 | - if ($file && file_exists(BASE_PATH."/$file->Filename")) { |
|
95 | - unlink(BASE_PATH."/$file->Filename"); |
|
94 | + if ($file && file_exists(BASE_PATH . "/$file->Filename")) { |
|
95 | + unlink(BASE_PATH . "/$file->Filename"); |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
@@ -100,11 +100,11 @@ discard block |
||
100 | 100 | $folderIDs = $this->allFixtureIDs('Folder'); |
101 | 101 | foreach ($folderIDs as $folderID) { |
102 | 102 | $folder = DataObject::get_by_id('Folder', $folderID); |
103 | - if ($folder && file_exists(BASE_PATH.'/'.$folder->Filename.'_resampled')) { |
|
104 | - Filesystem::removeFolder(BASE_PATH.'/'.$folder->Filename.'_resampled'); |
|
103 | + if ($folder && file_exists(BASE_PATH . '/' . $folder->Filename . '_resampled')) { |
|
104 | + Filesystem::removeFolder(BASE_PATH . '/' . $folder->Filename . '_resampled'); |
|
105 | 105 | } |
106 | - if ($folder && file_exists(BASE_PATH."/$folder->Filename")) { |
|
107 | - Filesystem::removeFolder(BASE_PATH."/$folder->Filename"); |
|
106 | + if ($folder && file_exists(BASE_PATH . "/$folder->Filename")) { |
|
107 | + Filesystem::removeFolder(BASE_PATH . "/$folder->Filename"); |
|
108 | 108 | } |
109 | 109 | } |
110 | 110 |
@@ -2,347 +2,347 @@ |
||
2 | 2 | |
3 | 3 | class SectionIOTest extends SapphireTest |
4 | 4 | { |
5 | - protected static $fixture_file = 'SectionIOTest.yml'; |
|
6 | - |
|
7 | - public function setUpOnce() |
|
8 | - { |
|
9 | - parent::setUpOnce(); |
|
10 | - |
|
11 | - // add config values |
|
12 | - Config::inst()->update('SectionIO', 'flush_on_dev_build', true); |
|
13 | - Config::inst()->update('SectionIO', 'api_url', 'https://example.com'); |
|
14 | - Config::inst()->update('SectionIO', 'account_id', '123456'); |
|
15 | - Config::inst()->update('SectionIO', 'application_id', '987654'); |
|
16 | - Config::inst()->update('SectionIO', 'environment_name', 'Production'); |
|
17 | - Config::inst()->update('SectionIO', 'proxy_name', 'myproxy'); |
|
18 | - Config::inst()->update('SectionIO', 'username', 'someuser'); |
|
19 | - Config::inst()->update('SectionIO', 'password', 'MySafePassword'); |
|
20 | - Config::inst()->update('SectionIO', 'verify_ssl', false); |
|
21 | - |
|
22 | - // remove extensions otherwise the fixtures will break the tests (by calling the live flush) |
|
23 | - File::remove_extension('SectionIOFileExtension'); |
|
24 | - SiteTree::remove_extension('SectionIOSiteTreeExtension'); |
|
25 | - } |
|
26 | - |
|
27 | - public function setUp() |
|
28 | - { |
|
29 | - parent::setUp(); |
|
30 | - |
|
31 | - if (!file_exists(ASSETS_PATH)) { |
|
32 | - mkdir(ASSETS_PATH); |
|
33 | - } |
|
34 | - |
|
35 | - // Create a test folders for each of the fixture references |
|
36 | - $folderIDs = $this->allFixtureIDs('Folder'); |
|
37 | - foreach ($folderIDs as $folderID) { |
|
38 | - $folder = DataObject::get_by_id('Folder', $folderID); |
|
39 | - if (!file_exists(BASE_PATH."/$folder->Filename")) { |
|
40 | - mkdir(BASE_PATH."/$folder->Filename"); |
|
41 | - } |
|
42 | - } |
|
43 | - |
|
44 | - // Copy test images for each of the fixture references |
|
45 | - $imageIDs = $this->allFixtureIDs('Image'); |
|
46 | - foreach ($imageIDs as $imageID) { |
|
47 | - $image = DataObject::get_by_id('Image', $imageID); |
|
48 | - $filePath = BASE_PATH."/$image->Filename"; |
|
49 | - $sourcePath = str_replace('assets/SectionTest/', 'section-io/tests/testfiles/', $filePath); |
|
50 | - if (!file_exists($filePath)) { |
|
51 | - if (!copy($sourcePath, $filePath)) { |
|
52 | - user_error('Failed to copy test images', E_USER_ERROR); |
|
53 | - } |
|
54 | - } |
|
55 | - } |
|
56 | - |
|
57 | - // Copy test files for each of the fixture references |
|
58 | - $fileIDs = $this->allFixtureIDs('File'); |
|
59 | - foreach ($fileIDs as $fileID) { |
|
60 | - $file = DataObject::get_by_id('File', $fileID); |
|
61 | - $filePath = BASE_PATH."/$file->Filename"; |
|
62 | - $sourcePath = str_replace('assets/SectionTest/', 'section-io/tests/testfiles/', $filePath); |
|
63 | - if (!file_exists($filePath)) { |
|
64 | - if (!copy($sourcePath, $filePath)) { |
|
65 | - user_error('Failed to copy test files', E_USER_ERROR); |
|
66 | - } |
|
67 | - } |
|
68 | - } |
|
69 | - } |
|
70 | - |
|
71 | - public function tearDownOnce() |
|
72 | - { |
|
73 | - parent::tearDownOnce(); |
|
74 | - |
|
75 | - // re-add extensions |
|
76 | - File::add_extension('SectionIOFileExtension'); |
|
77 | - SiteTree::add_extension('SectionIOSiteTreeExtension'); |
|
78 | - } |
|
79 | - |
|
80 | - public function tearDown() |
|
81 | - { |
|
82 | - // Remove the test images that we've created |
|
83 | - $imageIDs = $this->allFixtureIDs('Image'); |
|
84 | - foreach ($imageIDs as $imageID) { |
|
85 | - $image = DataObject::get_by_id('Image', $imageID); |
|
86 | - if ($image && file_exists(BASE_PATH."/$image->Filename")) { |
|
87 | - unlink(BASE_PATH."/$image->Filename"); |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - // Remove the test files that we've created |
|
92 | - $fileIDs = $this->allFixtureIDs('File'); |
|
93 | - foreach ($fileIDs as $fileID) { |
|
94 | - $file = DataObject::get_by_id('File', $fileID); |
|
95 | - if ($file && file_exists(BASE_PATH."/$file->Filename")) { |
|
96 | - unlink(BASE_PATH."/$file->Filename"); |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - // Remove the test folders that we've created |
|
101 | - $folderIDs = $this->allFixtureIDs('Folder'); |
|
102 | - foreach ($folderIDs as $folderID) { |
|
103 | - $folder = DataObject::get_by_id('Folder', $folderID); |
|
104 | - if ($folder && file_exists(BASE_PATH.'/'.$folder->Filename.'_resampled')) { |
|
105 | - Filesystem::removeFolder(BASE_PATH.'/'.$folder->Filename.'_resampled'); |
|
106 | - } |
|
107 | - if ($folder && file_exists(BASE_PATH."/$folder->Filename")) { |
|
108 | - Filesystem::removeFolder(BASE_PATH."/$folder->Filename"); |
|
109 | - } |
|
110 | - } |
|
111 | - |
|
112 | - parent::tearDown(); |
|
113 | - } |
|
114 | - |
|
115 | - public function testFlushAll() |
|
116 | - { |
|
117 | - $result = SectionIOTest_MySectionIO::flushAll(); |
|
118 | - |
|
119 | - $this->assertCount( |
|
120 | - 1, |
|
121 | - $result, |
|
122 | - 'one url returned for one application id' |
|
123 | - ); |
|
124 | - |
|
125 | - // url |
|
126 | - $this->assertEquals( |
|
127 | - 'https://example.com/account/123456/application/987654/environment/Production/proxy/myproxy/state', |
|
128 | - $result[0]['url'], |
|
129 | - 'URL is concatenated correctly' |
|
130 | - ); |
|
131 | - |
|
132 | - // ban expression |
|
133 | - $this->assertEquals( |
|
134 | - 'obj.http.x-url ~ /', |
|
135 | - $result[0]['banExpression'], |
|
136 | - 'ban expression is correct' |
|
137 | - ); |
|
138 | - |
|
139 | - // headers |
|
140 | - $this->assertContains( |
|
141 | - 'Content-Type: application/json', |
|
142 | - $result[0]['headers'], |
|
143 | - 'content type header is correct' |
|
144 | - ); |
|
145 | - $this->assertContains( |
|
146 | - 'Accept: application/json', |
|
147 | - $result[0]['headers'], |
|
148 | - 'accept header is correct' |
|
149 | - ); |
|
150 | - |
|
151 | - // service |
|
152 | - $this->assertInstanceOf( |
|
153 | - 'RestfulService', |
|
154 | - $result[0]['service'], |
|
155 | - 'service is of type RestfulService' |
|
156 | - ); |
|
157 | - } |
|
158 | - |
|
159 | - public function testFlush() |
|
160 | - { |
|
161 | - $result = SectionIOTest_MySectionIO::flush(); |
|
162 | - |
|
163 | - $this->assertCount( |
|
164 | - 1, |
|
165 | - $result, |
|
166 | - 'one url returned for one application id' |
|
167 | - ); |
|
168 | - |
|
169 | - // url |
|
170 | - $this->assertEquals( |
|
171 | - 'https://example.com/account/123456/application/987654/environment/Production/proxy/myproxy/state', |
|
172 | - $result[0]['url'], |
|
173 | - 'URL is concatenated correctly' |
|
174 | - ); |
|
175 | - |
|
176 | - // ban expression |
|
177 | - $this->assertEquals( |
|
178 | - 'obj.http.x-url ~ /', |
|
179 | - $result[0]['banExpression'], |
|
180 | - 'ban expression is correct' |
|
181 | - ); |
|
182 | - |
|
183 | - // test deactivated flush on build |
|
184 | - Config::inst()->update('SectionIO', 'flush_on_dev_build', false); |
|
185 | - $result = SectionIOTest_MySectionIO::flush(); |
|
186 | - $this->assertNull( |
|
187 | - $result, |
|
188 | - 'null returned if flush on build deactivated' |
|
189 | - ); |
|
190 | - } |
|
191 | - |
|
192 | - public function testMultipleApplicationIDs() |
|
193 | - { |
|
194 | - // add second application to config |
|
195 | - Config::inst()->update('SectionIO', 'application_id', '2546987,856954'); |
|
196 | - |
|
197 | - $result = SectionIOTest_MySectionIO::flushAll(); |
|
198 | - |
|
199 | - $this->assertCount( |
|
200 | - 2, |
|
201 | - $result, |
|
202 | - 'two urls returned for two application id' |
|
203 | - ); |
|
204 | - |
|
205 | - // url |
|
206 | - $this->assertEquals( |
|
207 | - 'https://example.com/account/123456/application/2546987/environment/Production/proxy/myproxy/state', |
|
208 | - $result[0]['url'], |
|
209 | - 'URL is concatenated correctly for app 1' |
|
210 | - ); |
|
211 | - $this->assertEquals( |
|
212 | - 'https://example.com/account/123456/application/856954/environment/Production/proxy/myproxy/state', |
|
213 | - $result[1]['url'], |
|
214 | - 'URL is concatenated correctly for app 2' |
|
215 | - ); |
|
216 | - |
|
217 | - // add second application to config with spaces in csv |
|
218 | - Config::inst()->update('SectionIO', 'application_id', '741852, 369258'); |
|
219 | - |
|
220 | - $result = SectionIOTest_MySectionIO::flushAll(); |
|
221 | - |
|
222 | - $this->assertCount( |
|
223 | - 2, |
|
224 | - $result, |
|
225 | - 'two urls returned for two application id' |
|
226 | - ); |
|
227 | - |
|
228 | - // url |
|
229 | - $this->assertEquals( |
|
230 | - 'https://example.com/account/123456/application/741852/environment/Production/proxy/myproxy/state', |
|
231 | - $result[0]['url'], |
|
232 | - 'URL is concatenated correctly for app 1' |
|
233 | - ); |
|
234 | - $this->assertEquals( |
|
235 | - 'https://example.com/account/123456/application/369258/environment/Production/proxy/myproxy/state', |
|
236 | - $result[1]['url'], |
|
237 | - 'URL is concatenated correctly for app 2' |
|
238 | - ); |
|
239 | - } |
|
240 | - |
|
241 | - public function testFlushImage() |
|
242 | - { |
|
243 | - $imageId = $this->idFromFixture('Image', 'testImage'); |
|
244 | - |
|
245 | - $result = SectionIOTest_MySectionIO::flushImage($imageId); |
|
246 | - |
|
247 | - // ban expression |
|
248 | - $this->assertEquals( |
|
249 | - 'obj.http.x-url ~ "^/assets/SectionTest/test_image\.png$"' |
|
250 | - .' || obj.http.x-url ~ "^/assets/SectionTest/_resampled/(.*)\-test_image\.png$"', |
|
251 | - $result[0]['banExpression'], |
|
252 | - 'ban expression is correct' |
|
253 | - ); |
|
254 | - } |
|
255 | - |
|
256 | - public function testFlushFile() |
|
257 | - { |
|
258 | - $fileId = $this->idFromFixture('File', 'testFile'); |
|
259 | - |
|
260 | - $result = SectionIOTest_MySectionIO::flushFile($fileId); |
|
261 | - |
|
262 | - // ban expression |
|
263 | - $this->assertEquals( |
|
264 | - 'obj.http.x-url ~ "^/assets/SectionTest/test_document\.pdf$"', |
|
265 | - $result[0]['banExpression'], |
|
266 | - 'ban expression is correct' |
|
267 | - ); |
|
268 | - } |
|
269 | - |
|
270 | - public function testFlushSiteTree() |
|
271 | - { |
|
272 | - $pageId = $this->idFromFixture('Page', 'ceo'); |
|
273 | - |
|
274 | - // test single page flush |
|
275 | - Config::inst()->update('SectionIO', 'sitetree_flush_strategy', 'single'); |
|
276 | - $result = SectionIOTest_MySectionIO::flushSiteTree($pageId); |
|
277 | - $this->assertEquals( |
|
278 | - 'obj.http.content-type ~ "text/html"' |
|
279 | - .' && obj.http.x-url ~ "^/about\-us/my\-staff/ceo/$"', |
|
280 | - $result[0]['banExpression'], |
|
281 | - 'ban expression is correct' |
|
282 | - ); |
|
283 | - |
|
284 | - // test parents flush |
|
285 | - Config::inst()->update('SectionIO', 'sitetree_flush_strategy', 'parents'); |
|
286 | - $result = SectionIOTest_MySectionIO::flushSiteTree($pageId); |
|
287 | - $this->assertEquals( |
|
288 | - 'obj.http.content-type ~ "text/html"' |
|
289 | - .' && (obj.http.x-url ~ "^/about\-us/my\-staff/ceo/$" || obj.http.x-url ~ "^/about\-us/my\-staff/$" || obj.http.x-url ~ "^/about\-us/$")', |
|
290 | - $result[0]['banExpression'], |
|
291 | - 'ban expression is correct' |
|
292 | - ); |
|
293 | - |
|
294 | - // test all pages flush |
|
295 | - Config::inst()->update('SectionIO', 'sitetree_flush_strategy', 'all'); |
|
296 | - $result = SectionIOTest_MySectionIO::flushSiteTree($pageId); |
|
297 | - $this->assertEquals( |
|
298 | - 'obj.http.content-type ~ "text/html"', |
|
299 | - $result[0]['banExpression'], |
|
300 | - 'ban expression is correct' |
|
301 | - ); |
|
302 | - |
|
303 | - // test whole site flush |
|
304 | - Config::inst()->update('SectionIO', 'sitetree_flush_strategy', 'everything'); |
|
305 | - $result = SectionIOTest_MySectionIO::flushSiteTree($pageId); |
|
306 | - $this->assertEquals( |
|
307 | - 'obj.http.x-url ~ /', |
|
308 | - $result[0]['banExpression'], |
|
309 | - 'ban expression is correct' |
|
310 | - ); |
|
311 | - } |
|
5 | + protected static $fixture_file = 'SectionIOTest.yml'; |
|
6 | + |
|
7 | + public function setUpOnce() |
|
8 | + { |
|
9 | + parent::setUpOnce(); |
|
10 | + |
|
11 | + // add config values |
|
12 | + Config::inst()->update('SectionIO', 'flush_on_dev_build', true); |
|
13 | + Config::inst()->update('SectionIO', 'api_url', 'https://example.com'); |
|
14 | + Config::inst()->update('SectionIO', 'account_id', '123456'); |
|
15 | + Config::inst()->update('SectionIO', 'application_id', '987654'); |
|
16 | + Config::inst()->update('SectionIO', 'environment_name', 'Production'); |
|
17 | + Config::inst()->update('SectionIO', 'proxy_name', 'myproxy'); |
|
18 | + Config::inst()->update('SectionIO', 'username', 'someuser'); |
|
19 | + Config::inst()->update('SectionIO', 'password', 'MySafePassword'); |
|
20 | + Config::inst()->update('SectionIO', 'verify_ssl', false); |
|
21 | + |
|
22 | + // remove extensions otherwise the fixtures will break the tests (by calling the live flush) |
|
23 | + File::remove_extension('SectionIOFileExtension'); |
|
24 | + SiteTree::remove_extension('SectionIOSiteTreeExtension'); |
|
25 | + } |
|
26 | + |
|
27 | + public function setUp() |
|
28 | + { |
|
29 | + parent::setUp(); |
|
30 | + |
|
31 | + if (!file_exists(ASSETS_PATH)) { |
|
32 | + mkdir(ASSETS_PATH); |
|
33 | + } |
|
34 | + |
|
35 | + // Create a test folders for each of the fixture references |
|
36 | + $folderIDs = $this->allFixtureIDs('Folder'); |
|
37 | + foreach ($folderIDs as $folderID) { |
|
38 | + $folder = DataObject::get_by_id('Folder', $folderID); |
|
39 | + if (!file_exists(BASE_PATH."/$folder->Filename")) { |
|
40 | + mkdir(BASE_PATH."/$folder->Filename"); |
|
41 | + } |
|
42 | + } |
|
43 | + |
|
44 | + // Copy test images for each of the fixture references |
|
45 | + $imageIDs = $this->allFixtureIDs('Image'); |
|
46 | + foreach ($imageIDs as $imageID) { |
|
47 | + $image = DataObject::get_by_id('Image', $imageID); |
|
48 | + $filePath = BASE_PATH."/$image->Filename"; |
|
49 | + $sourcePath = str_replace('assets/SectionTest/', 'section-io/tests/testfiles/', $filePath); |
|
50 | + if (!file_exists($filePath)) { |
|
51 | + if (!copy($sourcePath, $filePath)) { |
|
52 | + user_error('Failed to copy test images', E_USER_ERROR); |
|
53 | + } |
|
54 | + } |
|
55 | + } |
|
56 | + |
|
57 | + // Copy test files for each of the fixture references |
|
58 | + $fileIDs = $this->allFixtureIDs('File'); |
|
59 | + foreach ($fileIDs as $fileID) { |
|
60 | + $file = DataObject::get_by_id('File', $fileID); |
|
61 | + $filePath = BASE_PATH."/$file->Filename"; |
|
62 | + $sourcePath = str_replace('assets/SectionTest/', 'section-io/tests/testfiles/', $filePath); |
|
63 | + if (!file_exists($filePath)) { |
|
64 | + if (!copy($sourcePath, $filePath)) { |
|
65 | + user_error('Failed to copy test files', E_USER_ERROR); |
|
66 | + } |
|
67 | + } |
|
68 | + } |
|
69 | + } |
|
70 | + |
|
71 | + public function tearDownOnce() |
|
72 | + { |
|
73 | + parent::tearDownOnce(); |
|
74 | + |
|
75 | + // re-add extensions |
|
76 | + File::add_extension('SectionIOFileExtension'); |
|
77 | + SiteTree::add_extension('SectionIOSiteTreeExtension'); |
|
78 | + } |
|
79 | + |
|
80 | + public function tearDown() |
|
81 | + { |
|
82 | + // Remove the test images that we've created |
|
83 | + $imageIDs = $this->allFixtureIDs('Image'); |
|
84 | + foreach ($imageIDs as $imageID) { |
|
85 | + $image = DataObject::get_by_id('Image', $imageID); |
|
86 | + if ($image && file_exists(BASE_PATH."/$image->Filename")) { |
|
87 | + unlink(BASE_PATH."/$image->Filename"); |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + // Remove the test files that we've created |
|
92 | + $fileIDs = $this->allFixtureIDs('File'); |
|
93 | + foreach ($fileIDs as $fileID) { |
|
94 | + $file = DataObject::get_by_id('File', $fileID); |
|
95 | + if ($file && file_exists(BASE_PATH."/$file->Filename")) { |
|
96 | + unlink(BASE_PATH."/$file->Filename"); |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + // Remove the test folders that we've created |
|
101 | + $folderIDs = $this->allFixtureIDs('Folder'); |
|
102 | + foreach ($folderIDs as $folderID) { |
|
103 | + $folder = DataObject::get_by_id('Folder', $folderID); |
|
104 | + if ($folder && file_exists(BASE_PATH.'/'.$folder->Filename.'_resampled')) { |
|
105 | + Filesystem::removeFolder(BASE_PATH.'/'.$folder->Filename.'_resampled'); |
|
106 | + } |
|
107 | + if ($folder && file_exists(BASE_PATH."/$folder->Filename")) { |
|
108 | + Filesystem::removeFolder(BASE_PATH."/$folder->Filename"); |
|
109 | + } |
|
110 | + } |
|
111 | + |
|
112 | + parent::tearDown(); |
|
113 | + } |
|
114 | + |
|
115 | + public function testFlushAll() |
|
116 | + { |
|
117 | + $result = SectionIOTest_MySectionIO::flushAll(); |
|
118 | + |
|
119 | + $this->assertCount( |
|
120 | + 1, |
|
121 | + $result, |
|
122 | + 'one url returned for one application id' |
|
123 | + ); |
|
124 | + |
|
125 | + // url |
|
126 | + $this->assertEquals( |
|
127 | + 'https://example.com/account/123456/application/987654/environment/Production/proxy/myproxy/state', |
|
128 | + $result[0]['url'], |
|
129 | + 'URL is concatenated correctly' |
|
130 | + ); |
|
131 | + |
|
132 | + // ban expression |
|
133 | + $this->assertEquals( |
|
134 | + 'obj.http.x-url ~ /', |
|
135 | + $result[0]['banExpression'], |
|
136 | + 'ban expression is correct' |
|
137 | + ); |
|
138 | + |
|
139 | + // headers |
|
140 | + $this->assertContains( |
|
141 | + 'Content-Type: application/json', |
|
142 | + $result[0]['headers'], |
|
143 | + 'content type header is correct' |
|
144 | + ); |
|
145 | + $this->assertContains( |
|
146 | + 'Accept: application/json', |
|
147 | + $result[0]['headers'], |
|
148 | + 'accept header is correct' |
|
149 | + ); |
|
150 | + |
|
151 | + // service |
|
152 | + $this->assertInstanceOf( |
|
153 | + 'RestfulService', |
|
154 | + $result[0]['service'], |
|
155 | + 'service is of type RestfulService' |
|
156 | + ); |
|
157 | + } |
|
158 | + |
|
159 | + public function testFlush() |
|
160 | + { |
|
161 | + $result = SectionIOTest_MySectionIO::flush(); |
|
162 | + |
|
163 | + $this->assertCount( |
|
164 | + 1, |
|
165 | + $result, |
|
166 | + 'one url returned for one application id' |
|
167 | + ); |
|
168 | + |
|
169 | + // url |
|
170 | + $this->assertEquals( |
|
171 | + 'https://example.com/account/123456/application/987654/environment/Production/proxy/myproxy/state', |
|
172 | + $result[0]['url'], |
|
173 | + 'URL is concatenated correctly' |
|
174 | + ); |
|
175 | + |
|
176 | + // ban expression |
|
177 | + $this->assertEquals( |
|
178 | + 'obj.http.x-url ~ /', |
|
179 | + $result[0]['banExpression'], |
|
180 | + 'ban expression is correct' |
|
181 | + ); |
|
182 | + |
|
183 | + // test deactivated flush on build |
|
184 | + Config::inst()->update('SectionIO', 'flush_on_dev_build', false); |
|
185 | + $result = SectionIOTest_MySectionIO::flush(); |
|
186 | + $this->assertNull( |
|
187 | + $result, |
|
188 | + 'null returned if flush on build deactivated' |
|
189 | + ); |
|
190 | + } |
|
191 | + |
|
192 | + public function testMultipleApplicationIDs() |
|
193 | + { |
|
194 | + // add second application to config |
|
195 | + Config::inst()->update('SectionIO', 'application_id', '2546987,856954'); |
|
196 | + |
|
197 | + $result = SectionIOTest_MySectionIO::flushAll(); |
|
198 | + |
|
199 | + $this->assertCount( |
|
200 | + 2, |
|
201 | + $result, |
|
202 | + 'two urls returned for two application id' |
|
203 | + ); |
|
204 | + |
|
205 | + // url |
|
206 | + $this->assertEquals( |
|
207 | + 'https://example.com/account/123456/application/2546987/environment/Production/proxy/myproxy/state', |
|
208 | + $result[0]['url'], |
|
209 | + 'URL is concatenated correctly for app 1' |
|
210 | + ); |
|
211 | + $this->assertEquals( |
|
212 | + 'https://example.com/account/123456/application/856954/environment/Production/proxy/myproxy/state', |
|
213 | + $result[1]['url'], |
|
214 | + 'URL is concatenated correctly for app 2' |
|
215 | + ); |
|
216 | + |
|
217 | + // add second application to config with spaces in csv |
|
218 | + Config::inst()->update('SectionIO', 'application_id', '741852, 369258'); |
|
219 | + |
|
220 | + $result = SectionIOTest_MySectionIO::flushAll(); |
|
221 | + |
|
222 | + $this->assertCount( |
|
223 | + 2, |
|
224 | + $result, |
|
225 | + 'two urls returned for two application id' |
|
226 | + ); |
|
227 | + |
|
228 | + // url |
|
229 | + $this->assertEquals( |
|
230 | + 'https://example.com/account/123456/application/741852/environment/Production/proxy/myproxy/state', |
|
231 | + $result[0]['url'], |
|
232 | + 'URL is concatenated correctly for app 1' |
|
233 | + ); |
|
234 | + $this->assertEquals( |
|
235 | + 'https://example.com/account/123456/application/369258/environment/Production/proxy/myproxy/state', |
|
236 | + $result[1]['url'], |
|
237 | + 'URL is concatenated correctly for app 2' |
|
238 | + ); |
|
239 | + } |
|
240 | + |
|
241 | + public function testFlushImage() |
|
242 | + { |
|
243 | + $imageId = $this->idFromFixture('Image', 'testImage'); |
|
244 | + |
|
245 | + $result = SectionIOTest_MySectionIO::flushImage($imageId); |
|
246 | + |
|
247 | + // ban expression |
|
248 | + $this->assertEquals( |
|
249 | + 'obj.http.x-url ~ "^/assets/SectionTest/test_image\.png$"' |
|
250 | + .' || obj.http.x-url ~ "^/assets/SectionTest/_resampled/(.*)\-test_image\.png$"', |
|
251 | + $result[0]['banExpression'], |
|
252 | + 'ban expression is correct' |
|
253 | + ); |
|
254 | + } |
|
255 | + |
|
256 | + public function testFlushFile() |
|
257 | + { |
|
258 | + $fileId = $this->idFromFixture('File', 'testFile'); |
|
259 | + |
|
260 | + $result = SectionIOTest_MySectionIO::flushFile($fileId); |
|
261 | + |
|
262 | + // ban expression |
|
263 | + $this->assertEquals( |
|
264 | + 'obj.http.x-url ~ "^/assets/SectionTest/test_document\.pdf$"', |
|
265 | + $result[0]['banExpression'], |
|
266 | + 'ban expression is correct' |
|
267 | + ); |
|
268 | + } |
|
269 | + |
|
270 | + public function testFlushSiteTree() |
|
271 | + { |
|
272 | + $pageId = $this->idFromFixture('Page', 'ceo'); |
|
273 | + |
|
274 | + // test single page flush |
|
275 | + Config::inst()->update('SectionIO', 'sitetree_flush_strategy', 'single'); |
|
276 | + $result = SectionIOTest_MySectionIO::flushSiteTree($pageId); |
|
277 | + $this->assertEquals( |
|
278 | + 'obj.http.content-type ~ "text/html"' |
|
279 | + .' && obj.http.x-url ~ "^/about\-us/my\-staff/ceo/$"', |
|
280 | + $result[0]['banExpression'], |
|
281 | + 'ban expression is correct' |
|
282 | + ); |
|
283 | + |
|
284 | + // test parents flush |
|
285 | + Config::inst()->update('SectionIO', 'sitetree_flush_strategy', 'parents'); |
|
286 | + $result = SectionIOTest_MySectionIO::flushSiteTree($pageId); |
|
287 | + $this->assertEquals( |
|
288 | + 'obj.http.content-type ~ "text/html"' |
|
289 | + .' && (obj.http.x-url ~ "^/about\-us/my\-staff/ceo/$" || obj.http.x-url ~ "^/about\-us/my\-staff/$" || obj.http.x-url ~ "^/about\-us/$")', |
|
290 | + $result[0]['banExpression'], |
|
291 | + 'ban expression is correct' |
|
292 | + ); |
|
293 | + |
|
294 | + // test all pages flush |
|
295 | + Config::inst()->update('SectionIO', 'sitetree_flush_strategy', 'all'); |
|
296 | + $result = SectionIOTest_MySectionIO::flushSiteTree($pageId); |
|
297 | + $this->assertEquals( |
|
298 | + 'obj.http.content-type ~ "text/html"', |
|
299 | + $result[0]['banExpression'], |
|
300 | + 'ban expression is correct' |
|
301 | + ); |
|
302 | + |
|
303 | + // test whole site flush |
|
304 | + Config::inst()->update('SectionIO', 'sitetree_flush_strategy', 'everything'); |
|
305 | + $result = SectionIOTest_MySectionIO::flushSiteTree($pageId); |
|
306 | + $this->assertEquals( |
|
307 | + 'obj.http.x-url ~ /', |
|
308 | + $result[0]['banExpression'], |
|
309 | + 'ban expression is correct' |
|
310 | + ); |
|
311 | + } |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | class SectionIOTest_MySectionIO extends SectionIO |
315 | 315 | { |
316 | - protected static function performFlush($banExpression) |
|
317 | - { |
|
318 | - $result = array(); |
|
319 | - $urls = static::getUrls(); |
|
320 | - // config loaded successfully |
|
321 | - if ($urls) { |
|
322 | - foreach ($urls as $url) { |
|
323 | - |
|
324 | - // get restful service object |
|
325 | - $service = static::getService($url, $banExpression); |
|
326 | - |
|
327 | - // prepare headers |
|
328 | - $headers = static::getHeaders(); |
|
329 | - |
|
330 | - // prepare curl options |
|
331 | - $options = static::getOptions(); |
|
332 | - |
|
333 | - // store data for return |
|
334 | - $data = array(); |
|
335 | - $data['url'] = $url; |
|
336 | - $data['banExpression'] = $banExpression; |
|
337 | - $data['headers'] = $headers; |
|
338 | - $data['options'] = $options; |
|
339 | - $data['service'] = $service; |
|
340 | - $result[] = $data; |
|
341 | - } |
|
342 | - } else { |
|
343 | - user_error('SectionIOTest_MySectionIO::performFlush :: no URLs loaded for ban.', E_USER_WARNING); |
|
344 | - } |
|
345 | - |
|
346 | - return $result; |
|
347 | - } |
|
316 | + protected static function performFlush($banExpression) |
|
317 | + { |
|
318 | + $result = array(); |
|
319 | + $urls = static::getUrls(); |
|
320 | + // config loaded successfully |
|
321 | + if ($urls) { |
|
322 | + foreach ($urls as $url) { |
|
323 | + |
|
324 | + // get restful service object |
|
325 | + $service = static::getService($url, $banExpression); |
|
326 | + |
|
327 | + // prepare headers |
|
328 | + $headers = static::getHeaders(); |
|
329 | + |
|
330 | + // prepare curl options |
|
331 | + $options = static::getOptions(); |
|
332 | + |
|
333 | + // store data for return |
|
334 | + $data = array(); |
|
335 | + $data['url'] = $url; |
|
336 | + $data['banExpression'] = $banExpression; |
|
337 | + $data['headers'] = $headers; |
|
338 | + $data['options'] = $options; |
|
339 | + $data['service'] = $service; |
|
340 | + $result[] = $data; |
|
341 | + } |
|
342 | + } else { |
|
343 | + user_error('SectionIOTest_MySectionIO::performFlush :: no URLs loaded for ban.', E_USER_WARNING); |
|
344 | + } |
|
345 | + |
|
346 | + return $result; |
|
347 | + } |
|
348 | 348 | } |
@@ -2,12 +2,12 @@ |
||
2 | 2 | |
3 | 3 | class SectionIOFileExtension extends DataExtension |
4 | 4 | { |
5 | - public function onAfterWrite() |
|
6 | - { |
|
7 | - if (is_a($this->owner, 'Image')) { |
|
8 | - SectionIO::flushImage($this->owner->ID); |
|
9 | - } else { |
|
10 | - SectionIO::flushFile($this->owner->ID); |
|
11 | - } |
|
12 | - } |
|
5 | + public function onAfterWrite() |
|
6 | + { |
|
7 | + if (is_a($this->owner, 'Image')) { |
|
8 | + SectionIO::flushImage($this->owner->ID); |
|
9 | + } else { |
|
10 | + SectionIO::flushFile($this->owner->ID); |
|
11 | + } |
|
12 | + } |
|
13 | 13 | } |
@@ -99,6 +99,9 @@ |
||
99 | 99 | return false; |
100 | 100 | } |
101 | 101 | |
102 | + /** |
|
103 | + * @param string $banExpression |
|
104 | + */ |
|
102 | 105 | protected static function performFlush($banExpression) |
103 | 106 | { |
104 | 107 | $success = true; |
@@ -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 { |
@@ -1,8 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | class SectionIOFormControllerExtension extends Extension { |
3 | 3 | |
4 | - public function onAfterInit() { |
|
5 | - $response = $this->owner->getResponse(); |
|
6 | - $response->addHeader("X-SS-Form", "1"); |
|
7 | - } |
|
4 | + public function onAfterInit() { |
|
5 | + $response = $this->owner->getResponse(); |
|
6 | + $response->addHeader("X-SS-Form", "1"); |
|
7 | + } |
|
8 | 8 | } |
9 | 9 | \ No newline at end of file |
@@ -2,8 +2,8 @@ |
||
2 | 2 | |
3 | 3 | class SectionIODMSDocumentExtension extends DataExtension |
4 | 4 | { |
5 | - public function onAfterWrite() |
|
6 | - { |
|
7 | - SectionIO::flushURL($this->owner->getLink()); |
|
8 | - } |
|
5 | + public function onAfterWrite() |
|
6 | + { |
|
7 | + SectionIO::flushURL($this->owner->getLink()); |
|
8 | + } |
|
9 | 9 | } |
@@ -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 | } |