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,12 +63,15 @@ class LibraryController extends Zend_Controller_Action
$paramsPop = str_replace('#id#', $id, $params); $paramsPop = str_replace('#id#', $id, $params);
$paramsPop = str_replace('#type#', $type, $paramsPop); $paramsPop = str_replace('#type#', $type, $paramsPop);
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$user = new User($userInfo->id);
$pl_sess = $this->pl_sess; $pl_sess = $this->pl_sess;
if($type === "au") { if($type === "au") {
if(isset($pl_sess->id)) { if(isset($pl_sess->id)) {
$menu[] = array('action' => array('type' => 'ajax', 'url' => '/Playlist/add-item'.$params, 'callback' => 'window["setSPLContent"]'), $menu[] = array('action' => array('type' => 'ajax', 'url' => '/Playlist/add-item'.$params, 'callback' => 'window["setSPLContent"]'),
'title' => 'Add to Playlist'); 'title' => 'Add to Playlist');
} }
@ -85,9 +88,12 @@ class LibraryController extends Zend_Controller_Action
$menu[] = array('action' => array('type' => 'gourl', 'url' => $url), $menu[] = array('action' => array('type' => 'gourl', 'url' => $url),
'title' => 'Download'); 'title' => 'Download');
$menu[] = array('action' => array('type' => 'fn',
'callback' => "window['confirmDeleteAudioClip']('$paramsPop')"), if ($user->isAdmin()) {
'title' => 'Delete'); $menu[] = array('action' => array('type' => 'fn',
'callback' => "window['confirmDeleteAudioClip']('$paramsPop')"),
'title' => 'Delete');
}
} }
else if($type === "pl") { else if($type === "pl") {
@ -121,32 +127,37 @@ class LibraryController extends Zend_Controller_Action
public function deleteAction() public function deleteAction()
{ {
$id = $this->_getParam('id'); $id = $this->_getParam('id');
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$user = new User($userInfo->id);
if (!is_null($id)) { if ($user->isAdmin()) {
$file = StoredFile::Recall($id);
if (PEAR::isError($file)) { if (!is_null($id)) {
$this->view->message = $file->getMessage(); $file = StoredFile::Recall($id);
return;
} if (PEAR::isError($file)) {
else if(is_null($file)) { $this->view->message = $file->getMessage();
$this->view->message = "file doesn't exist"; return;
return; }
else if(is_null($file)) {
$this->view->message = "file doesn't exist";
return;
}
$res = $file->delete();
if (PEAR::isError($res)) {
$this->view->message = $res->getMessage();
return;
}
else {
$data = array("filepath" => $file->getFilePath(), "delete" => $res);
RabbitMq::SendMessageToMediaMonitor("file_delete", $data);
}
} }
$res = $file->delete(); $this->view->id = $id;
if (PEAR::isError($res)) {
$this->view->message = $res->getMessage();
return;
}
else {
$data = array("filepath" => $file->getFilePath(), "delete" => $res);
RabbitMq::SendMessageToMediaMonitor("file_delete", $data);
}
} }
$this->view->id = $id;
} }
public function contentsAction() public function contentsAction()

View File

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

View File

@ -40,7 +40,23 @@ class MusicDir {
public function remove() 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(); $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) public static function addDir($p_path, $p_type)
@ -60,7 +76,7 @@ class MusicDir {
//echo $e->getMessage(); //echo $e->getMessage();
return array("code"=>1, "error"=>"'$p_path' is already set as the current storage dir or in the watched folders list"); return array("code"=>1, "error"=>"'$p_path' is already set as the current storage dir or in the watched folders list");
} }
} }
public static function addWatchedDir($p_path) public static function addWatchedDir($p_path)
@ -123,8 +139,8 @@ class MusicDir {
$mus_dir = new MusicDir($dir); $mus_dir = new MusicDir($dir);
return $mus_dir; return $mus_dir;
} }
public static function setStorDir($p_dir) public static function setStorDir($p_dir)
{ {
if(!is_dir($p_dir)){ if(!is_dir($p_dir)){
@ -162,7 +178,7 @@ class MusicDir {
return null; return null;
} }
public static function removeWatchedDir($p_dir){ public static function removeWatchedDir($p_dir){
$p_dir = realpath($p_dir)."/"; $p_dir = realpath($p_dir)."/";
$dir = MusicDir::getDirByPath($p_dir); $dir = MusicDir::getDirByPath($p_dir);
@ -180,7 +196,7 @@ class MusicDir {
public static function splitFilePath($p_filepath) public static function splitFilePath($p_filepath)
{ {
$mus_dir = self::getWatchedDirFromFilepath($p_filepath); $mus_dir = self::getWatchedDirFromFilepath($p_filepath);
if(is_null($mus_dir)) { if(is_null($mus_dir)) {
return null; return null;
} }

View File

@ -341,18 +341,7 @@ class StoredFile {
return PEAR::raiseError('Cannot delete a file that is scheduled in the future.'); return PEAR::raiseError('Cannot delete a file that is scheduled in the future.');
} }
$storageDir = MusicDir::getStorDir()->getDirectory(); return true;
$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;
}
} }
/** /**

View File

@ -1,12 +1,12 @@
//used by jjmenu //used by jjmenu
function getId() { function getId() {
var tr_id = $(this.triggerElement).attr("id"); var tr_id = $(this.triggerElement).attr("id");
tr_id = tr_id.split("_"); tr_id = tr_id.split("_");
return tr_id[1]; return tr_id[1];
} }
function getType() { function getType() {
var tr_id = $(this.triggerElement).attr("id"); var tr_id = $(this.triggerElement).attr("id");
tr_id = tr_id.split("_"); tr_id = tr_id.split("_");
@ -25,8 +25,8 @@ function deleteItem(type, id) {
} }
function deleteAudioClip(json) { function deleteAudioClip(json) {
if(json.message) { if(json.message) {
alert(json.message); alert(json.message);
return; return;
} }
@ -35,13 +35,13 @@ function deleteAudioClip(json) {
//callbacks called by jjmenu //callbacks called by jjmenu
function confirmDeleteAudioClip(params){ 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; var url = '/Library/delete' + params;
$.ajax({ $.ajax({
url: url, url: url,
success: deleteAudioClip success: deleteAudioClip
}); });
} }
} }
//callbacks called by jjmenu //callbacks called by jjmenu
@ -52,12 +52,12 @@ function confirmDeletePlaylist(params){
url: url, url: url,
success: deletePlaylist success: deletePlaylist
}); });
} }
} }
function deletePlaylist(json) { function deletePlaylist(json) {
if(json.message) { if(json.message) {
alert(json.message); alert(json.message);
return; return;
} }
@ -69,15 +69,15 @@ function deletePlaylist(json) {
function addLibraryItemEvents() { function addLibraryItemEvents() {
$('#library_display tr[id ^= "au"]') $('#library_display tr[id ^= "au"]')
.draggable({ .draggable({
helper: 'clone', helper: 'clone',
cursor: 'pointer' cursor: 'pointer'
}); });
$('#library_display tbody tr') $('#library_display tbody tr')
.jjmenu("click", .jjmenu("click",
[{get:"/Library/context-menu/format/json/id/#id#/type/#type#"}], [{get:"/Library/context-menu/format/json/id/#id#/type/#type#"}],
{id: getId, type: getType}, {id: getId, type: getType},
{xposition: "mouse", yposition: "mouse"}); {xposition: "mouse", yposition: "mouse"});
} }
@ -96,7 +96,7 @@ function dtRowCallback( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
} }
$(nRow).attr("id", type+'_'+id); $(nRow).attr("id", type+'_'+id);
// insert id on lenth field // insert id on lenth field
$('td:eq(4)', nRow).attr("id", "length"); $('td:eq(4)', nRow).attr("id", "length");
@ -111,14 +111,14 @@ function dtRowCallback( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
button: 'Close' // Show a close link in the title button: 'Close' // Show a close link in the title
} }
}, },
position: { position: {
adjust: { adjust: {
screen: true // Keep the tooltip on-screen at all times screen: true // Keep the tooltip on-screen at all times
} }
}, },
style: { style: {
border: { border: {
width: 0, width: 0,
@ -146,16 +146,16 @@ $(document).ready(function() {
"sAjaxSource": "/Library/contents/format/json", "sAjaxSource": "/Library/contents/format/json",
"fnServerData": function ( sSource, aoData, fnCallback ) { "fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( { $.ajax( {
"dataType": 'json', "dataType": 'json',
"type": "POST", "type": "POST",
"url": sSource, "url": sSource,
"data": aoData, "data": aoData,
"success": fnCallback "success": fnCallback
} ); } );
}, },
"fnRowCallback": dtRowCallback, "fnRowCallback": dtRowCallback,
"fnDrawCallback": dtDrawCallback, "fnDrawCallback": dtDrawCallback,
"aoColumns": [ "aoColumns": [
/* Id */ { "sName": "id", "bSearchable": false, "bVisible": false }, /* Id */ { "sName": "id", "bSearchable": false, "bVisible": false },
/* Title */ { "sName": "track_title" }, /* Title */ { "sName": "track_title" },
/* Creator */ { "sName": "artist_name" }, /* Creator */ { "sName": "artist_name" },

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. #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. #Easy Tag creates this when changing metadata of ogg files.
self.temp_files[pathname] = None 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): elif self.mmc.is_audio_file(pathname):
if self.mmc.is_parent_directory(pathname, self.config.organize_directory): if self.mmc.is_parent_directory(pathname, self.config.organize_directory):
#file was created in /srv/airtime/stor/organize. Need to process and move #file was created in /srv/airtime/stor/organize. Need to process and move