CC-2558 : Only delete files from disk that are in stor directory and not scheduled etc.
This commit is contained in:
parent
b7819211ac
commit
c7279f74ca
|
@ -63,12 +63,15 @@ 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") {
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
|
@ -85,9 +88,12 @@ class LibraryController extends Zend_Controller_Action
|
|||
$menu[] = array('action' => array('type' => 'gourl', 'url' => $url),
|
||||
'title' => 'Download');
|
||||
|
||||
$menu[] = array('action' => array('type' => 'fn',
|
||||
'callback' => "window['confirmDeleteAudioClip']('$paramsPop')"),
|
||||
'title' => 'Delete');
|
||||
|
||||
if ($user->isAdmin()) {
|
||||
$menu[] = array('action' => array('type' => 'fn',
|
||||
'callback' => "window['confirmDeleteAudioClip']('$paramsPop')"),
|
||||
'title' => 'Delete');
|
||||
}
|
||||
}
|
||||
else if($type === "pl") {
|
||||
|
||||
|
@ -121,32 +127,37 @@ 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 (!is_null($id)) {
|
||||
$file = StoredFile::Recall($id);
|
||||
if ($user->isAdmin()) {
|
||||
|
||||
if (PEAR::isError($file)) {
|
||||
$this->view->message = $file->getMessage();
|
||||
return;
|
||||
}
|
||||
else if(is_null($file)) {
|
||||
$this->view->message = "file doesn't exist";
|
||||
return;
|
||||
if (!is_null($id)) {
|
||||
$file = StoredFile::Recall($id);
|
||||
|
||||
if (PEAR::isError($file)) {
|
||||
$this->view->message = $file->getMessage();
|
||||
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();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
$this->view->id = $id;
|
||||
}
|
||||
|
||||
public function contentsAction()
|
||||
|
|
|
@ -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']));
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
@ -60,7 +76,7 @@ class MusicDir {
|
|||
//echo $e->getMessage();
|
||||
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)
|
||||
|
@ -123,8 +139,8 @@ class MusicDir {
|
|||
$mus_dir = new MusicDir($dir);
|
||||
|
||||
return $mus_dir;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function setStorDir($p_dir)
|
||||
{
|
||||
if(!is_dir($p_dir)){
|
||||
|
@ -162,7 +178,7 @@ class MusicDir {
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static function removeWatchedDir($p_dir){
|
||||
$p_dir = realpath($p_dir)."/";
|
||||
$dir = MusicDir::getDirByPath($p_dir);
|
||||
|
@ -180,7 +196,7 @@ class MusicDir {
|
|||
public static function splitFilePath($p_filepath)
|
||||
{
|
||||
$mus_dir = self::getWatchedDirFromFilepath($p_filepath);
|
||||
|
||||
|
||||
if(is_null($mus_dir)) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -341,18 +341,7 @@ 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;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
//used by jjmenu
|
||||
function getId() {
|
||||
function getId() {
|
||||
var tr_id = $(this.triggerElement).attr("id");
|
||||
tr_id = tr_id.split("_");
|
||||
|
||||
return tr_id[1];
|
||||
}
|
||||
|
||||
function getType() {
|
||||
function getType() {
|
||||
var tr_id = $(this.triggerElement).attr("id");
|
||||
tr_id = tr_id.split("_");
|
||||
|
||||
|
@ -25,8 +25,8 @@ function deleteItem(type, id) {
|
|||
}
|
||||
|
||||
function deleteAudioClip(json) {
|
||||
if(json.message) {
|
||||
alert(json.message);
|
||||
if(json.message) {
|
||||
alert(json.message);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -35,13 +35,13 @@ 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,
|
||||
success: deleteAudioClip
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//callbacks called by jjmenu
|
||||
|
@ -52,12 +52,12 @@ function confirmDeletePlaylist(params){
|
|||
url: url,
|
||||
success: deletePlaylist
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function deletePlaylist(json) {
|
||||
if(json.message) {
|
||||
alert(json.message);
|
||||
if(json.message) {
|
||||
alert(json.message);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -69,15 +69,15 @@ function deletePlaylist(json) {
|
|||
function addLibraryItemEvents() {
|
||||
|
||||
$('#library_display tr[id ^= "au"]')
|
||||
.draggable({
|
||||
.draggable({
|
||||
helper: 'clone',
|
||||
cursor: 'pointer'
|
||||
});
|
||||
|
||||
$('#library_display tbody tr')
|
||||
.jjmenu("click",
|
||||
[{get:"/Library/context-menu/format/json/id/#id#/type/#type#"}],
|
||||
{id: getId, type: getType},
|
||||
.jjmenu("click",
|
||||
[{get:"/Library/context-menu/format/json/id/#id#/type/#type#"}],
|
||||
{id: getId, type: getType},
|
||||
{xposition: "mouse", yposition: "mouse"});
|
||||
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ function dtRowCallback( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
|
|||
}
|
||||
|
||||
$(nRow).attr("id", type+'_'+id);
|
||||
|
||||
|
||||
// insert id on lenth field
|
||||
$('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
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
position: {
|
||||
|
||||
|
||||
adjust: {
|
||||
screen: true // Keep the tooltip on-screen at all times
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
style: {
|
||||
border: {
|
||||
width: 0,
|
||||
|
@ -146,16 +146,16 @@ $(document).ready(function() {
|
|||
"sAjaxSource": "/Library/contents/format/json",
|
||||
"fnServerData": function ( sSource, aoData, fnCallback ) {
|
||||
$.ajax( {
|
||||
"dataType": 'json',
|
||||
"type": "POST",
|
||||
"url": sSource,
|
||||
"data": aoData,
|
||||
"dataType": 'json',
|
||||
"type": "POST",
|
||||
"url": sSource,
|
||||
"data": aoData,
|
||||
"success": fnCallback
|
||||
} );
|
||||
},
|
||||
"fnRowCallback": dtRowCallback,
|
||||
"fnDrawCallback": dtDrawCallback,
|
||||
"aoColumns": [
|
||||
"aoColumns": [
|
||||
/* Id */ { "sName": "id", "bSearchable": false, "bVisible": false },
|
||||
/* Title */ { "sName": "track_title" },
|
||||
/* Creator */ { "sName": "artist_name" },
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue