Merge pull request #98 from oddnoc/deleteFormattedImages-fixes

Delete formatted images fixes (Image)
This commit is contained in:
Sam Minnée 2011-10-31 12:55:06 -07:00
commit cd6ad64b53
3 changed files with 18 additions and 5 deletions

View File

@ -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,12 +361,12 @@ 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)) {

View File

@ -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));
}
}

View File

@ -12,3 +12,7 @@ Image:
imageWithoutTitleContainingDots:
Filename: assets/ImageTest/test.image.with.dots.png
Parent: =>Folder.folder1
imageWithMetacharacters:
Title: This is a/an image Title
Filename: assets/ImageTest/test_image*).png
Parent: =>Folder.folder1