Actually delete files from the database via the media REST API

This commit is contained in:
Albert Santoni 2014-11-18 18:15:45 -05:00
parent 11a31375df
commit dd3b54f8ed
1 changed files with 17 additions and 9 deletions

View File

@ -370,9 +370,7 @@ SQL;
* *
*/ */
public function delete() public function delete()
{ {
$filepath = $this->getFilePath();
// 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();
@ -390,17 +388,21 @@ SQL;
$type = $music_dir->getType(); $type = $music_dir->getType();
if (file_exists($filepath) && $type == "stor") { Logging::info($_SERVER["HTTP_HOST"].": User ".$user->getLogin()." is deleting file: ".$this->_file->getDbTrackTitle()." - file id: ".$this->_file->getDbId());
try {
try {
if ($this->existsOnDisk() && $type == "stor") {
$filepath = $this->getFilePath();
//Update the user's disk usage //Update the user's disk usage
Application_Model_Preference::updateDiskUsage(-1 * abs(filesize($filepath))); Application_Model_Preference::updateDiskUsage(-1 * abs(filesize($filepath)));
unlink($filepath); unlink($filepath);
} catch (Exception $e) {
Logging::error($e->getMessage());
return;
} }
} catch (Exception $e) {
Logging::warning($e->getMessage());
//If the file didn't exist on disk, that's fine, we still want to
//remove it from the database, so we continue here.
} }
<<<<<<< Updated upstream
Logging::info("User ".$user->getLogin()." is deleting file: ".$this->_file->getDbTrackTitle()." - file id: ".$this->_file->getDbId()); Logging::info("User ".$user->getLogin()." is deleting file: ".$this->_file->getDbTrackTitle()." - file id: ".$this->_file->getDbId());
// set hidden flag to true // set hidden flag to true
@ -408,6 +410,9 @@ SQL;
$this->_file->setDbFileExists(false); $this->_file->setDbFileExists(false);
$this->_file->save(); $this->_file->save();
=======
>>>>>>> Stashed changes
// need to explicitly update any playlist's and block's length // need to explicitly update any playlist's and block's length
// that contains the file getting deleted // that contains the file getting deleted
$fileId = $this->_file->getDbId(); $fileId = $this->_file->getDbId();
@ -424,6 +429,9 @@ SQL;
$bl->setDbLength($bl->computeDbLength(Propel::getConnection(CcBlockPeer::DATABASE_NAME))); $bl->setDbLength($bl->computeDbLength(Propel::getConnection(CcBlockPeer::DATABASE_NAME)));
$bl->save(); $bl->save();
} }
//We actually do want to delete the file from the database here
$this->_file->delete();
} }
/** /**