Fixed 'clear' button not working when files failed to import

This commit is contained in:
Duncan Sommerville 2014-11-10 16:07:23 -05:00
parent af8c6c2f48
commit 769e0e1d82

View file

@ -1,8 +1,13 @@
<?php
class Rest_MediaController extends Zend_Rest_Controller
{
const MUSIC_DIRS_STOR_PK = 1;
const IMPORT_STATUS_SUCCESS = 0;
const IMPORT_STATUS_PENDING = 1;
const IMPORT_STATUS_FAILED = 2;
//fields that are not modifiable via our RESTful API
private static $blackList = array(
'id',
@ -214,6 +219,8 @@ class Rest_MediaController extends Zend_Rest_Controller
}
$file = CcFilesQuery::create()->findPk($id);
// Since we check for this value when deleting files, set it first
$file->setDbDirectory(self::MUSIC_DIRS_STOR_PK);
$requestData = json_decode($this->getRequest()->getRawBody(), true);
$whiteList = $this->removeBlacklistedFieldsFromRequestData($requestData);
@ -232,7 +239,7 @@ class Rest_MediaController extends Zend_Rest_Controller
$fileSizeBytes = filesize($requestData["full_path"]);
if ($fileSizeBytes === false)
{
$file->setDbImportStatus(2)->save();
$file->setDbImportStatus(self::IMPORT_STATUS_FAILED)->save();
$this->fileNotFoundResponse();
return;
}
@ -248,7 +255,6 @@ class Rest_MediaController extends Zend_Rest_Controller
$filePathRelativeToStor = substr($fullPath, strlen($storDir));
$file->setDbFilepath($filePathRelativeToStor);
$file->setDbDirectory(1); //1 corresponds to the default stor/imported directory.
}
}
@ -263,7 +269,7 @@ class Rest_MediaController extends Zend_Rest_Controller
->setHttpResponseCode(200)
->appendBody(json_encode(CcFiles::sanitizeResponse($file)));
} else {
$file->setDbImportStatus(2)->save();
$file->setDbImportStatus(self::IMPORT_STATUS_FAILED)->save();
$this->fileNotFoundResponse();
}
}
@ -274,6 +280,7 @@ class Rest_MediaController extends Zend_Rest_Controller
{
return;
}
$id = $this->getId();
if (!$id) {