diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index e277f37d1..a017380a0 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -370,9 +370,7 @@ SQL; * */ public function delete() - { - $filepath = $this->getFilePath(); - + { // Check if the file is scheduled to be played in the future if (Application_Model_Schedule::IsFileScheduledInTheFuture($this->getId())) { throw new DeleteScheduledFileException(); @@ -390,20 +388,21 @@ SQL; assert($music_dir); $type = $music_dir->getType(); - if (file_exists($filepath) && $type == "stor") { - try { - //Update the user's disk usage - Application_Model_Preference::updateDiskUsage(-1 * abs(filesize($filepath))); - - unlink($filepath); - } catch (Exception $e) { - Logging::error($e->getMessage()); - return; - } - } - Logging::info($_SERVER["HTTP_HOST"].": User ".$user->getLogin()." is deleting file: ".$this->_file->getDbTrackTitle()." - file id: ".$this->_file->getDbId()); + try { + if ($this->existsOnDisk() && $type == "stor") { + $filepath = $this->getFilePath(); + //Update the user's disk usage + Application_Model_Preference::updateDiskUsage(-1 * abs(filesize($filepath))); + unlink($filepath); + } + } 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. + } + // need to explicitly update any playlist's and block's length // that contains the file getting deleted $fileId = $this->_file->getDbId(); @@ -421,8 +420,7 @@ SQL; $bl->save(); } - // We were setting file_exists to false and leaving it at that - // but we should actually delete the file + //We actually do want to delete the file from the database here $this->_file->delete(); }