Updated show edit functionality to accommodate uploading new show image

This commit is contained in:
Duncan Sommerville 2014-09-17 10:27:14 -04:00
parent b2d81f370a
commit f64b7d0813
3 changed files with 30 additions and 13 deletions

View File

@ -531,13 +531,24 @@ class ScheduleController extends Zend_Controller_Action
list($data, $validateStartDate, $validateStartTime, $originalShowStartDateTime) = list($data, $validateStartDate, $validateStartTime, $originalShowStartDateTime) =
$service_showForm->preEditShowValidationCheck($data); $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, if ($service_showForm->validateShowForms($forms, $data, $validateStartDate,
$originalShowStartDateTime, true, $data["add_show_instance_id"])) { $originalShowStartDateTime, true, $data["add_show_instance_id"])) {
// Get the show ID from the show service to pass as a parameter to the RESTful ShowController
$service_show->addUpdateShow($data); $this->view->showId = $service_show->addUpdateShow($data);
$this->view->addNewShow = true; // re-add the upload element
$forms["style"]->addElement($upload);
$this->view->addNewShow = true;
$this->view->newForm = $this->view->render('schedule/add-show-form.phtml'); $this->view->newForm = $this->view->render('schedule/add-show-form.phtml');
} else { } else {
if (!$validateStartDate) { 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->when->getElement('add_show_start_time')->setOptions(array('disabled' => true));
} }
//$this->view->rr->getElement('add_show_record')->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->addNewShow = false;
$this->view->action = "edit-show"; $this->view->action = "edit-show";
$this->view->form = $this->view->render('schedule/add-show-form.phtml'); $this->view->form = $this->view->render('schedule/add-show-form.phtml');

View File

@ -55,8 +55,6 @@ class Rest_ShowController extends Zend_Rest_Controller
public function uploadImageAction() public function uploadImageAction()
{ {
Logging::info("Uploading image: " . $_FILES["file"]);
if (!$this->restAuth->verifyAuth(true, true)) if (!$this->restAuth->verifyAuth(true, true))
{ {
Logging::info("Authentication failed"); Logging::info("Authentication failed");
@ -64,7 +62,6 @@ class Rest_ShowController extends Zend_Rest_Controller
} }
$showId = $this->getShowId(); $showId = $this->getShowId();
Logging::info("Show Id " . $showId);
if (!$showId) { if (!$showId) {
Logging::info("No show id provided"); 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 // Did all the checks for real, now trying to copy
$image_stor = Application_Common_OsPath::join($importedStorageDirectory, $newFileName); $image_stor = Application_Common_OsPath::join($importedStorageDirectory, $newFileName);
Logging::info($newFileName); Logging::info("Adding image: " . $image_stor);
Logging::info($image_stor);
Logging::info("copyFileToStor: moving file $image_file to $image_stor"); Logging::info("copyFileToStor: moving file $image_file to $image_stor");
if (@rename($image_file, $image_stor) === false) { if (@rename($image_file, $image_stor) === false) {
@ -181,14 +177,14 @@ class Rest_ShowController extends Zend_Rest_Controller
return $image_stor; return $image_stor;
} }
public static function deleteFileFromStor($showId) { public static function deleteFilesFromStor($showId) {
$auth = new RestAuth(); $auth = new RestAuth();
$ownerId = $auth->getOwnerId(); $ownerId = $auth->getOwnerId();
$storDir = Application_Model_MusicDir::getStorDir(); $storDir = Application_Model_MusicDir::getStorDir();
$importedStorageDirectory = $storDir->getDirectory() . "imported/" . $ownerId . "/show-images/" . $showId; $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 // to be safe in case image uploading functionality is extended later
return Rest_ShowController::delTree($importedStorageDirectory); return Rest_ShowController::delTree($importedStorageDirectory);

View File

@ -198,7 +198,13 @@ class Application_Service_ShowService
$daysAdded = array(); $daysAdded = array();
if ($this->isUpdate) { 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()) { if (!$this->ccShow->getCcShowDayss()->isEmpty()) {
$this->storeOrigLocalShowInfo(); $this->storeOrigLocalShowInfo();
} }
@ -746,8 +752,9 @@ SQL;
throw new Exception("Could not find show instance"); throw new Exception("Could not find show instance");
} }
// Delete show images
$showId = $ccShowInstance->getDbShowId(); $showId = $ccShowInstance->getDbShowId();
if (!Rest_ShowController::deleteFileFromStor($showId)) { if (!Rest_ShowController::deleteFilesFromStor($showId)) {
throw new Exception("Error deleting show images"); throw new Exception("Error deleting show images");
} }