2010-12-07 20:19:27 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* StoredFile class
|
|
|
|
*
|
2011-01-05 18:19:58 +01:00
|
|
|
* @package Airtime
|
2010-12-07 20:19:27 +01:00
|
|
|
* @subpackage StorageServer
|
|
|
|
* @copyright 2010 Sourcefabric O.P.S.
|
|
|
|
* @license http://www.gnu.org/licenses/gpl.txt
|
|
|
|
* @see MetaData
|
|
|
|
*/
|
|
|
|
class StoredFile {
|
|
|
|
|
|
|
|
/**
|
2011-06-08 10:15:35 +02:00
|
|
|
* @holds propel database object
|
|
|
|
*/
|
|
|
|
private $_file;
|
2010-12-07 20:19:27 +01:00
|
|
|
|
|
|
|
/**
|
2011-06-08 10:15:35 +02:00
|
|
|
* array of db metadata -> propel
|
2010-12-07 20:19:27 +01:00
|
|
|
*/
|
2011-06-08 10:15:35 +02:00
|
|
|
private $_dbMD = array (
|
|
|
|
"track_title" => "DbTrackTitle",
|
|
|
|
"artist_name" => "DbArtistName",
|
|
|
|
"album_title" => "DbAlbumTitle",
|
|
|
|
"genre" => "DbGenre",
|
|
|
|
"mood" => "DbMood",
|
|
|
|
"track_number" => "DbTrackNumber",
|
|
|
|
"bpm" => "DbBpm",
|
|
|
|
"label" => "DbLabel",
|
|
|
|
"composer" => "DbComposer",
|
|
|
|
"encoded_by" => "DbEncodedBy",
|
|
|
|
"conductor" => "DbConductor",
|
|
|
|
"year" => "DbYear",
|
|
|
|
"info_url" => "DbInfoUrl",
|
|
|
|
"isrc_number" => "DbIsrcNumber",
|
|
|
|
"copyright" => "DbCopyright",
|
|
|
|
"length" => "DbLength",
|
|
|
|
"bit_rate" => "DbBitRate",
|
|
|
|
"sample_rate" => "DbSampleRate",
|
|
|
|
"mime" => "DbMime",
|
2011-06-14 18:52:43 +02:00
|
|
|
"md5" => "DbMd5",
|
|
|
|
"ftype" => "DbFtype"
|
2011-06-08 10:15:35 +02:00
|
|
|
);
|
|
|
|
|
2011-06-09 11:50:03 +02:00
|
|
|
public function __construct()
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2011-06-08 10:15:35 +02:00
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2011-06-08 11:59:48 +02:00
|
|
|
public function getId()
|
|
|
|
{
|
2011-06-08 10:15:35 +02:00
|
|
|
return $this->_file->getDbId();
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2011-06-09 11:50:03 +02:00
|
|
|
public function getGunId() {
|
|
|
|
return $this->_file->getDbGunid();
|
|
|
|
}
|
|
|
|
|
2011-06-08 11:59:48 +02:00
|
|
|
public function getFormat()
|
|
|
|
{
|
|
|
|
return $this->_file->getDbFtype();
|
|
|
|
}
|
|
|
|
|
2011-06-20 20:10:33 +02:00
|
|
|
public function getPropelOrm(){
|
|
|
|
return $this->_file;
|
|
|
|
}
|
|
|
|
|
2011-06-08 11:59:48 +02:00
|
|
|
public function setFormat($p_format)
|
|
|
|
{
|
|
|
|
$this->_file->setDbFtype($p_format);
|
|
|
|
}
|
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
/**
|
2011-06-08 10:15:35 +02:00
|
|
|
* Set multiple metadata values using defined metadata constants.
|
2010-12-07 20:19:27 +01:00
|
|
|
*
|
2011-06-08 10:15:35 +02:00
|
|
|
* @param array $p_md
|
|
|
|
* example: $p_md['MDATA_KEY_URL'] = 'http://www.fake.com'
|
2010-12-07 20:19:27 +01:00
|
|
|
*/
|
2011-06-08 10:15:35 +02:00
|
|
|
public function setMetadata($p_md=null)
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2011-06-08 10:15:35 +02:00
|
|
|
if (is_null($p_md)) {
|
|
|
|
$this->setDbColMetadata();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$dbMd = array();
|
|
|
|
foreach ($p_md as $mdConst => $mdValue) {
|
|
|
|
$dbMd[constant($mdConst)] = $mdValue;
|
|
|
|
}
|
|
|
|
$this->setDbColMetadata($dbMd);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-15 18:06:50 +02:00
|
|
|
public static function getFileCount()
|
|
|
|
{
|
|
|
|
global $CC_CONFIG, $CC_DBC;
|
2011-06-30 16:45:55 +02:00
|
|
|
$sql = "SELECT count(*) as cnt FROM ".$CC_CONFIG["filesTable"];
|
2011-06-23 17:33:05 +02:00
|
|
|
return $CC_DBC->GetOne($sql);
|
2011-06-15 18:06:50 +02:00
|
|
|
}
|
2011-06-23 17:33:05 +02:00
|
|
|
|
2011-06-08 10:15:35 +02:00
|
|
|
/**
|
|
|
|
* Set multiple metadata values using database columns as indexes.
|
|
|
|
*
|
|
|
|
* @param array $p_md
|
|
|
|
* example: $p_md['url'] = 'http://www.fake.com'
|
|
|
|
*/
|
|
|
|
public function setDbColMetadata($p_md=null)
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2011-06-08 10:15:35 +02:00
|
|
|
if (is_null($p_md)) {
|
|
|
|
foreach ($this->_dbMD as $dbColumn => $propelColumn) {
|
|
|
|
$method = "set$propelColumn";
|
|
|
|
$this->_file->$method(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach ($p_md as $dbColumn => $mdValue) {
|
2011-06-15 09:19:41 +02:00
|
|
|
//don't blank out name, defaults to original filename on first insertion to database.
|
2011-06-15 11:12:57 +02:00
|
|
|
if($dbColumn == "track_title" && (is_null($mdValue) || $mdValue == "")) {
|
2011-06-15 09:19:41 +02:00
|
|
|
continue;
|
|
|
|
}
|
2011-06-21 10:24:02 +02:00
|
|
|
if (isset($this->_dbMD[$dbColumn])) {
|
|
|
|
$propelColumn = $this->_dbMD[$dbColumn];
|
|
|
|
$method = "set$propelColumn";
|
|
|
|
$this->_file->$method($mdValue);
|
|
|
|
}
|
2011-06-08 10:15:35 +02:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
2011-06-08 10:15:35 +02:00
|
|
|
|
|
|
|
$this->_file->save();
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set metadata element value
|
|
|
|
*
|
|
|
|
* @param string $category
|
2011-06-08 10:15:35 +02:00
|
|
|
* Metadata element by metadata constant
|
2010-12-07 20:19:27 +01:00
|
|
|
* @param string $value
|
|
|
|
* value to store, if NULL then delete record
|
|
|
|
*/
|
|
|
|
public function setMetadataValue($p_category, $p_value)
|
|
|
|
{
|
2011-07-15 23:35:16 +02:00
|
|
|
// constant() was used because it gets quoted constant name value from
|
|
|
|
// api_client.py. This is the wrapper funtion
|
2011-06-08 10:15:35 +02:00
|
|
|
$this->setDbColMetadataValue(constant($p_category), $p_value);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-06-08 10:15:35 +02:00
|
|
|
* Set metadata element value
|
2010-12-07 20:19:27 +01:00
|
|
|
*
|
2011-06-08 10:15:35 +02:00
|
|
|
* @param string $category
|
|
|
|
* Metadata element by db column
|
|
|
|
* @param string $value
|
|
|
|
* value to store, if NULL then delete record
|
2010-12-07 20:19:27 +01:00
|
|
|
*/
|
2011-06-08 10:15:35 +02:00
|
|
|
public function setDbColMetadataValue($p_category, $p_value)
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2011-06-15 09:19:41 +02:00
|
|
|
//don't blank out name, defaults to original filename on first insertion to database.
|
|
|
|
if($p_category == "track_title" && (is_null($p_value) || $p_value == "")) {
|
|
|
|
return;
|
|
|
|
}
|
2011-07-15 23:35:16 +02:00
|
|
|
if (isset($this->_dbMD[$p_category])) {
|
2011-06-21 10:24:02 +02:00
|
|
|
$propelColumn = $this->_dbMD[$p_category];
|
|
|
|
$method = "set$propelColumn";
|
|
|
|
$this->_file->$method($p_value);
|
|
|
|
$this->_file->save();
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-06-08 10:15:35 +02:00
|
|
|
* Get one metadata value.
|
2010-12-07 20:19:27 +01:00
|
|
|
*
|
2011-06-08 10:15:35 +02:00
|
|
|
* @param string $p_category (MDATA_KEY_URL)
|
|
|
|
* @return string
|
2010-12-07 20:19:27 +01:00
|
|
|
*/
|
2011-06-08 10:15:35 +02:00
|
|
|
public function getMetadataValue($p_category)
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2011-07-15 23:35:16 +02:00
|
|
|
// constant() was used because it gets quoted constant name value from
|
|
|
|
// api_client.py. This is the wrapper funtion
|
|
|
|
return $this->getDbColMetadataValue(constant($p_category));
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2011-06-08 10:15:35 +02:00
|
|
|
/**
|
2010-12-07 20:19:27 +01:00
|
|
|
* Get one metadata value.
|
|
|
|
*
|
2011-06-08 10:15:35 +02:00
|
|
|
* @param string $p_category (url)
|
2010-12-07 20:19:27 +01:00
|
|
|
* @return string
|
|
|
|
*/
|
2011-06-08 10:15:35 +02:00
|
|
|
public function getDbColMetadataValue($p_category)
|
|
|
|
{
|
|
|
|
$propelColumn = $this->_dbMD[$p_category];
|
|
|
|
$method = "get$propelColumn";
|
|
|
|
return $this->_file->$method();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get metadata as array, indexed by the column names in the database.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getDbColMetadata()
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2011-06-08 10:15:35 +02:00
|
|
|
$md = array();
|
|
|
|
foreach ($this->_dbMD as $dbColumn => $propelColumn) {
|
|
|
|
$method = "get$propelColumn";
|
|
|
|
$md[$dbColumn] = $this->_file->$method();
|
2010-12-07 23:29:28 +01:00
|
|
|
}
|
2011-06-08 10:15:35 +02:00
|
|
|
|
|
|
|
return $md;
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2011-06-15 14:20:14 +02:00
|
|
|
/**
|
|
|
|
* Get metadata as array, indexed by the constant names.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getMetadata()
|
|
|
|
{
|
|
|
|
$c = get_defined_constants(true);
|
|
|
|
$md = array();
|
|
|
|
|
|
|
|
foreach ($c['user'] as $constant => $value) {
|
|
|
|
if (preg_match('/^MDATA_KEY/', $constant)) {
|
|
|
|
if (isset($this->_dbMD[$value])) {
|
|
|
|
$md[$constant] = $this->getDbColMetadataValue($value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $md;
|
|
|
|
}
|
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
/**
|
2011-06-08 10:15:35 +02:00
|
|
|
* Delete and insert media file
|
2010-12-07 20:19:27 +01:00
|
|
|
*
|
2011-06-08 10:15:35 +02:00
|
|
|
* @param string $p_localFilePath
|
|
|
|
* local path
|
2010-12-07 20:19:27 +01:00
|
|
|
* @return TRUE|PEAR_Error
|
|
|
|
*/
|
2011-06-08 10:15:35 +02:00
|
|
|
public function replaceFile($p_localFilePath, $p_copyMedia=TRUE)
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2011-06-08 10:15:35 +02:00
|
|
|
// Dont do anything if the source and destination files are
|
|
|
|
// the same.
|
|
|
|
if ($this->name == $p_localFilePath) {
|
|
|
|
return TRUE;
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2011-06-08 10:15:35 +02:00
|
|
|
if ($this->exists) {
|
|
|
|
$r = $this->deleteFile();
|
|
|
|
if (PEAR::isError($r)) {
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->addFile($p_localFilePath, $p_copyMedia);
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set state of virtual file
|
|
|
|
*
|
|
|
|
* @param string $p_state
|
|
|
|
* 'empty'|'incomplete'|'ready'|'edited'
|
|
|
|
* @param int $p_editedby
|
|
|
|
* user id | 'NULL' for clear editedBy field
|
|
|
|
* @return TRUE|PEAR_Error
|
|
|
|
*/
|
|
|
|
public function setState($p_state, $p_editedby=NULL)
|
|
|
|
{
|
|
|
|
global $CC_CONFIG, $CC_DBC;
|
|
|
|
$escapedState = pg_escape_string($p_state);
|
|
|
|
$eb = (!is_null($p_editedby) ? ", editedBy=$p_editedby" : '');
|
|
|
|
$sql = "UPDATE ".$CC_CONFIG['filesTable']
|
2010-12-07 23:29:28 +01:00
|
|
|
." SET state='$escapedState'$eb, mtime=now()"
|
|
|
|
." WHERE gunid='{$this->gunid}'";
|
2010-12-07 20:19:27 +01:00
|
|
|
$res = $CC_DBC->query($sql);
|
|
|
|
if (PEAR::isError($res)) {
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
$this->state = $p_state;
|
|
|
|
$this->editedby = $p_editedby;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array of playlist objects that this file is a part of.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getPlaylists() {
|
|
|
|
global $CC_CONFIG, $CC_DBC;
|
|
|
|
$sql = "SELECT playlist_id "
|
2010-12-07 23:29:28 +01:00
|
|
|
." FROM ".$CC_CONFIG['playistTable']
|
|
|
|
." WHERE file_id='{$this->id}'";
|
2010-12-07 20:19:27 +01:00
|
|
|
$ids = $CC_DBC->getAll($sql);
|
|
|
|
$playlists = array();
|
|
|
|
if (is_array($ids) && count($ids) > 0) {
|
2010-12-07 23:29:28 +01:00
|
|
|
foreach ($ids as $id) {
|
|
|
|
$playlists[] = Playlist::Recall($id);
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
return $playlists;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-06-08 11:59:48 +02:00
|
|
|
* Delete stored virtual file
|
2010-12-07 20:19:27 +01:00
|
|
|
*
|
2011-06-08 11:59:48 +02:00
|
|
|
* @param boolean $p_deleteFile
|
|
|
|
*
|
|
|
|
* @return void|PEAR_Error
|
2010-12-07 20:19:27 +01:00
|
|
|
*/
|
2011-06-08 11:59:48 +02:00
|
|
|
public function delete()
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2011-06-13 16:41:57 +02:00
|
|
|
if ($this->exists()) {
|
|
|
|
if ($this->getFormat() == 'audioclip') {
|
|
|
|
$res = $this->deleteFile();
|
|
|
|
if (PEAR::isError($res)) {
|
|
|
|
return $res;
|
|
|
|
}
|
2011-06-08 11:59:48 +02:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2011-06-08 11:59:48 +02:00
|
|
|
Playlist::DeleteFileFromAllPlaylists($this->getId());
|
|
|
|
$this->_file->delete();
|
2011-07-19 11:00:32 +02:00
|
|
|
|
2011-07-19 11:50:49 +02:00
|
|
|
if (isset($res)) {
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
2011-06-08 11:59:48 +02:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
|
|
|
/**
|
2011-06-08 11:59:48 +02:00
|
|
|
* 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.
|
2010-12-07 20:19:27 +01:00
|
|
|
*
|
2011-07-18 15:28:17 +02:00
|
|
|
* @return boolean|PEAR_Error
|
2010-12-07 20:19:27 +01:00
|
|
|
*/
|
2011-06-08 11:59:48 +02:00
|
|
|
public function deleteFile()
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2011-06-08 11:59:48 +02:00
|
|
|
global $CC_CONFIG;
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2011-06-08 11:59:48 +02:00
|
|
|
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.');
|
|
|
|
}
|
2011-07-18 15:28:17 +02:00
|
|
|
|
2011-07-18 19:48:20 +02:00
|
|
|
return true;
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-06-08 11:59:48 +02:00
|
|
|
* Returns true if media file exists
|
|
|
|
* @return boolean
|
2010-12-07 20:19:27 +01:00
|
|
|
*/
|
|
|
|
public function exists()
|
|
|
|
{
|
2011-06-08 11:59:48 +02:00
|
|
|
if ($this->_file->isDeleted()) {
|
|
|
|
return false;
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
2011-06-08 11:59:48 +02:00
|
|
|
if ($this->getFormat() == 'audioclip') {
|
2010-12-07 20:19:27 +01:00
|
|
|
return $this->existsFile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-08 11:59:48 +02:00
|
|
|
/**
|
|
|
|
* Returns true if raw media file exists
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2011-06-08 10:15:35 +02:00
|
|
|
public function existsFile() {
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2011-07-18 15:28:17 +02:00
|
|
|
$filepath = $this->getFilePath();
|
2011-06-08 11:59:48 +02:00
|
|
|
|
|
|
|
if (!isset($filepath) || !file_exists($filepath) || !is_readable($filepath)) {
|
2011-06-08 10:15:35 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return true;
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2011-06-08 11:59:48 +02:00
|
|
|
/**
|
|
|
|
* Returns true if virtual file is currently in use.<br>
|
2010-12-07 20:19:27 +01:00
|
|
|
*
|
2011-06-08 11:59:48 +02:00
|
|
|
* @return boolean
|
2010-12-07 20:19:27 +01:00
|
|
|
*/
|
2011-06-08 11:59:48 +02:00
|
|
|
public function isAccessed()
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2011-06-08 11:59:48 +02:00
|
|
|
return ($this->_file->getDbCurrentlyaccessing() > 0);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-06-08 11:59:48 +02:00
|
|
|
* Return suitable extension.
|
2010-12-07 20:19:27 +01:00
|
|
|
*
|
|
|
|
* @return string
|
2011-06-08 11:59:48 +02:00
|
|
|
* file extension without a dot
|
2010-12-07 20:19:27 +01:00
|
|
|
*/
|
2011-06-08 11:59:48 +02:00
|
|
|
public function getFileExtension()
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2011-06-08 11:59:48 +02:00
|
|
|
$mime = $this->_file->getDbMime();
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2011-06-08 11:59:48 +02:00
|
|
|
if ($mime == "audio/vorbis") {
|
|
|
|
return "ogg";
|
|
|
|
}
|
|
|
|
else if ($mime == "audio/mp3") {
|
|
|
|
return "mp3";
|
|
|
|
}
|
2011-06-08 10:15:35 +02:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get real filename of raw media data
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2011-06-08 11:59:48 +02:00
|
|
|
public function getFilePath()
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2011-06-21 10:24:02 +02:00
|
|
|
$music_dir = MusicDir::getDirByPK($this->_file->getDbDirectory());
|
|
|
|
$filepath = $this->_file->getDbFilepath();
|
|
|
|
|
2011-07-12 23:05:40 +02:00
|
|
|
return $music_dir->getDirectory().$filepath;
|
2011-06-21 10:24:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set real filename of raw media data
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function setFilePath($p_filepath)
|
|
|
|
{
|
|
|
|
$path_info = MusicDir::splitFilePath($p_filepath);
|
|
|
|
if (is_null($path_info)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
$musicDir = MusicDir::getDirByPath($path_info[0]);
|
|
|
|
|
|
|
|
$this->_file->setDbDirectory($musicDir->getId());
|
|
|
|
$this->_file->setDbFilepath($path_info[1]);
|
|
|
|
$this->_file->save();
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the URL to access this file.
|
|
|
|
*/
|
|
|
|
public function getFileUrl()
|
|
|
|
{
|
2010-12-07 23:29:28 +01:00
|
|
|
global $CC_CONFIG;
|
2011-06-09 11:50:03 +02:00
|
|
|
return "http://$CC_CONFIG[baseUrl]:$CC_CONFIG[basePort]/api/get-media/file/".$this->getGunId().".".$this->getFileExtension();
|
|
|
|
}
|
|
|
|
|
2011-06-22 22:50:58 +02:00
|
|
|
/**
|
|
|
|
* Sometimes we want a relative URL and not a full URL. See bug
|
|
|
|
* http://dev.sourcefabric.org/browse/CC-2403
|
|
|
|
*/
|
2011-06-24 22:04:57 +02:00
|
|
|
public function getRelativeFileUrl($baseUrl)
|
2011-06-22 22:50:58 +02:00
|
|
|
{
|
2011-06-24 22:04:57 +02:00
|
|
|
return $baseUrl."/api/get-media/file/".$this->getGunId().".".$this->getFileExtension();
|
2011-06-22 22:50:58 +02:00
|
|
|
}
|
|
|
|
|
2011-06-09 11:50:03 +02:00
|
|
|
public static function Insert($md=null)
|
|
|
|
{
|
|
|
|
$file = new CcFiles();
|
|
|
|
$file->setDbGunid(md5(uniqid("", true)));
|
|
|
|
|
2011-06-09 12:57:30 +02:00
|
|
|
$storedFile = new StoredFile();
|
|
|
|
$storedFile->_file = $file;
|
|
|
|
|
2011-06-21 10:24:02 +02:00
|
|
|
if(isset($md['MDATA_KEY_FILEPATH'])) {
|
|
|
|
$res = $storedFile->setFilePath($md['MDATA_KEY_FILEPATH']);
|
|
|
|
if ($res === -1) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2011-06-09 11:50:03 +02:00
|
|
|
if(isset($md)) {
|
2011-06-09 12:57:30 +02:00
|
|
|
$storedFile->setMetadata($md);
|
2011-06-09 11:50:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $storedFile;
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-06-08 10:15:35 +02:00
|
|
|
* Fetch instance of StoreFile object.<br>
|
|
|
|
* Should be supplied with only ONE parameter, all the rest should
|
|
|
|
* be NULL.
|
2010-12-07 20:19:27 +01:00
|
|
|
*
|
2011-06-08 10:15:35 +02:00
|
|
|
* @param int $p_id
|
|
|
|
* local id
|
|
|
|
* @param string $p_gunid
|
|
|
|
* global unique id of file
|
|
|
|
* @param string $p_md5sum
|
|
|
|
* MD5 sum of the file
|
2011-06-09 11:50:03 +02:00
|
|
|
* @return StoredFile|NULL
|
2011-06-08 10:15:35 +02:00
|
|
|
* Return NULL if the object doesnt exist in the DB.
|
2010-12-07 20:19:27 +01:00
|
|
|
*/
|
2011-06-08 10:15:35 +02:00
|
|
|
public static function Recall($p_id=null, $p_gunid=null, $p_md5sum=null, $p_filepath=null)
|
|
|
|
{
|
|
|
|
if (isset($p_id)) {
|
2011-06-09 11:50:03 +02:00
|
|
|
$file = CcFilesQuery::create()->findPK(intval($p_id));
|
2011-06-08 10:15:35 +02:00
|
|
|
}
|
|
|
|
else if (isset($p_gunid)) {
|
2011-06-09 11:50:03 +02:00
|
|
|
$file = CcFilesQuery::create()
|
2011-06-08 18:24:17 +02:00
|
|
|
->filterByDbGunid($p_gunid)
|
|
|
|
->findOne();
|
2011-06-08 10:15:35 +02:00
|
|
|
}
|
|
|
|
else if (isset($p_md5sum)) {
|
2011-06-09 11:50:03 +02:00
|
|
|
$file = CcFilesQuery::create()
|
2011-06-08 18:24:17 +02:00
|
|
|
->filterByDbMd5($p_md5sum)
|
|
|
|
->findOne();
|
2011-06-08 10:15:35 +02:00
|
|
|
}
|
|
|
|
else if (isset($p_filepath)) {
|
2011-06-21 10:24:02 +02:00
|
|
|
$path_info = MusicDir::splitFilePath($p_filepath);
|
|
|
|
if (is_null($path_info)) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-06-28 15:04:03 +02:00
|
|
|
$music_dir = MusicDir::getDirByPath($path_info[0]);
|
2011-06-21 10:24:02 +02:00
|
|
|
|
2011-06-09 11:50:03 +02:00
|
|
|
$file = CcFilesQuery::create()
|
2011-06-21 10:24:02 +02:00
|
|
|
->filterByDbDirectory($music_dir->getId())
|
|
|
|
->filterByDbFilepath($path_info[1])
|
2011-06-08 18:24:17 +02:00
|
|
|
->findOne();
|
2011-06-08 10:15:35 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2011-06-09 12:57:30 +02:00
|
|
|
if (isset($file)) {
|
|
|
|
$storedFile = new StoredFile();
|
|
|
|
$storedFile->_file = $file;
|
2011-06-09 11:50:03 +02:00
|
|
|
|
2011-06-09 12:57:30 +02:00
|
|
|
return $storedFile;
|
|
|
|
}
|
2011-06-10 16:43:30 +02:00
|
|
|
else {
|
2011-06-09 12:57:30 +02:00
|
|
|
return null;
|
|
|
|
}
|
2011-06-08 10:15:35 +02:00
|
|
|
}
|
2011-06-28 15:04:03 +02:00
|
|
|
|
2011-06-27 17:23:48 +02:00
|
|
|
public function getName(){
|
|
|
|
$info = pathinfo($this->getFilePath());
|
|
|
|
return $info['filename'];
|
|
|
|
}
|
2011-06-08 10:15:35 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create instance of StoreFile object and recall existing file
|
|
|
|
* by gunid.
|
|
|
|
*
|
|
|
|
* @param string $p_gunid
|
|
|
|
* global unique id of file
|
|
|
|
* @return StoredFile|NULL
|
|
|
|
*/
|
|
|
|
public static function RecallByGunid($p_gunid)
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2011-06-08 10:15:35 +02:00
|
|
|
return StoredFile::Recall(null, $p_gunid);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-06-08 10:15:35 +02:00
|
|
|
* Fetch the StoredFile by looking up the MD5 value.
|
2010-12-07 20:19:27 +01:00
|
|
|
*
|
2011-06-08 10:15:35 +02:00
|
|
|
* @param string $p_md5sum
|
|
|
|
* @return StoredFile|NULL
|
2010-12-07 20:19:27 +01:00
|
|
|
*/
|
2011-06-08 10:15:35 +02:00
|
|
|
public static function RecallByMd5($p_md5sum)
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2011-06-08 10:15:35 +02:00
|
|
|
return StoredFile::Recall(null, null, $p_md5sum);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2011-06-08 10:15:35 +02:00
|
|
|
/**
|
|
|
|
* Fetch the StoredFile by looking up its filepath.
|
|
|
|
*
|
|
|
|
* @param string $p_filepath path of file stored in Airtime.
|
|
|
|
* @return StoredFile|NULL
|
|
|
|
*/
|
|
|
|
public static function RecallByFilepath($p_filepath)
|
|
|
|
{
|
|
|
|
return StoredFile::Recall(null, null, null, $p_filepath);
|
|
|
|
}
|
2011-01-26 20:17:52 +01:00
|
|
|
|
2011-03-06 17:35:10 +01:00
|
|
|
public static function searchFilesForPlaylistBuilder($datatables) {
|
|
|
|
global $CC_CONFIG;
|
2010-12-07 23:29:28 +01:00
|
|
|
|
2011-06-08 11:59:48 +02:00
|
|
|
$displayData = array("track_title", "artist_name", "album_title", "track_number", "length", "ftype");
|
|
|
|
|
2010-12-30 00:43:17 +01:00
|
|
|
$plSelect = "SELECT ";
|
|
|
|
$fileSelect = "SELECT ";
|
2011-06-08 11:59:48 +02:00
|
|
|
foreach ($displayData as $key){
|
2011-01-26 00:41:59 +01:00
|
|
|
|
2011-06-08 11:59:48 +02:00
|
|
|
if($key === "track_title"){
|
|
|
|
$plSelect .= "name AS ".$key.", ";
|
|
|
|
$fileSelect .= $key.", ";
|
2010-12-30 00:43:17 +01:00
|
|
|
}
|
2011-06-08 11:59:48 +02:00
|
|
|
else if ($key === "ftype"){
|
|
|
|
$plSelect .= "'playlist' AS ".$key.", ";
|
|
|
|
$fileSelect .= $key.", ";
|
2010-12-30 00:43:17 +01:00
|
|
|
}
|
2011-06-08 11:59:48 +02:00
|
|
|
else if ($key === "artist_name"){
|
|
|
|
$plSelect .= "creator AS ".$key.", ";
|
|
|
|
$fileSelect .= $key.", ";
|
2010-12-30 00:43:17 +01:00
|
|
|
}
|
2011-06-08 11:59:48 +02:00
|
|
|
else if ($key === "length"){
|
|
|
|
$plSelect .= $key.", ";
|
|
|
|
$fileSelect .= $key.", ";
|
2010-12-30 00:43:17 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-06-08 11:59:48 +02:00
|
|
|
$plSelect .= "NULL AS ".$key.", ";
|
|
|
|
$fileSelect .= $key.", ";
|
2010-12-30 00:43:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-28 00:38:02 +01:00
|
|
|
$fromTable = " ((".$plSelect."PL.id
|
|
|
|
FROM ".$CC_CONFIG["playListTable"]." AS PL
|
|
|
|
LEFT JOIN ".$CC_CONFIG['playListTimeView']." AS PLT USING(id))
|
|
|
|
|
|
|
|
UNION
|
|
|
|
|
|
|
|
(".$fileSelect."id FROM ".$CC_CONFIG["filesTable"]." AS FILES)) AS RESULTS";
|
|
|
|
|
|
|
|
return StoredFile::searchFiles($fromTable, $datatables);
|
2011-02-22 18:22:31 +01:00
|
|
|
|
2011-01-28 00:38:02 +01:00
|
|
|
}
|
|
|
|
|
2011-04-25 22:48:34 +02:00
|
|
|
public static function searchPlaylistsForSchedule($datatables)
|
2011-03-07 18:43:05 +01:00
|
|
|
{
|
2011-01-28 00:38:02 +01:00
|
|
|
$fromTable = "cc_playlist AS pl LEFT JOIN cc_playlisttimes AS plt USING(id) LEFT JOIN cc_subjs AS sub ON pl.editedby = sub.id";
|
2011-04-06 23:53:09 +02:00
|
|
|
//$datatables["optWhere"][] = "INTERVAL '{$time_remaining}' > INTERVAL '00:00:00'";
|
2011-02-12 23:26:02 +01:00
|
|
|
$datatables["optWhere"][] = "plt.length > INTERVAL '00:00:00'";
|
2011-03-07 18:43:05 +01:00
|
|
|
|
2011-01-28 00:38:02 +01:00
|
|
|
return StoredFile::searchFiles($fromTable, $datatables);
|
2011-02-22 18:22:31 +01:00
|
|
|
}
|
2010-12-30 00:43:17 +01:00
|
|
|
|
2011-02-08 01:03:14 +01:00
|
|
|
public static function searchFiles($fromTable, $data)
|
2011-01-28 00:38:02 +01:00
|
|
|
{
|
|
|
|
global $CC_CONFIG, $CC_DBC;
|
2010-12-30 00:43:17 +01:00
|
|
|
|
2011-01-28 00:38:02 +01:00
|
|
|
$columnsDisplayed = explode(",", $data["sColumns"]);
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2011-01-28 00:38:02 +01:00
|
|
|
if($data["sSearch"] !== "")
|
|
|
|
$searchTerms = explode(" ", $data["sSearch"]);
|
|
|
|
|
|
|
|
$selectorCount = "SELECT COUNT(*)";
|
|
|
|
$selectorRows = "SELECT ". join("," , $columnsDisplayed);
|
|
|
|
|
|
|
|
$sql = $selectorCount." FROM ".$fromTable;
|
2011-01-26 00:41:59 +01:00
|
|
|
$totalRows = $CC_DBC->getOne($sql);
|
|
|
|
|
2011-01-26 20:17:52 +01:00
|
|
|
// Where clause
|
2011-01-28 00:38:02 +01:00
|
|
|
if(isset($data["optWhere"])) {
|
2011-02-22 18:22:31 +01:00
|
|
|
$where[] = join(" AND ", $data["optWhere"]);
|
2011-01-28 00:38:02 +01:00
|
|
|
}
|
|
|
|
|
2011-01-26 20:17:52 +01:00
|
|
|
if(isset($searchTerms)) {
|
|
|
|
$searchCols = array();
|
|
|
|
for($i=0; $i<$data["iColumns"]; $i++) {
|
|
|
|
if($data["bSearchable_".$i] == "true") {
|
|
|
|
$searchCols[] = $columnsDisplayed[$i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$outerCond = array();
|
|
|
|
|
|
|
|
foreach($searchTerms as $term) {
|
|
|
|
$innerCond = array();
|
|
|
|
|
|
|
|
foreach($searchCols as $col) {
|
2011-02-22 17:59:55 +01:00
|
|
|
$escapedTerm = pg_escape_string($term);
|
2011-03-05 17:06:22 +01:00
|
|
|
$innerCond[] = "{$col}::text ILIKE '%{$escapedTerm}%'";
|
2011-01-26 20:17:52 +01:00
|
|
|
}
|
2011-02-22 18:22:31 +01:00
|
|
|
$outerCond[] = "(".join(" OR ", $innerCond).")";
|
2011-01-26 20:17:52 +01:00
|
|
|
}
|
2011-01-28 00:38:02 +01:00
|
|
|
$where[] = "(".join(" AND ", $outerCond).")";
|
2011-01-26 20:17:52 +01:00
|
|
|
}
|
|
|
|
// End Where clause
|
|
|
|
|
|
|
|
// Order By clause
|
|
|
|
$orderby = array();
|
|
|
|
for($i=0; $i<$data["iSortingCols"]; $i++){
|
|
|
|
$orderby[] = $columnsDisplayed[$data["iSortCol_".$i]]." ".$data["sSortDir_".$i];
|
|
|
|
}
|
|
|
|
$orderby[] = "id";
|
|
|
|
$orderby = join("," , $orderby);
|
|
|
|
// End Order By clause
|
|
|
|
|
2011-01-26 00:41:59 +01:00
|
|
|
//ordered by integer as expected by datatables.
|
|
|
|
$CC_DBC->setFetchMode(DB_FETCHMODE_ORDERED);
|
2011-01-26 20:17:52 +01:00
|
|
|
|
|
|
|
if(isset($where)) {
|
2011-01-28 00:38:02 +01:00
|
|
|
$where = join(" AND ", $where);
|
|
|
|
$sql = $selectorCount." FROM ".$fromTable." WHERE ".$where;
|
|
|
|
$totalDisplayRows = $CC_DBC->getOne($sql);
|
|
|
|
$sql = $selectorRows." FROM ".$fromTable." WHERE ".$where." ORDER BY ".$orderby." OFFSET ".$data["iDisplayStart"]." LIMIT ".$data["iDisplayLength"];
|
2011-01-26 20:17:52 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-01-28 00:38:02 +01:00
|
|
|
$sql = $selectorRows." FROM ".$fromTable." ORDER BY ".$orderby." OFFSET ".$data["iDisplayStart"]." LIMIT ".$data["iDisplayLength"];
|
2011-01-26 20:17:52 +01:00
|
|
|
}
|
2011-02-22 18:22:31 +01:00
|
|
|
|
2011-01-26 00:41:59 +01:00
|
|
|
$results = $CC_DBC->getAll($sql);
|
|
|
|
//echo $results;
|
|
|
|
//echo $sql;
|
|
|
|
|
2011-02-22 18:22:31 +01:00
|
|
|
//put back to default fetch mode.
|
2011-01-26 00:41:59 +01:00
|
|
|
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
|
|
|
|
|
2011-01-26 20:17:52 +01:00
|
|
|
if(!isset($totalDisplayRows)) {
|
|
|
|
$totalDisplayRows = $totalRows;
|
|
|
|
}
|
|
|
|
|
2011-01-28 00:38:02 +01:00
|
|
|
return array("sEcho" => intval($data["sEcho"]), "iTotalDisplayRecords" => $totalDisplayRows, "iTotalRecords" => $totalRows, "aaData" => $results);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2011-06-08 10:15:35 +02:00
|
|
|
public static function uploadFile($p_targetDir)
|
2011-06-06 16:18:03 +02:00
|
|
|
{
|
2011-03-25 04:07:13 +01:00
|
|
|
// HTTP headers for no cache etc
|
|
|
|
header('Content-type: text/plain; charset=UTF-8');
|
|
|
|
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
|
|
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
|
|
|
|
header("Cache-Control: no-store, no-cache, must-revalidate");
|
|
|
|
header("Cache-Control: post-check=0, pre-check=0", false);
|
|
|
|
header("Pragma: no-cache");
|
|
|
|
|
|
|
|
// Settings
|
|
|
|
$cleanupTargetDir = false; // Remove old files
|
|
|
|
$maxFileAge = 60 * 60; // Temp file age in seconds
|
|
|
|
|
|
|
|
// 5 minutes execution time
|
|
|
|
@set_time_limit(5 * 60);
|
|
|
|
// usleep(5000);
|
|
|
|
|
|
|
|
// Get parameters
|
|
|
|
$chunk = isset($_REQUEST["chunk"]) ? $_REQUEST["chunk"] : 0;
|
|
|
|
$chunks = isset($_REQUEST["chunks"]) ? $_REQUEST["chunks"] : 0;
|
|
|
|
$fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : '';
|
|
|
|
|
|
|
|
// Clean the fileName for security reasons
|
2011-07-21 12:12:37 +02:00
|
|
|
//this needs fixing for songs not in ascii.
|
|
|
|
//$fileName = preg_replace('/[^\w\._]+/', '', $fileName);
|
2011-03-25 04:07:13 +01:00
|
|
|
|
|
|
|
// Create target dir
|
2011-06-06 16:18:03 +02:00
|
|
|
if (!file_exists($p_targetDir))
|
|
|
|
@mkdir($p_targetDir);
|
2011-03-25 04:07:13 +01:00
|
|
|
|
|
|
|
// Remove old temp files
|
2011-06-06 16:18:03 +02:00
|
|
|
if (is_dir($p_targetDir) && ($dir = opendir($p_targetDir))) {
|
2011-03-25 04:07:13 +01:00
|
|
|
while (($file = readdir($dir)) !== false) {
|
2011-06-06 16:18:03 +02:00
|
|
|
$filePath = $p_targetDir . DIRECTORY_SEPARATOR . $file;
|
2011-03-25 04:07:13 +01:00
|
|
|
|
|
|
|
// Remove temp files if they are older than the max age
|
|
|
|
if (preg_match('/\.tmp$/', $file) && (filemtime($filePath) < time() - $maxFileAge))
|
|
|
|
@unlink($filePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
closedir($dir);
|
|
|
|
} else
|
|
|
|
die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}');
|
|
|
|
|
|
|
|
// Look for the content type header
|
|
|
|
if (isset($_SERVER["HTTP_CONTENT_TYPE"]))
|
|
|
|
$contentType = $_SERVER["HTTP_CONTENT_TYPE"];
|
|
|
|
|
|
|
|
if (isset($_SERVER["CONTENT_TYPE"]))
|
|
|
|
$contentType = $_SERVER["CONTENT_TYPE"];
|
|
|
|
|
|
|
|
if (strpos($contentType, "multipart") !== false) {
|
|
|
|
if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
|
|
|
|
// Open temp file
|
2011-06-06 16:18:03 +02:00
|
|
|
$out = fopen($p_targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab");
|
2011-03-25 04:07:13 +01:00
|
|
|
if ($out) {
|
|
|
|
// Read binary input stream and append it to temp file
|
|
|
|
$in = fopen($_FILES['file']['tmp_name'], "rb");
|
|
|
|
|
|
|
|
if ($in) {
|
|
|
|
while ($buff = fread($in, 4096))
|
|
|
|
fwrite($out, $buff);
|
|
|
|
} else
|
|
|
|
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
|
|
|
|
|
|
|
|
fclose($out);
|
|
|
|
unlink($_FILES['file']['tmp_name']);
|
|
|
|
} else
|
|
|
|
die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
|
|
|
|
} else
|
|
|
|
die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}');
|
|
|
|
} else {
|
|
|
|
// Open temp file
|
2011-06-06 16:18:03 +02:00
|
|
|
$out = fopen($p_targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab");
|
2011-03-25 04:07:13 +01:00
|
|
|
if ($out) {
|
|
|
|
// Read binary input stream and append it to temp file
|
|
|
|
$in = fopen("php://input", "rb");
|
|
|
|
|
|
|
|
if ($in) {
|
|
|
|
while ($buff = fread($in, 4096))
|
|
|
|
fwrite($out, $buff);
|
|
|
|
} else
|
|
|
|
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
|
|
|
|
|
|
|
|
fclose($out);
|
|
|
|
} else
|
|
|
|
die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
|
|
|
|
}
|
|
|
|
|
2011-06-06 16:18:03 +02:00
|
|
|
$audio_file = $p_targetDir . DIRECTORY_SEPARATOR . $fileName;
|
2011-03-25 04:07:13 +01:00
|
|
|
|
|
|
|
$md5 = md5_file($audio_file);
|
|
|
|
$duplicate = StoredFile::RecallByMd5($md5);
|
|
|
|
if ($duplicate) {
|
|
|
|
if (PEAR::isError($duplicate)) {
|
|
|
|
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": ' . $duplicate->getMessage() .'}}');
|
|
|
|
}
|
2011-06-23 17:51:38 +02:00
|
|
|
if (file_exists($duplicate->getFilePath())) {
|
2011-07-15 23:35:16 +02:00
|
|
|
$duplicateName = $duplicate->getMetadataValue('MDATA_KEY_TITLE');
|
2011-06-23 17:51:38 +02:00
|
|
|
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "An identical audioclip named ' . $duplicateName . ' already exists in the storage server."}}');
|
|
|
|
}
|
2011-03-25 04:07:13 +01:00
|
|
|
}
|
2011-06-14 12:07:21 +02:00
|
|
|
|
2011-06-23 17:33:05 +02:00
|
|
|
$storDir = MusicDir::getStorDir();
|
|
|
|
$stor = $storDir->getDirectory();
|
2011-06-21 10:24:02 +02:00
|
|
|
|
2011-07-06 19:54:52 +02:00
|
|
|
$stor .= "/organize";
|
2011-07-18 15:28:17 +02:00
|
|
|
|
2011-06-23 17:33:05 +02:00
|
|
|
$audio_stor = $stor . DIRECTORY_SEPARATOR . $fileName;
|
2011-06-14 12:07:21 +02:00
|
|
|
|
2011-06-23 17:33:05 +02:00
|
|
|
$r = @copy($audio_file, $audio_stor);
|
2011-03-25 04:07:13 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-07-04 23:37:05 +02:00
|
|
|
public static function listAllFiles($dir_id){
|
2011-07-04 23:59:02 +02:00
|
|
|
global $CC_DBC;
|
2011-07-04 20:29:09 +02:00
|
|
|
|
2011-07-07 23:41:08 +02:00
|
|
|
// $sql = "SELECT m.directory || '/' || f.filepath as fp"
|
|
|
|
// ." FROM CC_MUSIC_DIRS m"
|
|
|
|
// ." LEFT JOIN CC_FILES f"
|
|
|
|
// ." ON m.id = f.directory"
|
|
|
|
// ." WHERE m.id = f.directory"
|
|
|
|
// ." AND m.id = $dir_id";
|
|
|
|
$sql = "SELECT filepath as fp"
|
|
|
|
." FROM CC_FILES"
|
2011-07-18 15:28:17 +02:00
|
|
|
." WHERE directory = $dir_id";
|
|
|
|
|
2011-07-04 20:29:09 +02:00
|
|
|
$rows = $CC_DBC->getAll($sql);
|
|
|
|
|
|
|
|
$results = array();
|
|
|
|
foreach ($rows as $row){
|
|
|
|
$results[] = $row["fp"];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
}
|
2010-12-07 23:29:28 +01:00
|
|
|
}
|
2011-02-22 18:22:31 +01:00
|
|
|
|