CC-1434 && CC-1373
Won't delete a file that's scheduled or contained in a playlist.
This commit is contained in:
parent
51436f76b8
commit
4d3b90621e
2 changed files with 87 additions and 11 deletions
|
@ -159,23 +159,55 @@ class BasicStor {
|
||||||
$res = BasicStor::RemoveObj($id, $forced);
|
$res = BasicStor::RemoveObj($id, $forced);
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$storedFile = StoredFile::Recall($id);
|
||||||
|
|
||||||
|
if (is_null($storedFile) || PEAR::isError($storedFile)) {
|
||||||
|
return $storedFile;
|
||||||
|
}
|
||||||
|
if ($storedFile->isAccessed()) {
|
||||||
|
return PEAR::raiseError(
|
||||||
|
'Cannot delete an object that is currently accessed.'
|
||||||
|
);
|
||||||
|
}
|
||||||
// move to trash:
|
// move to trash:
|
||||||
switch (BasicStor::GetObjType($id)) {
|
switch (BasicStor::GetObjType($id)) {
|
||||||
|
|
||||||
case "audioclip":
|
case "audioclip":
|
||||||
|
$playLists = $storedFile->getPlaylists();
|
||||||
|
$item_gunid = $storedFile->getGunid();
|
||||||
|
if( $playLists != NULL) {
|
||||||
|
|
||||||
|
foreach($playLists as $key=>$val) {
|
||||||
|
$playList_id = BasicStor::IdFromGunidBigInt($val["gunid"]);
|
||||||
|
$playList_titles[] = BasicStor::bsGetMetadataValue($playList_id, "dc:title");
|
||||||
|
}
|
||||||
|
return PEAR::raiseError(
|
||||||
|
'Please remove this song from all playlists: ' . join(",", $playList_titles)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case "playlist":
|
case "playlist":
|
||||||
|
if($storedFile->isScheduled()) {
|
||||||
|
return PEAR::raiseError(
|
||||||
|
'Cannot delete an object that is scheduled to play.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case "webstream":
|
case "webstream":
|
||||||
$storedFile = StoredFile::Recall($id);
|
|
||||||
if (is_null($storedFile) || PEAR::isError($storedFile)) {
|
|
||||||
return $storedFile;
|
|
||||||
}
|
|
||||||
$res = $storedFile->setState('deleted');
|
|
||||||
if (PEAR::isError($res)) {
|
|
||||||
return $res;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
return TRUE;
|
|
||||||
|
$res = $storedFile->setState('deleted');
|
||||||
|
if (PEAR::isError($res)) {
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1491,7 +1523,7 @@ class BasicStor {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get local id from global id.
|
* Get local id from global id (in hex).
|
||||||
*
|
*
|
||||||
* @param string $p_gunid
|
* @param string $p_gunid
|
||||||
* Global id
|
* Global id
|
||||||
|
@ -1505,6 +1537,21 @@ class BasicStor {
|
||||||
return $CC_DBC->getOne("SELECT id FROM ".$CC_CONFIG['filesTable']." WHERE gunid=x'$p_gunid'::bigint");
|
return $CC_DBC->getOne("SELECT id FROM ".$CC_CONFIG['filesTable']." WHERE gunid=x'$p_gunid'::bigint");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get local id from global id (big int).
|
||||||
|
*
|
||||||
|
* @param string $p_gunid
|
||||||
|
* Global id
|
||||||
|
* @return int
|
||||||
|
* Local id
|
||||||
|
*/
|
||||||
|
public static function IdFromGunidBigInt($p_gunid)
|
||||||
|
{
|
||||||
|
global $CC_DBC;
|
||||||
|
global $CC_CONFIG;
|
||||||
|
return $CC_DBC->getOne("SELECT id FROM ".$CC_CONFIG['filesTable']." WHERE gunid='$p_gunid'");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get global id from local id
|
* Get global id from local id
|
||||||
|
|
|
@ -1087,6 +1087,35 @@ class StoredFile {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns gunIds of the playlists the stored file is in.
|
||||||
|
*/
|
||||||
|
public function getPlaylists() {
|
||||||
|
global $CC_CONFIG, $CC_DBC;
|
||||||
|
|
||||||
|
$_SESSION['delete'] = "gunid: " . $this->gunid;
|
||||||
|
|
||||||
|
$sql = "SELECT gunid "
|
||||||
|
." FROM ".$CC_CONFIG['mdataTable']
|
||||||
|
." WHERE object='{$this->gunid}'";
|
||||||
|
|
||||||
|
$_SESSION['delete'] = $sql;
|
||||||
|
$playlists = $CC_DBC->getAll($sql);
|
||||||
|
|
||||||
|
return $playlists;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isScheduled() {
|
||||||
|
global $CC_CONFIG, $CC_DBC;
|
||||||
|
|
||||||
|
$sql = "SELECT * "
|
||||||
|
." FROM ".$CC_CONFIG['scheduleTable']
|
||||||
|
." WHERE ends > now() and playlist=x'{$this->gunid}'::bigint";
|
||||||
|
$scheduled = $CC_DBC->getAll($sql);
|
||||||
|
|
||||||
|
return $scheduled;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if virtual file is currently in use.<br>
|
* Returns true if virtual file is currently in use.<br>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue