@@ -1,8 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | class ImageEditPartialCacheBustExtensionTest extends SapphireTest { |
| 4 | - public function testOnAfterWrite() { |
|
| 5 | - $this->markTestSkipped('TODO'); |
|
| 6 | - } |
|
| 4 | + public function testOnAfterWrite() { |
|
| 5 | + $this->markTestSkipped('TODO'); |
|
| 6 | + } |
|
| 7 | 7 | |
| 8 | 8 | } |
@@ -2,46 +2,46 @@ |
||
| 2 | 2 | |
| 3 | 3 | class ImageEditPartialCacheBustExtension extends DataExtension { |
| 4 | 4 | |
| 5 | - /* |
|
| 5 | + /* |
|
| 6 | 6 | This is intended to be added to Image as an extension. When an image is edited checks are made |
| 7 | 7 | against a configurable list of classes mapped to the image ID field. If the image ID field value matches |
| 8 | 8 | the ID of the image being refocussed, the DataObject's LastEdited field is updated. |
| 9 | 9 | */ |
| 10 | - public function onAfterWrite() { |
|
| 11 | - $config = Config::inst(); |
|
| 12 | - $sitetreeclasses = $config->get('ImageEditCacheBust', 'SiteTree'); |
|
| 13 | - $dataobjectclasses = $config->get('ImageEditCacheBust', 'DataObject'); |
|
| 14 | - $stages = $config->get('ImageEditCacheBust', 'Stages'); |
|
| 10 | + public function onAfterWrite() { |
|
| 11 | + $config = Config::inst(); |
|
| 12 | + $sitetreeclasses = $config->get('ImageEditCacheBust', 'SiteTree'); |
|
| 13 | + $dataobjectclasses = $config->get('ImageEditCacheBust', 'DataObject'); |
|
| 14 | + $stages = $config->get('ImageEditCacheBust', 'Stages'); |
|
| 15 | 15 | |
| 16 | - if ($sitetreeclasses) { |
|
| 17 | - // deal with SiteTree first |
|
| 18 | - foreach ($sitetreeclasses as $clazz => $idfield) { |
|
| 19 | - $instanceofclass = Injector::inst()->create($clazz); |
|
| 20 | - $objectsWithImage = $instanceofclass::get()->filter($idfield, $this->owner->ID); |
|
| 21 | - foreach ($objectsWithImage as $objectWithImage) { |
|
| 22 | - foreach ($stages as $stage) { |
|
| 23 | - $suffix = '_'.$stage; |
|
| 24 | - $suffix = str_replace('_Stage', '', $suffix); |
|
| 25 | - $sql = "UPDATE `SiteTree{$suffix}` SET LastEdited=NOW() where ID=".$objectWithImage->ID; |
|
| 26 | - DB::query($sql); |
|
| 27 | - } |
|
| 28 | - } |
|
| 29 | - } |
|
| 30 | - } |
|
| 16 | + if ($sitetreeclasses) { |
|
| 17 | + // deal with SiteTree first |
|
| 18 | + foreach ($sitetreeclasses as $clazz => $idfield) { |
|
| 19 | + $instanceofclass = Injector::inst()->create($clazz); |
|
| 20 | + $objectsWithImage = $instanceofclass::get()->filter($idfield, $this->owner->ID); |
|
| 21 | + foreach ($objectsWithImage as $objectWithImage) { |
|
| 22 | + foreach ($stages as $stage) { |
|
| 23 | + $suffix = '_'.$stage; |
|
| 24 | + $suffix = str_replace('_Stage', '', $suffix); |
|
| 25 | + $sql = "UPDATE `SiteTree{$suffix}` SET LastEdited=NOW() where ID=".$objectWithImage->ID; |
|
| 26 | + DB::query($sql); |
|
| 27 | + } |
|
| 28 | + } |
|
| 29 | + } |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | 33 | |
| 34 | - if ($dataobjectclasses) { |
|
| 35 | - // deal with SiteTree first |
|
| 36 | - foreach ($dataobjectclasses as $clazz => $idfield) { |
|
| 37 | - $instanceofclass = Injector::inst()->create($clazz); |
|
| 38 | - $objectsWithImage = $instanceofclass::get()->filter($idfield, $this->owner->ID); |
|
| 39 | - foreach ($objectsWithImage as $objectWithImage) { |
|
| 40 | - $sql = "UPDATE `$clazz` SET LastEdited=NOW() where ID=".$objectWithImage->ID; |
|
| 41 | - DB::query($sql); |
|
| 34 | + if ($dataobjectclasses) { |
|
| 35 | + // deal with SiteTree first |
|
| 36 | + foreach ($dataobjectclasses as $clazz => $idfield) { |
|
| 37 | + $instanceofclass = Injector::inst()->create($clazz); |
|
| 38 | + $objectsWithImage = $instanceofclass::get()->filter($idfield, $this->owner->ID); |
|
| 39 | + foreach ($objectsWithImage as $objectWithImage) { |
|
| 40 | + $sql = "UPDATE `$clazz` SET LastEdited=NOW() where ID=".$objectWithImage->ID; |
|
| 41 | + DB::query($sql); |
|
| 42 | 42 | |
| 43 | - } |
|
| 44 | - } |
|
| 45 | - } |
|
| 46 | - } |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | 47 | } |
| 48 | 48 | \ No newline at end of file |
@@ -20,9 +20,9 @@ discard block |
||
| 20 | 20 | $objectsWithImage = $instanceofclass::get()->filter($idfield, $this->owner->ID); |
| 21 | 21 | foreach ($objectsWithImage as $objectWithImage) { |
| 22 | 22 | foreach ($stages as $stage) { |
| 23 | - $suffix = '_'.$stage; |
|
| 23 | + $suffix = '_' . $stage; |
|
| 24 | 24 | $suffix = str_replace('_Stage', '', $suffix); |
| 25 | - $sql = "UPDATE `SiteTree{$suffix}` SET LastEdited=NOW() where ID=".$objectWithImage->ID; |
|
| 25 | + $sql = "UPDATE `SiteTree{$suffix}` SET LastEdited=NOW() where ID=" . $objectWithImage->ID; |
|
| 26 | 26 | DB::query($sql); |
| 27 | 27 | } |
| 28 | 28 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | $instanceofclass = Injector::inst()->create($clazz); |
| 38 | 38 | $objectsWithImage = $instanceofclass::get()->filter($idfield, $this->owner->ID); |
| 39 | 39 | foreach ($objectsWithImage as $objectWithImage) { |
| 40 | - $sql = "UPDATE `$clazz` SET LastEdited=NOW() where ID=".$objectWithImage->ID; |
|
| 40 | + $sql = "UPDATE `$clazz` SET LastEdited=NOW() where ID=" . $objectWithImage->ID; |
|
| 41 | 41 | DB::query($sql); |
| 42 | 42 | |
| 43 | 43 | } |