Merge branch 'saas' into saas-media-refactor

Conflicts:
	airtime_mvc/application/modules/rest/controllers/MediaController.php
This commit is contained in:
Albert Santoni 2015-02-26 14:26:33 -05:00
commit f1a311dad6
4 changed files with 62 additions and 59 deletions

View file

@ -192,74 +192,76 @@ class CcFiles extends BaseCcFiles {
$fileArray = self::removeBlacklistedFields($fileArray); $fileArray = self::removeBlacklistedFields($fileArray);
$fileArray = self::stripTimeStampFromYearTag($fileArray); $fileArray = self::stripTimeStampFromYearTag($fileArray);
self::validateFileArray($fileArray); try {
if ($file && isset($fileArray["resource_id"])) {
$file->fromArray($fileArray, BasePeer::TYPE_FIELDNAME); self::validateFileArray($fileArray);
if ($file && isset($fileArray["resource_id"])) {
//store the original filename $file->fromArray($fileArray, BasePeer::TYPE_FIELDNAME);
$file->setDbFilepath($fileArray["filename"]);
$fileSizeBytes = $fileArray["filesize"]; //store the original filename
if (!isset($fileSizeBytes) || $fileSizeBytes === false) $file->setDbFilepath($fileArray["filename"]);
{
$file->setDbImportStatus(self::IMPORT_STATUS_FAILED)->save();
throw new FileNotFoundException();
}
$cloudFile = new CloudFile(); $fileSizeBytes = $fileArray["filesize"];
$cloudFile->setStorageBackend($fileArray["storage_backend"]); if (!isset($fileSizeBytes) || $fileSizeBytes === false) {
$cloudFile->setResourceId($fileArray["resource_id"]); throw new FileNotFoundException("Invalid filesize for $fileId");
$cloudFile->setCcFiles($file);
$cloudFile->save();
Application_Model_Preference::updateDiskUsage($fileSizeBytes);
$now = new DateTime("now", new DateTimeZone("UTC"));
$file->setDbMtime($now);
$file->save();
} else if ($file) {
// Since we check for this value when deleting files, set it first
$file->setDbDirectory(self::MUSIC_DIRS_STOR_PK);
$file->fromArray($fileArray, BasePeer::TYPE_FIELDNAME);
//Our RESTful API takes "full_path" as a field, which we then split and translate to match
//our internal schema. Internally, file path is stored relative to a directory, with the directory
//as a foreign key to cc_music_dirs.
if (isset($fileArray["full_path"])) {
$fileSizeBytes = filesize($fileArray["full_path"]);
if (!isset($fileSizeBytes) || $fileSizeBytes === false)
{
$file->setDbImportStatus(self::IMPORT_STATUS_FAILED)->save();
throw new FileNotFoundException();
} }
$cloudFile = new CloudFile();
$cloudFile->setStorageBackend($fileArray["storage_backend"]);
$cloudFile->setResourceId($fileArray["resource_id"]);
$cloudFile->setCcFiles($file);
$cloudFile->save();
Application_Model_Preference::updateDiskUsage($fileSizeBytes); Application_Model_Preference::updateDiskUsage($fileSizeBytes);
$fullPath = $fileArray["full_path"]; $now = new DateTime("now", new DateTimeZone("UTC"));
$storDir = Application_Model_MusicDir::getStorDir()->getDirectory(); $file->setDbMtime($now);
$pos = strpos($fullPath, $storDir); $file->save();
if ($pos !== FALSE) } else if ($file) {
{
assert($pos == 0); //Path must start with the stor directory path
$filePathRelativeToStor = substr($fullPath, strlen($storDir)); // Since we check for this value when deleting files, set it first
$file->setDbFilepath($filePathRelativeToStor); $file->setDbDirectory(self::MUSIC_DIRS_STOR_PK);
$file->fromArray($fileArray, BasePeer::TYPE_FIELDNAME);
//Our RESTful API takes "full_path" as a field, which we then split and translate to match
//our internal schema. Internally, file path is stored relative to a directory, with the directory
//as a foreign key to cc_music_dirs.
if (isset($fileArray["full_path"])) {
$fileSizeBytes = filesize($fileArray["full_path"]);
if (!isset($fileSizeBytes) || $fileSizeBytes === false) {
throw new FileNotFoundException("Invalid filesize for $fileId");
}
Application_Model_Preference::updateDiskUsage($fileSizeBytes);
$fullPath = $fileArray["full_path"];
$storDir = Application_Model_MusicDir::getStorDir()->getDirectory();
$pos = strpos($fullPath, $storDir);
if ($pos !== FALSE) {
assert($pos == 0); //Path must start with the stor directory path
$filePathRelativeToStor = substr($fullPath, strlen($storDir));
$file->setDbFilepath($filePathRelativeToStor);
}
} }
$now = new DateTime("now", new DateTimeZone("UTC"));
$file->setDbMtime($now);
$file->save();
} else {
throw new FileNotFoundException();
} }
}
$now = new DateTime("now", new DateTimeZone("UTC")); catch (FileNotFoundException $e)
$file->setDbMtime($now); {
$file->setDbImportStatus(self::IMPORT_STATUS_FAILED);
$file->setDbHidden(true);
$file->save(); $file->save();
throw $e;
/* $this->removeEmptySubFolders(
isset($_SERVER['AIRTIME_BASE']) ? $_SERVER['AIRTIME_BASE']."/srv/airtime/stor/organize/" : "/srv/airtime/stor/organize/"); */
} else {
$file->setDbImportStatus(self::IMPORT_STATUS_FAILED)->save();
throw new FileNotFoundException();
} }
return CcFiles::sanitizeResponse($file); return CcFiles::sanitizeResponse($file);
@ -409,7 +411,7 @@ class CcFiles extends BaseCcFiles {
{ {
$music_dir = Application_Model_MusicDir::getDirByPK($this->getDbDirectory()); $music_dir = Application_Model_MusicDir::getDirByPK($this->getDbDirectory());
if (!$music_dir) { if (!$music_dir) {
throw new Exception("Invalid music_dir for file in database."); throw new Exception("Invalid music_dir for file " . $this->getDbId() . " in database.");
} }
$directory = $music_dir->getDirectory(); $directory = $music_dir->getDirectory();
$filepath = $this->getDbFilepath(); $filepath = $this->getDbFilepath();

View file

@ -119,6 +119,7 @@ class Rest_MediaController extends Zend_Rest_Controller
try { try {
$requestData = json_decode($this->getRequest()->getRawBody(), true); $requestData = json_decode($this->getRequest()->getRawBody(), true);
$sanitizedFile = CcFiles::updateFromArray($id, $requestData); $sanitizedFile = CcFiles::updateFromArray($id, $requestData);
$this->getResponse() $this->getResponse()
->setHttpResponseCode(201) ->setHttpResponseCode(201)
->appendBody(json_encode($sanitizedFile)); ->appendBody(json_encode($sanitizedFile));

View file

@ -1,4 +1,4 @@
<?php if($this->trial_remain != '' && $this->trial_remain != "Trial expired."){?> <?php if($this->is_trial && $this->trial_remain != '' && $this->trial_remain != "Trial expired."){?>
<div class="trial-box"> <div class="trial-box">
<p><?php echo _("Your trial expires in") ?></p> <p><?php echo _("Your trial expires in") ?></p>
<div class="trial-box-calendar"> <div class="trial-box-calendar">

View file

@ -167,7 +167,7 @@ class PypoFile(Thread):
except IOError as e: except IOError as e:
logging.debug("Failed to open config file at %s: %s" % (config_path, e.strerror)) logging.debug("Failed to open config file at %s: %s" % (config_path, e.strerror))
sys.exit() sys.exit()
except Exception: except Exception as e:
logging.debug(e.strerror) logging.debug(e.strerror)
sys.exit() sys.exit()