CC-2558 : Only delete files from disk that are in stor directory and not scheduled etc.

This commit is contained in:
Naomi Aro 2011-07-18 19:48:20 +02:00
parent b7819211ac
commit c7279f74ca
6 changed files with 87 additions and 66 deletions

View File

@ -63,6 +63,9 @@ class LibraryController extends Zend_Controller_Action
$paramsPop = str_replace('#id#', $id, $params);
$paramsPop = str_replace('#type#', $type, $paramsPop);
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$user = new User($userInfo->id);
$pl_sess = $this->pl_sess;
if($type === "au") {
@ -85,10 +88,13 @@ class LibraryController extends Zend_Controller_Action
$menu[] = array('action' => array('type' => 'gourl', 'url' => $url),
'title' => 'Download');
if ($user->isAdmin()) {
$menu[] = array('action' => array('type' => 'fn',
'callback' => "window['confirmDeleteAudioClip']('$paramsPop')"),
'title' => 'Delete');
}
}
else if($type === "pl") {
if(!isset($pl_sess->id) || $pl_sess->id !== $id) {
@ -121,6 +127,10 @@ class LibraryController extends Zend_Controller_Action
public function deleteAction()
{
$id = $this->_getParam('id');
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$user = new User($userInfo->id);
if ($user->isAdmin()) {
if (!is_null($id)) {
$file = StoredFile::Recall($id);
@ -148,6 +158,7 @@ class LibraryController extends Zend_Controller_Action
$this->view->id = $id;
}
}
public function contentsAction()
{

View File

@ -123,9 +123,10 @@ class PreferenceController extends Zend_Controller_Action
$chosen = $this->getRequest()->getParam("dir");
$element = $this->getRequest()->getParam("element");
$watched_dirs_form = new Application_Form_WatchedDirPreferences();
$watched_dirs_form->populate(array('storageFolder' => $chosen));
$res = MusicDir::setStorDir($chosen);
if($res['code'] != 0){
$watched_dirs_form->populate(array('storageFolder' => $chosen));
$watched_dirs_form->getElement($element)->setErrors(array($res['error']));
}
@ -137,9 +138,10 @@ class PreferenceController extends Zend_Controller_Action
$chosen = $this->getRequest()->getParam("dir");
$element = $this->getRequest()->getParam("element");
$watched_dirs_form = new Application_Form_WatchedDirPreferences();
$watched_dirs_form->populate(array('watchedFolder' => $chosen));
$res = MusicDir::addWatchedDir($chosen);
if($res['code'] != 0){
$watched_dirs_form->populate(array('watchedFolder' => $chosen));
$watched_dirs_form->getElement($element)->setErrors(array($res['error']));
}

View File

@ -40,7 +40,23 @@ class MusicDir {
public function remove()
{
global $CC_DBC;
$music_dir_id = $this->getId();
$sql = "SELECT DISTINCT s.instance_id from cc_music_dirs as md LEFT JOIN cc_files as f on f.directory = md.id
RIGHT JOIN cc_schedule as s on s.file_id = f.id WHERE md.id = $music_dir_id";
$show_instances = $CC_DBC->GetAll($sql);
$this->_dir->delete();
foreach ($show_instances as $show_instance_row) {
$temp_show = new ShowInstance($show_instance_row["instance_id"]);
$temp_show->updateScheduledTime();
}
RabbitMq::PushSchedule();
}
public static function addDir($p_path, $p_type)

View File

@ -341,19 +341,8 @@ class StoredFile {
return PEAR::raiseError('Cannot delete a file that is scheduled in the future.');
}
$storageDir = MusicDir::getStorDir()->getDirectory();
$dirCompare = substr($this->getFilePath(), 0, strlen($storageDir));
//return PEAR::raiseError("({$storageDir} , {$dirCompare})");
// Only delete the file from filesystem if it has been copied to the storage directory
if ($dirCompare === $storageDir) {
return true;
}
else {
return false;
}
}
/**
* Returns true if media file exists

View File

@ -35,7 +35,7 @@ function deleteAudioClip(json) {
//callbacks called by jjmenu
function confirmDeleteAudioClip(params){
if(confirm('Are you sure you want to delete?')){
if(confirm('The file will be deleted from disk, are you sure you want to delete?')){
var url = '/Library/delete' + params;
$.ajax({
url: url,

View File

@ -57,6 +57,9 @@ class AirtimeProcessEvent(ProcessEvent):
#file created is a tmp file which will be modified and then moved back to the original filename.
#Easy Tag creates this when changing metadata of ogg files.
self.temp_files[pathname] = None
#file is being overwritten/replaced in GUI.
elif "goutputstream" in pathname:
self.temp_files[pathname] = None
elif self.mmc.is_audio_file(pathname):
if self.mmc.is_parent_directory(pathname, self.config.organize_directory):
#file was created in /srv/airtime/stor/organize. Need to process and move