CC-1799 Put Airtime Storage into a Human Readable File Naming Convention

plupload is not set up with media monitor yet, need to finish import to airtime by dragging into stor folder.
This commit is contained in:
Naomi Aro 2011-06-08 11:59:48 +02:00
parent 69b4847df3
commit f066135380
1 changed files with 106 additions and 167 deletions

View File

@ -51,10 +51,21 @@ class StoredFile {
$this->setMetadata($md); $this->setMetadata($md);
} }
public function getId() { public function getId()
{
return $this->_file->getDbId(); return $this->_file->getDbId();
} }
public function getFormat()
{
return $this->_file->getDbFtype();
}
public function setFormat($p_format)
{
$this->_file->setDbFtype($p_format);
}
/** /**
* Set multiple metadata values using defined metadata constants. * Set multiple metadata values using defined metadata constants.
* *
@ -219,80 +230,6 @@ class StoredFile {
return TRUE; return TRUE;
} }
/**
* Delete media file from filesystem.
* You cant delete a file if it is being accessed.
* You cant delete a file if it is scheduled to be played in the future.
* The file will be removed from all playlists it is a part of.
*
* @return boolean|PEAR_Error
*/
public function deleteFile()
{
global $CC_CONFIG;
if (!$this->exists()) {
return FALSE;
}
if ($this->isAccessed()) {
return PEAR::raiseError(
'Cannot delete a file that is currently accessed.'
);
}
// Check if the file is scheduled to be played in the future
if (Schedule::IsFileScheduledInTheFuture($this->id)) {
return PEAR::raiseError(
'Cannot delete a file that is scheduled in the future.'
);
}
// Only delete the file from filesystem if it has been copied to the
// storage directory. (i.e. dont delete linked files)
if (substr($this->filepath, 0, strlen($CC_CONFIG["storageDir"])) == $CC_CONFIG["storageDir"]) {
// Delete the file
if (!file_exists($this->filepath) || @unlink($this->filepath)) {
$this->exists = FALSE;
return TRUE;
}
else {
return PEAR::raiseError("StoredFile::deleteFile: unlink failed ({$this->filepath})");
}
}
else {
$this->exists = FALSE;
return TRUE;
}
}
/**
* Delete stored virtual file
*
* @param boolean $p_deleteFile
*
* @return TRUE|PEAR_Error
*/
public function delete($p_deleteFile = true)
{
global $CC_CONFIG, $CC_DBC;
if ($p_deleteFile) {
$res = $this->deleteFile();
if (PEAR::isError($res)) {
return $res;
}
Playlist::DeleteFileFromAllPlaylists($this->id);
}
$sql = "DELETE FROM ".$CC_CONFIG['filesTable']
." WHERE gunid='{$this->gunid}'";
$res = $CC_DBC->query($sql);
if (PEAR::isError($res)) {
return $res;
}
return TRUE;
}
/** /**
* Returns an array of playlist objects that this file is a part of. * Returns an array of playlist objects that this file is a part of.
* @return array * @return array
@ -312,72 +249,85 @@ class StoredFile {
return $playlists; return $playlists;
} }
/** /**
* Returns true if virtual file is currently in use.<br> * Delete stored virtual file
* Static or dynamic call is possible.
* *
* @param string $p_gunid * @param boolean $p_deleteFile
* optional (for static call), global unique id *
* @return boolean|PEAR_Error * @return void|PEAR_Error
*/ */
public function isAccessed($p_gunid=NULL) public function delete()
{ {
global $CC_CONFIG, $CC_DBC; if (!$this->exists()) {
if (is_null($p_gunid)) { return PEAR::raiseError('File does not exist.');
return ($this->currentlyaccessing > 0);
} }
$sql = "SELECT currentlyAccessing FROM ".$CC_CONFIG['filesTable']
." WHERE gunid='$p_gunid'"; if ($this->getFormat() == 'audioclip') {
$ca = $CC_DBC->getOne($sql); $res = $this->deleteFile();
if (is_null($ca)) { if (PEAR::isError($res)) {
return PEAR::raiseError( return $res;
"StoredFile::isAccessed: invalid gunid ($p_gunid)", }
GBERR_FOBJNEX
);
} }
return ($ca > 0);
Playlist::DeleteFileFromAllPlaylists($this->getId());
$this->_file->delete();
} }
/**
* Delete media file from filesystem.
* You cant delete a file if it is being accessed.
* You cant delete a file if it is scheduled to be played in the future.
* The file will be removed from all playlists it is a part of.
*
* @return void|PEAR_Error
*/
public function deleteFile()
{
global $CC_CONFIG;
if ($this->isAccessed()) {
return PEAR::raiseError('Cannot delete a file that is currently accessed.');
}
// Check if the file is scheduled to be played in the future
if (Schedule::IsFileScheduledInTheFuture($this->getId())) {
return PEAR::raiseError('Cannot delete a file that is scheduled in the future.');
}
// Only delete the file from filesystem if it has been copied to the storage directory
if (substr($this->getFilePath(), 0, strlen($CC_CONFIG["storageDir"])) == $CC_CONFIG["storageDir"]) {
// Delete the file
$res = unlink($this->getFilePath());
if (!$res) {
return PEAR::raiseError("StoredFile::deleteFile: unlink failed ({$this->getFilePath()})");
}
}
}
/** /**
* Returns true if virtual file is edited * Returns true if media file exists
*
* @param string $p_playlistId
* playlist global unique ID
* @return boolean * @return boolean
*/ */
public function isEdited() public function exists()
{ {
if ($this->_file->isDeleted()) {
return false;
}
if ($this->getFormat() == 'audioclip') {
return $this->existsFile();
}
} }
/** /**
* Returns true if raw media file exists * Returns true if raw media file exists
* @return boolean|PEAR_Error * @return boolean
*/ */
public function exists()
{
global $CC_CONFIG, $CC_DBC;
$sql = "SELECT gunid "
." FROM ".$CC_CONFIG['filesTable']
." WHERE gunid='{$this->gunid}'";
$indb = $CC_DBC->getRow($sql);
if (PEAR::isError($indb)) {
return $indb;
}
if (is_null($indb)) {
return FALSE;
}
if ($this->ftype == 'audioclip') {
return $this->existsFile();
}
return TRUE;
}
public function existsFile() { public function existsFile() {
if (!isset($p_md["filepath"]) || !file_exists($p_md['filepath']) || !is_readable($p_md['filepath'])) { $filepath = $this->_file->getDbFilepath();
if (!isset($filepath) || !file_exists($filepath) || !is_readable($filepath)) {
return false; return false;
} }
else { else {
@ -385,6 +335,16 @@ class StoredFile {
} }
} }
/**
* Returns true if virtual file is currently in use.<br>
*
* @return boolean
*/
public function isAccessed()
{
return ($this->_file->getDbCurrentlyaccessing() > 0);
}
/** /**
* Return suitable extension. * Return suitable extension.
* *
@ -393,33 +353,14 @@ class StoredFile {
*/ */
public function getFileExtension() public function getFileExtension()
{ {
$mime = $this->_file->getDbMime();
} if ($mime == "audio/vorbis") {
return "ogg";
/** }
* Get storage-internal file state else if ($mime == "audio/mp3") {
* return "mp3";
* @param string $p_gunid }
* global unique id of file
* @return string
* see install()
*/
public function getState()
{
}
/**
* Get mnemonic file name
*
* @param string $p_gunid
* global unique id of file
* @return string
*/
public function getName()
{
} }
/** /**
@ -427,7 +368,7 @@ class StoredFile {
* *
* @return string * @return string
*/ */
public function getRealFilePath() public function getFilePath()
{ {
return $this->_file->getDbFilepath(); return $this->_file->getDbFilepath();
} }
@ -515,33 +456,31 @@ class StoredFile {
public static function searchFilesForPlaylistBuilder($datatables) { public static function searchFilesForPlaylistBuilder($datatables) {
global $CC_CONFIG; global $CC_CONFIG;
$displayData = array("track_title", "artist_name", "album_title", "track_number", "length", "ftype");
$plSelect = "SELECT "; $plSelect = "SELECT ";
$fileSelect = "SELECT "; $fileSelect = "SELECT ";
foreach (Metadata::GetMapMetadataXmlToDb() as $key => $val){ foreach ($displayData as $key){
if($key === "dc:title"){ if($key === "track_title"){
$plSelect .= "name AS ".$val.", "; $plSelect .= "name AS ".$key.", ";
$fileSelect .= $val.", "; $fileSelect .= $key.", ";
} }
else if ($key === "ls:type"){ else if ($key === "ftype"){
$plSelect .= "'playlist' AS ".$val.", "; $plSelect .= "'playlist' AS ".$key.", ";
$fileSelect .= $val.", "; $fileSelect .= $key.", ";
} }
else if ($key === "dc:creator"){ else if ($key === "artist_name"){
$plSelect .= "creator AS ".$val.", "; $plSelect .= "creator AS ".$key.", ";
$fileSelect .= $val.", "; $fileSelect .= $key.", ";
} }
else if ($key === "dcterms:extent"){ else if ($key === "length"){
$plSelect .= "length, "; $plSelect .= $key.", ";
$fileSelect .= "length, "; $fileSelect .= $key.", ";
}
else if ($key === "dc:description"){
$plSelect .= "text(description) AS ".$val.", ";
$fileSelect .= $val.", ";
} }
else { else {
$plSelect .= "NULL AS ".$val.", "; $plSelect .= "NULL AS ".$key.", ";
$fileSelect .= $val.", "; $fileSelect .= $key.", ";
} }
} }