X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=DataObjects%2FImages.php;fp=DataObjects%2FImages.php;h=5783a2d23f457152116d84dc0317fa100f10bf21;hp=907b890dacd81661757e6f14b5300377f16f0535;hb=c65ad9cedbf05a7a1c9fc4f5a1146fe5b8fa1dc3;hpb=c59690f8a6802c8c95086a25b354479e87e1e8f3 diff --git a/DataObjects/Images.php b/DataObjects/Images.php index 907b890d..5783a2d2 100644 --- a/DataObjects/Images.php +++ b/DataObjects/Images.php @@ -200,13 +200,10 @@ class Pman_Core_DataObjects_Images extends DB_DataObject * * @return - target file name */ - function getStoreName($alt = false) + function getStoreName() { $opts = HTML_FlexyFramework::get()->Pman; $fn = preg_replace('/[^a-z0-9_\.]+/i', '_', $this->filename); - if ($alt) { - $fn = preg_replace('/[^a-z0-9\.]+/i', '_', $this->filename); - } return implode( '/', array( $opts['storedir'], '_images_', date('Y/m', strtotime($this->created)), $this->id . '-'. $fn )); @@ -220,7 +217,39 @@ class Pman_Core_DataObjects_Images extends DB_DataObject { clearstatcache(); //var_dump($this->getStoreName()); - return file_exists($this->getStoreName()); + $ret = file_exists($this->getStoreName()); + if (!$ret) { + return $this->canFix(); + } + return $ret; + } + + function canFix() { + // look for the image in the folder, with matching id. + // this is problematic.. + $fn = $this->getStoreName(); + if (file_exists($fn . '-really-missing')) { + return false; + } + if (!file_exists(dirname($fn))) { + return false; + } + foreach( scandir(dirname($fn)) as $n) { + if (empty($n) || $n[0] == '.') { + continue; + } + $bits = explode('-', $n); + if ($bits[0] != $this->id) { + continue; + } + if (preg_match('/\.[0-9]+x[0-9]]+\.jpeg$/', $n)) { + continue; + } + copy(dirname($fn). '/'. $n, $fn); + clearstatcache(); + return true; + } + // fixme - flag it as bad } @@ -672,9 +701,6 @@ class Pman_Core_DataObjects_Images extends DB_DataObject function toFileConvert() { $fn = $this->getStoreName(); - if (!file_exists($fn)) { - $fn = $this->getStoreName(true); - } require_once 'File/Convert.php'; $fc = new File_Convert($this->getStoreName(), $this->mimetype);