+
+ /**
+ * does the files exist?
+ */
+ function exists()
+ {
+ return self::staticExists($this);
+ }
+
+ static function staticExists($o)
+ {
+ clearstatcache();
+ $ret = file_exists(self::staticGetStoreName($o));
+ if (!$ret) {
+ return self::staticCanFix($o);
+ }
+ return $ret;
+ }
+
+ /**
+ * the getStorename code got changed, and some old files may not end up with the correct name anymore.
+ * this tries to fix it.
+ *
+ */
+ function canFix()
+ {
+ return self::staticCanFix($this);
+ }
+
+ static function staticCanFix($o)
+ {
+ // look for the image in the folder, with matching id.
+ // this is problematic..
+ $fn = self::staticGetStoreName($o);
+ 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] != $o->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
+ touch($fn . '-really-missing');
+ }
+
+