CC-5896: Store cloud files in separate table, inherited from cc_files
Refactored storedfile->delete() Added a deletePhysicalFile function to CcFile and CloudFile Cleaned up schedule events that get passed to Pypo
This commit is contained in:
parent
b7d1852fc0
commit
8c2754972e
|
@ -724,7 +724,7 @@ SQL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function createFileScheduleEvent(&$data, $item, $media_id, $uri, $filesize, $object_name, $isInCloud)
|
private static function createFileScheduleEvent(&$data, $item, $media_id, $uri, $filesize, $object_name=null)
|
||||||
{
|
{
|
||||||
$start = self::AirtimeTimeToPypoTime($item["start"]);
|
$start = self::AirtimeTimeToPypoTime($item["start"]);
|
||||||
$end = self::AirtimeTimeToPypoTime($item["end"]);
|
$end = self::AirtimeTimeToPypoTime($item["end"]);
|
||||||
|
@ -759,10 +759,11 @@ SQL;
|
||||||
'show_name' => $item["show_name"],
|
'show_name' => $item["show_name"],
|
||||||
'replay_gain' => $replay_gain,
|
'replay_gain' => $replay_gain,
|
||||||
'independent_event' => $independent_event,
|
'independent_event' => $independent_event,
|
||||||
'filesize' => $filesize,
|
'filesize' => $filesize
|
||||||
'object_name' => $object_name,
|
|
||||||
'is_in_cloud' => $isInCloud
|
|
||||||
);
|
);
|
||||||
|
if (!is_null($object_name)) {
|
||||||
|
$schedule_item["object_name"] = $object_name;
|
||||||
|
}
|
||||||
|
|
||||||
if ($schedule_item['cue_in'] > $schedule_item['cue_out']) {
|
if ($schedule_item['cue_in'] > $schedule_item['cue_out']) {
|
||||||
$schedule_item['cue_in'] = $schedule_item['cue_out'];
|
$schedule_item['cue_in'] = $schedule_item['cue_out'];
|
||||||
|
@ -895,10 +896,12 @@ SQL;
|
||||||
$media_id = $item['file_id'];
|
$media_id = $item['file_id'];
|
||||||
$storedFile = Application_Model_StoredFile::RecallById($media_id);
|
$storedFile = Application_Model_StoredFile::RecallById($media_id);
|
||||||
$uri = $storedFile->getFilePath();
|
$uri = $storedFile->getFilePath();
|
||||||
$object_name = $storedFile->getResourceId();
|
$object_name = null;
|
||||||
|
if ($storedFile->getPropelOrm() instanceof CloudFile) {
|
||||||
|
$object_name = $storedFile->getResourceId();
|
||||||
|
}
|
||||||
$filesize = $storedFile->getFileSize();
|
$filesize = $storedFile->getFileSize();
|
||||||
$isInCloud = $storedFile->isInCloud();
|
self::createFileScheduleEvent($data, $item, $media_id, $uri, $filesize, $object_name);
|
||||||
self::createFileScheduleEvent($data, $item, $media_id, $uri, $filesize, $object_name, $isInCloud);
|
|
||||||
}
|
}
|
||||||
elseif (!is_null($item['stream_id'])) {
|
elseif (!is_null($item['stream_id'])) {
|
||||||
//row is type "webstream"
|
//row is type "webstream"
|
||||||
|
|
|
@ -387,44 +387,24 @@ SQL;
|
||||||
$music_dir = Application_Model_MusicDir::getDirByPK($this->_file->getDbDirectory());
|
$music_dir = Application_Model_MusicDir::getDirByPK($this->_file->getDbDirectory());
|
||||||
if (!is_null($music_dir) && $music_dir->getType() == "stor" && file_exists($filepath)) {
|
if (!is_null($music_dir) && $music_dir->getType() == "stor" && file_exists($filepath)) {
|
||||||
try {
|
try {
|
||||||
$this->doFileDeletionCleanup($this->getFileSize());
|
$filesize = $this->getFileSize();
|
||||||
unlink($filepath);
|
|
||||||
|
//Update the user's disk usage
|
||||||
|
Application_Model_Preference::updateDiskUsage(-1 * $filesize);
|
||||||
|
|
||||||
|
//Explicitly update any playlist's and block's length that contain
|
||||||
|
//the file getting deleted
|
||||||
|
self::updateBlockAndPlaylistLength($this->_file->getDbId());
|
||||||
|
|
||||||
|
$this->_file->deletePhysicalFile();
|
||||||
|
|
||||||
|
//delete the file record from cc_files (and cloud_file, if applicable)
|
||||||
|
$this->_file->delete();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Logging::error($e->getMessage());
|
Logging::error($e->getMessage());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} /*elseif ($isInCloud) {
|
|
||||||
//Dispatch a message to airtime_analyzer through RabbitMQ,
|
|
||||||
//notifying it that we need to delete a file from the cloud
|
|
||||||
$CC_CONFIG = Config::getConfig();
|
|
||||||
$apiKey = $CC_CONFIG["apiKey"][0];
|
|
||||||
|
|
||||||
//If the file was successfully deleted from the cloud the analyzer
|
|
||||||
//will make a request to the Media API to do the deletion cleanup.
|
|
||||||
$callbackUrl = 'http://'.$_SERVER['HTTP_HOST'].'/rest/media/'.$file_id.'/delete-success';
|
|
||||||
|
|
||||||
Application_Model_RabbitMq::SendDeleteMessageToAnalyzer(
|
|
||||||
$callbackUrl, $this->_file->getDbResourceId(), $apiKey, 'delete');
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This function handles all the actions required when a file is deleted
|
|
||||||
*/
|
|
||||||
public function doFileDeletionCleanup($filesize)
|
|
||||||
{
|
|
||||||
if ($filesize <= 0) {
|
|
||||||
throw new Exception ("Could not delete file with ".$filesize." filesize");
|
|
||||||
}
|
}
|
||||||
//Update the user's disk usage
|
|
||||||
Application_Model_Preference::updateDiskUsage(-1 * $filesize);
|
|
||||||
|
|
||||||
//Explicitly update any playlist's and block's length that contains
|
|
||||||
//the file getting deleted
|
|
||||||
self::updateBlockAndPlaylistLength($this->_file->getDbId());
|
|
||||||
|
|
||||||
//delete the file record from cc_files
|
|
||||||
$this->_file->delete();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -574,12 +554,16 @@ SQL;
|
||||||
|
|
||||||
public function getResourceId()
|
public function getResourceId()
|
||||||
{
|
{
|
||||||
return $this->_file->getDbResourceId();
|
return $this->_file->getResourceId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFileSize()
|
public function getFileSize()
|
||||||
{
|
{
|
||||||
return $this->_file->getFileSize();
|
$filesize = $this->_file->getFileSize();
|
||||||
|
if ($filesize <= 0) {
|
||||||
|
throw new Exception ("Could not determine filesize for file id: ".$this->_file->getDbId().". Filesize: ".$filesize);
|
||||||
|
}
|
||||||
|
return $filesize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function Insert($md, $con)
|
public static function Insert($md, $con)
|
||||||
|
|
|
@ -99,4 +99,9 @@ class CcFiles extends BaseCcFiles {
|
||||||
return is_file($this->getAbsoluteFilePath());
|
return is_file($this->getAbsoluteFilePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function deletePhysicalFile()
|
||||||
|
{
|
||||||
|
unlink($this->getAbsoluteFilePath());
|
||||||
|
}
|
||||||
|
|
||||||
} // CcFiles
|
} // CcFiles
|
||||||
|
|
|
@ -50,4 +50,21 @@ class CloudFile extends BaseCloudFile
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function deletePhysicalFile()
|
||||||
|
{
|
||||||
|
//TODO: execute a python script that deletes the file from the cloud
|
||||||
|
|
||||||
|
//Dispatch a message to airtime_analyzer through RabbitMQ,
|
||||||
|
//notifying it that we need to delete a file from the cloud
|
||||||
|
/*$CC_CONFIG = Config::getConfig();
|
||||||
|
$apiKey = $CC_CONFIG["apiKey"][0];
|
||||||
|
|
||||||
|
//If the file was successfully deleted from the cloud the analyzer
|
||||||
|
//will make a request to the Media API to do the deletion cleanup.
|
||||||
|
$callbackUrl = 'http://'.$_SERVER['HTTP_HOST'].'/rest/media/'.$file_id.'/delete-success';
|
||||||
|
|
||||||
|
Application_Model_RabbitMq::SendDeleteMessageToAnalyzer(
|
||||||
|
$callbackUrl, $this->_file->getDbResourceId(), $apiKey, 'delete');*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,21 +37,11 @@ class PypoFile(Thread):
|
||||||
"""
|
"""
|
||||||
src = media_item['uri']
|
src = media_item['uri']
|
||||||
dst = media_item['dst']
|
dst = media_item['dst']
|
||||||
is_in_cloud = media_item['is_in_cloud']
|
src_size = media_item['filesize']
|
||||||
|
|
||||||
try:
|
|
||||||
if is_in_cloud:
|
|
||||||
src_size = media_item['filesize']
|
|
||||||
else:
|
|
||||||
src_size = os.path.getsize(src)
|
|
||||||
except Exception, e:
|
|
||||||
self.logger.error("Could not get size of source file: %s", src)
|
|
||||||
return
|
|
||||||
|
|
||||||
dst_exists = True
|
dst_exists = True
|
||||||
try:
|
try:
|
||||||
dst_size = os.path.getsize(dst)
|
dst_size = os.path.getsize(dst)
|
||||||
self.logger.debug(dst_size)
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
dst_exists = False
|
dst_exists = False
|
||||||
|
|
||||||
|
@ -73,7 +63,7 @@ class PypoFile(Thread):
|
||||||
"""
|
"""
|
||||||
copy will overwrite dst if it already exists
|
copy will overwrite dst if it already exists
|
||||||
"""
|
"""
|
||||||
if is_in_cloud:
|
if 'object_name' in media_item:
|
||||||
csd = CloudStorageDownloader()
|
csd = CloudStorageDownloader()
|
||||||
csd.download_obj(dst, media_item['object_name'])
|
csd.download_obj(dst, media_item['object_name'])
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue