mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge pull request #98 from oddnoc/deleteFormattedImages-fixes
Delete formatted images fixes (Image)
This commit is contained in:
commit
cd6ad64b53
@ -339,7 +339,7 @@ class Image extends File {
|
||||
if(!$this->Filename) return 0;
|
||||
|
||||
$numDeleted = 0;
|
||||
$methodNames = $this->allMethodNames();
|
||||
$methodNames = $this->allMethodNames(true);
|
||||
$cachedFiles = array();
|
||||
|
||||
$folder = $this->ParentID ? $this->Parent()->Filename : ASSETS_DIR . '/';
|
||||
@ -361,13 +361,13 @@ class Image extends File {
|
||||
foreach($methodNames as $methodName) {
|
||||
if(substr($methodName, 0, 8) == 'generate') {
|
||||
$format = substr($methodName, 8);
|
||||
$generateFuncs[] = $format;
|
||||
$generateFuncs[] = preg_quote($format);
|
||||
}
|
||||
}
|
||||
// All generate functions may appear any number of times in the image cache name.
|
||||
$generateFuncs = implode('|', $generateFuncs);
|
||||
$pattern = "/^(({$generateFuncs})\d+\-)+{$this->Name}$/i";
|
||||
|
||||
$pattern = "/^(({$generateFuncs})\d+\-)+" . preg_quote($this->Name) . "$/i";
|
||||
|
||||
foreach($cachedFiles as $cfile) {
|
||||
if(preg_match($pattern, $cfile)) {
|
||||
if(Director::fileExists($cacheDir . $cfile)) {
|
||||
|
@ -93,4 +93,13 @@ class ImageTest extends SapphireTest {
|
||||
$actual = $imageSecond->getHeight();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
function testGeneratedImageDeletion() {
|
||||
$image = $this->objFromFixture('Image', 'imageWithMetacharacters');
|
||||
$image_generated = $image->SetWidth(200);
|
||||
$p = $image_generated->getFullPath();
|
||||
$this->assertTrue(file_exists($p));
|
||||
$image->deleteFormattedImages();
|
||||
$this->assertFalse(file_exists($p));
|
||||
}
|
||||
}
|
@ -11,4 +11,8 @@ Image:
|
||||
Parent: =>Folder.folder1
|
||||
imageWithoutTitleContainingDots:
|
||||
Filename: assets/ImageTest/test.image.with.dots.png
|
||||
Parent: =>Folder.folder1
|
||||
Parent: =>Folder.folder1
|
||||
imageWithMetacharacters:
|
||||
Title: This is a/an image Title
|
||||
Filename: assets/ImageTest/test_image*).png
|
||||
Parent: =>Folder.folder1
|
||||
|
Loading…
x
Reference in New Issue
Block a user