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:
Albert Santoni 2014-03-24 17:14:04 -04:00
parent 6952902b22
commit db2b52a1bf
5 changed files with 35 additions and 8 deletions

View File

@ -356,7 +356,6 @@ class LibraryController extends Zend_Controller_Action
if (isset($file)) { if (isset($file)) {
try { try {
Application_Model_Preference::updateDiskUsage(-1 * abs(filesize($file->getFilePath())));
$res = $file->delete(); $res = $file->delete();
} catch (FileNoPermissionException $e) { } catch (FileNoPermissionException $e) {
$message = $noPermissionMsg; $message = $noPermissionMsg;

View File

@ -301,7 +301,9 @@ SQL;
public static function getDirByPK($pk) public static function getDirByPK($pk)
{ {
$dir = CcMusicDirsQuery::create()->findPK($pk); $dir = CcMusicDirsQuery::create()->findPK($pk);
if (!$dir) {
return null;
}
$mus_dir = new Application_Model_MusicDir($dir); $mus_dir = new Application_Model_MusicDir($dir);
return $mus_dir; return $mus_dir;

View File

@ -346,6 +346,21 @@ SQL;
return array(); 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 * Delete stored virtual file
@ -355,8 +370,11 @@ SQL;
*/ */
public function delete() public function delete()
{ {
$filepath = $this->getFilePath(); $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 // Check if the file is scheduled to be played in the future
if (Application_Model_Schedule::IsFileScheduledInTheFuture($this->getId())) { if (Application_Model_Schedule::IsFileScheduledInTheFuture($this->getId())) {
throw new DeleteScheduledFileException(); throw new DeleteScheduledFileException();
@ -370,8 +388,10 @@ SQL;
} }
$music_dir = Application_Model_MusicDir::getDirByPK($this->_file->getDbDirectory()); $music_dir = Application_Model_MusicDir::getDirByPK($this->_file->getDbDirectory());
assert($music_dir);
$type = $music_dir->getType(); $type = $music_dir->getType();
if (file_exists($filepath) && $type == "stor") { if (file_exists($filepath) && $type == "stor") {
$data = array("filepath" => $filepath, "delete" => 1); $data = array("filepath" => $filepath, "delete" => 1);
try { try {
@ -473,8 +493,13 @@ SQL;
*/ */
public function getFilePath() public function getFilePath()
{ {
assert($this->_file);
$music_dir = Application_Model_MusicDir::getDirByPK($this-> $music_dir = Application_Model_MusicDir::getDirByPK($this->
_file->getDbDirectory()); _file->getDbDirectory());
if (!$music_dir) {
throw new Exception("Invalid music_dir for file in database.");
}
$directory = $music_dir->getDirectory(); $directory = $music_dir->getDirectory();
$filepath = $this->_file->getDbFilepath(); $filepath = $this->_file->getDbFilepath();

View File

@ -198,8 +198,9 @@ class Rest_MediaController extends Zend_Rest_Controller
if ($file) { if ($file) {
$con = Propel::getConnection(); $con = Propel::getConnection();
$storedFile = new Application_Model_StoredFile($file, $con); $storedFile = new Application_Model_StoredFile($file, $con);
Application_Model_Preference::updateDiskUsage(-1 * abs(filesize($storedFile->getFilePath()))); if ($storedFile->existsOnDisk()) {
$storedFile->delete(); //TODO: This checks your session permissions... Make it work without a session? $storedFile->delete(); //TODO: This checks your session permissions... Make it work without a session?
}
$file->delete(); $file->delete();
$this->getResponse() $this->getResponse()
->setHttpResponseCode(204); ->setHttpResponseCode(204);

View File

@ -149,7 +149,7 @@ $(document).ready(function() {
if (self.isRecentUploadsRefreshTimerActive()) { //Prevent multiple timers from running if (self.isRecentUploadsRefreshTimerActive()) { //Prevent multiple timers from running
return; return;
} }
self.recentUploadsRefreshTimer = setTimeout("self.recentUploadsTable.fnDraw()", 3000); self.recentUploadsRefreshTimer = setInterval("self.recentUploadsTable.fnDraw()", 3000);
}; };
self.isRecentUploadsRefreshTimerActive = function() self.isRecentUploadsRefreshTimerActive = function()
@ -159,7 +159,7 @@ $(document).ready(function() {
self.stopRefreshingRecentUploads = function() self.stopRefreshingRecentUploads = function()
{ {
clearTimeout(self.recentUploadsRefreshTimer); clearInterval(self.recentUploadsRefreshTimer);
self.recentUploadsRefreshTimer = null; self.recentUploadsRefreshTimer = null;
}; };