From f64b7d0813ea2e791efbcdc299aec101542e0506 Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Wed, 17 Sep 2014 10:27:14 -0400 Subject: [PATCH] Updated show edit functionality to accommodate uploading new show image --- .../controllers/ScheduleController.php | 22 +++++++++++++++---- .../rest/controllers/ShowController.php | 10 +++------ .../application/services/ShowService.php | 11 ++++++++-- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index e8ef3df36..de7a79dc9 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -531,13 +531,24 @@ class ScheduleController extends Zend_Controller_Action list($data, $validateStartDate, $validateStartTime, $originalShowStartDateTime) = $service_showForm->preEditShowValidationCheck($data); + + /* + * hack to prevent validating the file upload field since it + * isn't passed into $data + */ + $upload = $forms["style"]->getElement("upload"); + $forms["style"]->removeElement("upload"); + if ($service_showForm->validateShowForms($forms, $data, $validateStartDate, $originalShowStartDateTime, true, $data["add_show_instance_id"])) { - - $service_show->addUpdateShow($data); - - $this->view->addNewShow = true; + // Get the show ID from the show service to pass as a parameter to the RESTful ShowController + $this->view->showId = $service_show->addUpdateShow($data); + + // re-add the upload element + $forms["style"]->addElement($upload); + + $this->view->addNewShow = true; $this->view->newForm = $this->view->render('schedule/add-show-form.phtml'); } else { if (!$validateStartDate) { @@ -547,6 +558,9 @@ class ScheduleController extends Zend_Controller_Action $this->view->when->getElement('add_show_start_time')->setOptions(array('disabled' => true)); } //$this->view->rr->getElement('add_show_record')->setOptions(array('disabled' => true)); + // re-add the upload element + $forms["style"]->addElement($upload); + $this->view->addNewShow = false; $this->view->action = "edit-show"; $this->view->form = $this->view->render('schedule/add-show-form.phtml'); diff --git a/airtime_mvc/application/modules/rest/controllers/ShowController.php b/airtime_mvc/application/modules/rest/controllers/ShowController.php index a8b06fbbf..e5f16b07f 100644 --- a/airtime_mvc/application/modules/rest/controllers/ShowController.php +++ b/airtime_mvc/application/modules/rest/controllers/ShowController.php @@ -55,8 +55,6 @@ class Rest_ShowController extends Zend_Rest_Controller public function uploadImageAction() { - Logging::info("Uploading image: " . $_FILES["file"]); - if (!$this->restAuth->verifyAuth(true, true)) { Logging::info("Authentication failed"); @@ -64,7 +62,6 @@ class Rest_ShowController extends Zend_Rest_Controller } $showId = $this->getShowId(); - Logging::info("Show Id " . $showId); if (!$showId) { Logging::info("No show id provided"); @@ -162,8 +159,7 @@ class Rest_ShowController extends Zend_Rest_Controller // Did all the checks for real, now trying to copy $image_stor = Application_Common_OsPath::join($importedStorageDirectory, $newFileName); - Logging::info($newFileName); - Logging::info($image_stor); + Logging::info("Adding image: " . $image_stor); Logging::info("copyFileToStor: moving file $image_file to $image_stor"); if (@rename($image_file, $image_stor) === false) { @@ -181,14 +177,14 @@ class Rest_ShowController extends Zend_Rest_Controller return $image_stor; } - public static function deleteFileFromStor($showId) { + public static function deleteFilesFromStor($showId) { $auth = new RestAuth(); $ownerId = $auth->getOwnerId(); $storDir = Application_Model_MusicDir::getStorDir(); $importedStorageDirectory = $storDir->getDirectory() . "imported/" . $ownerId . "/show-images/" . $showId; - Logging::info($importedStorageDirectory); + Logging::info("Deleting images from " . $importedStorageDirectory); // to be safe in case image uploading functionality is extended later return Rest_ShowController::delTree($importedStorageDirectory); diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index d3dcb32ad..5fd8c354c 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -198,7 +198,13 @@ class Application_Service_ShowService $daysAdded = array(); if ($this->isUpdate) { - + + // Delete previous show images + $showId = $this->ccShow->getDbId(); + if (!Rest_ShowController::deleteFilesFromStor($showId)) { + throw new Exception("Error deleting show images"); + } + if (!$this->ccShow->getCcShowDayss()->isEmpty()) { $this->storeOrigLocalShowInfo(); } @@ -746,8 +752,9 @@ SQL; throw new Exception("Could not find show instance"); } + // Delete show images $showId = $ccShowInstance->getDbShowId(); - if (!Rest_ShowController::deleteFileFromStor($showId)) { + if (!Rest_ShowController::deleteFilesFromStor($showId)) { throw new Exception("Error deleting show images"); }