CC-5709: Airtime Analyzer
* Some cleanup and refactoring for file deletion in the Media REST API * Fix the refresh timer on the Add Media page when there's pending imports.
This commit is contained in:
parent
6952902b22
commit
db2b52a1bf
|
@ -356,7 +356,6 @@ class LibraryController extends Zend_Controller_Action
|
|||
|
||||
if (isset($file)) {
|
||||
try {
|
||||
Application_Model_Preference::updateDiskUsage(-1 * abs(filesize($file->getFilePath())));
|
||||
$res = $file->delete();
|
||||
} catch (FileNoPermissionException $e) {
|
||||
$message = $noPermissionMsg;
|
||||
|
|
|
@ -301,7 +301,9 @@ SQL;
|
|||
public static function getDirByPK($pk)
|
||||
{
|
||||
$dir = CcMusicDirsQuery::create()->findPK($pk);
|
||||
|
||||
if (!$dir) {
|
||||
return null;
|
||||
}
|
||||
$mus_dir = new Application_Model_MusicDir($dir);
|
||||
|
||||
return $mus_dir;
|
||||
|
|
|
@ -346,6 +346,21 @@ SQL;
|
|||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the file (on disk) corresponding to this class exists or not.
|
||||
* @return boolean true if the file exists, false otherwise.
|
||||
*/
|
||||
public function existsOnDisk()
|
||||
{
|
||||
$exists = false;
|
||||
try {
|
||||
$exists = file_exists($this->getFilePath());
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
return $exists;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete stored virtual file
|
||||
|
@ -355,8 +370,11 @@ SQL;
|
|||
*/
|
||||
public function delete()
|
||||
{
|
||||
|
||||
$filepath = $this->getFilePath();
|
||||
|
||||
//Update the user's disk usage
|
||||
Application_Model_Preference::updateDiskUsage(-1 * abs(filesize($filepath)));
|
||||
|
||||
// Check if the file is scheduled to be played in the future
|
||||
if (Application_Model_Schedule::IsFileScheduledInTheFuture($this->getId())) {
|
||||
throw new DeleteScheduledFileException();
|
||||
|
@ -370,8 +388,10 @@ SQL;
|
|||
}
|
||||
|
||||
$music_dir = Application_Model_MusicDir::getDirByPK($this->_file->getDbDirectory());
|
||||
assert($music_dir);
|
||||
$type = $music_dir->getType();
|
||||
|
||||
|
||||
|
||||
if (file_exists($filepath) && $type == "stor") {
|
||||
$data = array("filepath" => $filepath, "delete" => 1);
|
||||
try {
|
||||
|
@ -473,8 +493,13 @@ SQL;
|
|||
*/
|
||||
public function getFilePath()
|
||||
{
|
||||
assert($this->_file);
|
||||
|
||||
$music_dir = Application_Model_MusicDir::getDirByPK($this->
|
||||
_file->getDbDirectory());
|
||||
if (!$music_dir) {
|
||||
throw new Exception("Invalid music_dir for file in database.");
|
||||
}
|
||||
$directory = $music_dir->getDirectory();
|
||||
$filepath = $this->_file->getDbFilepath();
|
||||
|
||||
|
|
|
@ -198,8 +198,9 @@ class Rest_MediaController extends Zend_Rest_Controller
|
|||
if ($file) {
|
||||
$con = Propel::getConnection();
|
||||
$storedFile = new Application_Model_StoredFile($file, $con);
|
||||
Application_Model_Preference::updateDiskUsage(-1 * abs(filesize($storedFile->getFilePath())));
|
||||
$storedFile->delete(); //TODO: This checks your session permissions... Make it work without a session?
|
||||
if ($storedFile->existsOnDisk()) {
|
||||
$storedFile->delete(); //TODO: This checks your session permissions... Make it work without a session?
|
||||
}
|
||||
$file->delete();
|
||||
$this->getResponse()
|
||||
->setHttpResponseCode(204);
|
||||
|
|
|
@ -149,7 +149,7 @@ $(document).ready(function() {
|
|||
if (self.isRecentUploadsRefreshTimerActive()) { //Prevent multiple timers from running
|
||||
return;
|
||||
}
|
||||
self.recentUploadsRefreshTimer = setTimeout("self.recentUploadsTable.fnDraw()", 3000);
|
||||
self.recentUploadsRefreshTimer = setInterval("self.recentUploadsTable.fnDraw()", 3000);
|
||||
};
|
||||
|
||||
self.isRecentUploadsRefreshTimerActive = function()
|
||||
|
@ -159,7 +159,7 @@ $(document).ready(function() {
|
|||
|
||||
self.stopRefreshingRecentUploads = function()
|
||||
{
|
||||
clearTimeout(self.recentUploadsRefreshTimer);
|
||||
clearInterval(self.recentUploadsRefreshTimer);
|
||||
self.recentUploadsRefreshTimer = null;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue