diff --git a/classes/Scene.php b/classes/Scene.php index 2c50c85dd..296660c63 100644 --- a/classes/Scene.php +++ b/classes/Scene.php @@ -118,6 +118,10 @@ class SceneCore extends ObjectModel public function deleteImage() { + // Hack to prevent the main scene image from being deleted in AdminController::uploadImage() when a thumb image is uploaded + if (isset($_FILES['thumb']) && (!isset($_FILES['image']) || empty($_FILES['image']['name']))) + return true; + if (parent::deleteImage()) { if (file_exists($this->image_dir.'thumbs/'.$this->id.'-thumb_scene.'.$this->image_format) diff --git a/controllers/admin/AdminScenesController.php b/controllers/admin/AdminScenesController.php index e8e3bd690..f94303f43 100644 --- a/controllers/admin/AdminScenesController.php +++ b/controllers/admin/AdminScenesController.php @@ -69,15 +69,17 @@ class AdminScenesControllerCore extends AdminController /* Generate image with differents size */ if (!($obj = $this->loadObject(true))) return; + if ($obj->id && (isset($_FILES['image']) || isset($_FILES['thumb']))) { + $base_img_path = _PS_SCENE_IMG_DIR_.$obj->id.'.jpg'; $images_types = ImageType::getImagesTypes('scenes'); foreach ($images_types as $k => $image_type) { if ($image_type['name'] == 'large_scene' && isset($_FILES['image'])) ImageManager::resize( - $_FILES['image']['tmp_name'], + $base_img_path, _PS_SCENE_IMG_DIR_.$obj->id.'-'.stripslashes($image_type['name']).'.jpg', (int)$image_type['width'], (int)$image_type['height'] @@ -85,11 +87,11 @@ class AdminScenesControllerCore extends AdminController else if ($image_type['name'] == 'thumb_scene') { if (isset($_FILES['thumb']) && !$_FILES['thumb']['error']) - $tmp_name = $_FILES['thumb']['tmp_name']; + $base_thumb_path = _PS_SCENE_THUMB_IMG_DIR_.$obj->id.'.jpg'; else - $tmp_name = $_FILES['image']['tmp_name']; + $base_thumb_path = $base_img_path; ImageManager::resize( - $tmp_name, + $base_thumb_path, _PS_SCENE_THUMB_IMG_DIR_.$obj->id.'-'.stripslashes($image_type['name']).'.jpg', (int)$image_type['width'], (int)$image_type['height']