From 523c467eed670c59580ede2ab1dbe8b4ad59c800 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 8 Apr 2009 15:11:55 +0000 Subject: Fixes issues with Server Add: 1) Fixes Ticket #208 2) Fixes Ticket #190 3) Fixes an unticketed issue where two items could collide when creating the thumbnail and/or resize. For example, loading a.flv and a.jpg would have generated the same thumbnail image. This change adds a random value to the name to avoid conflicts. 4) Added item::__set() to clear the relative path if the name changes --- core/helpers/photo.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'core/helpers/photo.php') diff --git a/core/helpers/photo.php b/core/helpers/photo.php index a3f88ecb..a6934286 100644 --- a/core/helpers/photo.php +++ b/core/helpers/photo.php @@ -74,11 +74,17 @@ class photo_Core { // @todo Improve this. Random numbers are not user friendly $photo->name = rand() . "." . $pi["extension"]; } + // This saves the photo $photo->add_to_parent($parent); - // If the thumb or resize already exists then rename it - if (file_exists($photo->resize_path()) || file_exists($photo->thumb_path())) { + /* + * If the thumb or resize already exists then rename it. We need to do this after the save + * because the resize_path and thumb_path both call relative_path which caches the + * path. Before add_to_parent the relative path will be incorrect. + */ + if (file_exists($photo->resize_path()) || + file_exists($photo->thumb_path())) { $photo->name = $pi["filename"] . "-" . rand() . "." . $pi["extension"]; $photo->save(); } @@ -91,7 +97,6 @@ class photo_Core { graphics::generate($photo); // If the parent has no cover item, make this it. - $parent = $photo->parent(); if ($parent->album_cover_item_id == null) { $parent->album_cover_item_id = $photo->id; $parent->save(); -- cgit v1.2.3