Merge branch 'master' of dev.sourcefabric.org:campcaster
This commit is contained in:
commit
a3e8e41f33
|
@ -200,15 +200,6 @@ function camp_import_audio_file($p_filepath, $p_importMode = null, $p_testOnly =
|
||||||
|
|
||||||
echo "Importing: [".sprintf("%05d",$g_fileCount+1)."] $p_filepath\n";
|
echo "Importing: [".sprintf("%05d",$g_fileCount+1)."] $p_filepath\n";
|
||||||
|
|
||||||
$metadata = camp_get_audio_metadata($p_filepath, $p_testOnly);
|
|
||||||
if (PEAR::isError($metadata)) {
|
|
||||||
import_err($metadata);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// bsSetMetadataBatch doesnt like these values
|
|
||||||
unset($metadata['audio']);
|
|
||||||
unset($metadata['playtime_seconds']);
|
|
||||||
|
|
||||||
if (!$p_testOnly) {
|
if (!$p_testOnly) {
|
||||||
if ($p_importMode == "copy") {
|
if ($p_importMode == "copy") {
|
||||||
$doCopyFiles = true;
|
$doCopyFiles = true;
|
||||||
|
@ -216,36 +207,15 @@ function camp_import_audio_file($p_filepath, $p_importMode = null, $p_testOnly =
|
||||||
$doCopyFiles = false;
|
$doCopyFiles = false;
|
||||||
}
|
}
|
||||||
$values = array(
|
$values = array(
|
||||||
"filename" => $metadata['ls:filename'],
|
|
||||||
"filepath" => $p_filepath,
|
"filepath" => $p_filepath,
|
||||||
"metadata" => "$STORAGE_SERVER_PATH/var/emptyMdata.xml",
|
|
||||||
"gunid" => NULL,
|
|
||||||
"filetype" => "audioclip",
|
|
||||||
"md5" => $md5sum,
|
"md5" => $md5sum,
|
||||||
"mime" => $metadata['dc:format']
|
|
||||||
);
|
);
|
||||||
// $timeBegin = microtime(true);
|
|
||||||
$storedFile = $greenbox->bsPutFile($values, $doCopyFiles);
|
$storedFile = $greenbox->bsPutFile($values, $doCopyFiles);
|
||||||
if (PEAR::isError($storedFile)) {
|
if (PEAR::isError($storedFile)) {
|
||||||
import_err($storedFile, "Error in bsPutFile()");
|
import_err($storedFile, "Error in bsPutFile()");
|
||||||
echo var_export($metadata)."\n";
|
echo var_export($metadata)."\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$id = $storedFile->getId();
|
|
||||||
// $timeEnd = microtime(true);
|
|
||||||
// echo " * Store file time: ".($timeEnd-$timeBegin)."\n";
|
|
||||||
|
|
||||||
// Note: the bsSetMetadataBatch() takes up .25 of a second
|
|
||||||
// on my 3Ghz computer. We should try to speed this up.
|
|
||||||
// $timeBegin = microtime(true);
|
|
||||||
$r = $greenbox->bsSetMetadataBatch($id, $metadata);
|
|
||||||
if (PEAR::isError($r)) {
|
|
||||||
import_err($r, "Error in bsSetMetadataBatch()");
|
|
||||||
echo var_export($metadata)."\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// $timeEnd = microtime(true);
|
|
||||||
// echo " * Metadata store time: ".($timeEnd-$timeBegin)."\n";
|
|
||||||
} else {
|
} else {
|
||||||
echo "==========================================================================\n";
|
echo "==========================================================================\n";
|
||||||
echo "METADATA\n";
|
echo "METADATA\n";
|
||||||
|
|
|
@ -101,34 +101,16 @@ class BasicStor {
|
||||||
/**
|
/**
|
||||||
* Store new file in the storage
|
* Store new file in the storage
|
||||||
*
|
*
|
||||||
* @param int $p_parentId
|
|
||||||
* Parent id
|
|
||||||
* @param array $p_values
|
* @param array $p_values
|
||||||
* See StoredFile::Insert() for details.
|
* See StoredFile::Insert() for details.
|
||||||
* @param boolean $copyMedia
|
* @param boolean $copyMedia
|
||||||
* copy the media file if true, make symlink if false
|
* copy the media file if true, make symlink if false
|
||||||
* @return int|PEAR_Error
|
* @return StoredFile|PEAR_Error
|
||||||
* ID of the StoredFile that was created.
|
* The StoredFile that was created.
|
||||||
*/
|
*/
|
||||||
public function bsPutFile($p_values, $p_copyMedia=TRUE)
|
public function bsPutFile($p_values, $p_copyMedia=TRUE)
|
||||||
{
|
{
|
||||||
if (!isset($p_values['filetype']) || !isset($p_values['filename'])) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
$ftype = strtolower($p_values['filetype']);
|
|
||||||
$storedFile = StoredFile::Insert($p_values, $p_copyMedia);
|
$storedFile = StoredFile::Insert($p_values, $p_copyMedia);
|
||||||
if (PEAR::isError($storedFile)) {
|
|
||||||
$res = BasicStor::RemoveObj($id);
|
|
||||||
// catch constraint violations
|
|
||||||
switch ($storedFile->getCode()) {
|
|
||||||
case -3:
|
|
||||||
return PEAR::raiseError(
|
|
||||||
"BasicStor::bsPutFile: gunid duplication",
|
|
||||||
GBERR_GUNID);
|
|
||||||
default:
|
|
||||||
return $storedFile;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $storedFile;
|
return $storedFile;
|
||||||
} // fn bsPutFile
|
} // fn bsPutFile
|
||||||
|
|
||||||
|
@ -857,55 +839,34 @@ class BasicStor {
|
||||||
* Metadata element identification (e.g. dc:title)
|
* Metadata element identification (e.g. dc:title)
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* value to store, if NULL then delete record
|
* value to store, if NULL then delete record
|
||||||
* @param string $lang
|
|
||||||
* xml:lang value for select language version
|
|
||||||
* @param int $mid
|
|
||||||
* (optional on unique elements) metadata record id
|
|
||||||
* @param string $container
|
|
||||||
* container element name for insert
|
|
||||||
* @param boolean $regen
|
|
||||||
* flag, if true, regenerate XML file
|
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static function bsSetMetadataValue($p_id, $p_category, $p_value)/*,
|
public static function bsSetMetadataValue($p_id, $p_category, $p_value)
|
||||||
$lang=NULL, $mid=NULL, $container='metadata', $regen=TRUE)*/
|
|
||||||
{
|
{
|
||||||
global $CC_CONFIG, $CC_DBC;
|
global $CC_CONFIG, $CC_DBC;
|
||||||
if (!is_string($p_category) || is_array($p_value)) {
|
if (!is_string($p_category) || is_array($p_value)) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (is_a($p_id, "StoredFile")) {
|
if (is_a($p_id, "StoredFile")) {
|
||||||
$storedFile =& $p_id;
|
$p_id = $p_id->getId();
|
||||||
} else {
|
}
|
||||||
$storedFile = StoredFile::Recall($p_id);
|
if ($p_category == 'dcterms:extent') {
|
||||||
if (is_null($storedFile) || PEAR::isError($storedFile)) {
|
$p_value = BasicStor::NormalizeExtent($p_value);
|
||||||
return $storedFile;
|
}
|
||||||
}
|
$columnName = BasicStor::xmlCategoryToDbColumn($p_category); // Get column name
|
||||||
}
|
|
||||||
if ($p_category == 'dcterms:extent') {
|
|
||||||
$p_value = BasicStor::NormalizeExtent($p_value);
|
|
||||||
}
|
|
||||||
$columnName = BasicStor::xmlCategoryToDbColumn($p_category); // Get column name
|
|
||||||
|
|
||||||
if (!is_null($columnName)) {
|
if (!is_null($columnName)) {
|
||||||
$escapedValue = pg_escape_string($p_value);
|
$escapedValue = pg_escape_string($p_value);
|
||||||
$sql = "UPDATE ".$CC_CONFIG["filesTable"]
|
$sql = "UPDATE ".$CC_CONFIG["filesTable"]
|
||||||
." SET $columnName='$escapedValue'"
|
." SET $columnName='$escapedValue'"
|
||||||
." WHERE id=".$storedFile->getId();
|
." WHERE id=$p_id";
|
||||||
//var_dump($sql);
|
//var_dump($sql);
|
||||||
//$res = $storedFile->md->setMetadataValue($category, $value, $lang, $mid, $container);
|
$res = $CC_DBC->query($sql);
|
||||||
$res = $CC_DBC->query($sql);
|
if (PEAR::isError($res)) {
|
||||||
if (PEAR::isError($res)) {
|
return $res;
|
||||||
return $res;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// if ($regen) {
|
}
|
||||||
// $r = $storedFile->md->regenerateXmlFile();
|
return TRUE;
|
||||||
// if (PEAR::isError($r)) {
|
|
||||||
// return $r;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return $res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -936,46 +897,37 @@ class BasicStor {
|
||||||
* @param array $values
|
* @param array $values
|
||||||
* array of key/value pairs
|
* array of key/value pairs
|
||||||
* (e.g. 'dc:title'=>'New title')
|
* (e.g. 'dc:title'=>'New title')
|
||||||
* @param string $lang
|
|
||||||
* xml:lang value for select language version
|
|
||||||
* @param string $container
|
|
||||||
* Container element name for insert
|
|
||||||
* @param boolean $regen
|
|
||||||
* flag, if true, regenerate XML file
|
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static function bsSetMetadataBatch(
|
public static function bsSetMetadataBatch($id, $values)
|
||||||
$id, $values, $lang=NULL, $container='metadata', $regen=TRUE)
|
|
||||||
{
|
{
|
||||||
if (!is_array($values)) {
|
global $CC_CONFIG, $CC_DBC;
|
||||||
$values = array($values);
|
if (!is_array($values)) {
|
||||||
|
$values = array($values);
|
||||||
|
}
|
||||||
|
if (is_a($id, "StoredFile")) {
|
||||||
|
$storedFile =& $id;
|
||||||
|
} else {
|
||||||
|
$storedFile = StoredFile::Recall($id);
|
||||||
|
if (is_null($storedFile) || PEAR::isError($storedFile)) {
|
||||||
|
return $storedFile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($values as $category => $oneValue) {
|
||||||
|
$columnName = BasicStor::xmlCategoryToDbColumn($category);
|
||||||
|
if (!is_null($columnName)) {
|
||||||
|
if ($category == 'dcterms:extent') {
|
||||||
|
$oneValue = BasicStor::NormalizeExtent($oneValue);
|
||||||
|
}
|
||||||
|
$escapedValue = pg_escape_string($oneValue);
|
||||||
|
$sqlValues[] = "$columnName = '$escapedValue'";
|
||||||
}
|
}
|
||||||
if (is_a($id, "StoredFile")) {
|
}
|
||||||
$storedFile =& $id;
|
$sql = "UPDATE ".$CC_CONFIG["filesTable"]
|
||||||
} else {
|
." SET ".join(",", $sqlValues)
|
||||||
$storedFile = StoredFile::Recall($id);
|
." WHERE id=$id";
|
||||||
if (is_null($storedFile) || PEAR::isError($storedFile)) {
|
$CC_DBC->query($sql);
|
||||||
return $storedFile;
|
return TRUE;
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach ($values as $category => $oneValue) {
|
|
||||||
$res = BasicStor::bsSetMetadataValue($storedFile, $category,
|
|
||||||
$oneValue/*, $lang, NULL, $container, FALSE*/);
|
|
||||||
if (PEAR::isError($res)) {
|
|
||||||
return $res;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// if ($regen) {
|
|
||||||
// $storedFile = StoredFile::Recall($id);
|
|
||||||
// if (is_null($storedFile) || PEAR::isError($storedFile)) {
|
|
||||||
// return $storedFile;
|
|
||||||
// }
|
|
||||||
// $r = $storedFile->md->regenerateXmlFile();
|
|
||||||
// if (PEAR::isError($r)) {
|
|
||||||
// return $r;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1869,7 +1821,7 @@ class BasicStor {
|
||||||
$res = preg_match("|^([0-9a-fA-F]{16})?$|", $p_gunid);
|
$res = preg_match("|^([0-9a-fA-F]{16})?$|", $p_gunid);
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set playlist edit flag
|
* Set playlist edit flag
|
||||||
*
|
*
|
||||||
|
|
|
@ -44,13 +44,14 @@ class ScheduleItem {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Add a music clip or playlist to the schedule.
|
||||||
*
|
*
|
||||||
* @param $p_audioFileId
|
* @param $p_audioFileId
|
||||||
* @param $p_playlistId
|
* @param $p_playlistId
|
||||||
* @param $p_datetime
|
* @param $p_datetime
|
||||||
* @param $p_options
|
* @param $p_options
|
||||||
* @return int|null
|
* @return int|PEAR_Error
|
||||||
* Return null if the item could not be added.
|
* Return PEAR_Error if the item could not be added.
|
||||||
*/
|
*/
|
||||||
public function add($p_datetime, $p_audioFileId = null, $p_playlistId = null, $p_options = null) {
|
public function add($p_datetime, $p_audioFileId = null, $p_playlistId = null, $p_options = null) {
|
||||||
global $CC_CONFIG, $CC_DBC;
|
global $CC_CONFIG, $CC_DBC;
|
||||||
|
@ -60,14 +61,17 @@ class ScheduleItem {
|
||||||
// Load existing track
|
// Load existing track
|
||||||
$track = StoredFile::Recall($p_audioFileId);
|
$track = StoredFile::Recall($p_audioFileId);
|
||||||
if (is_null($track)) {
|
if (is_null($track)) {
|
||||||
return null;
|
return new PEAR_Error("Could not find audio track.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if there are any conflicts with existing entries
|
// Check if there are any conflicts with existing entries
|
||||||
$metadata = $track->getMetadata();
|
$metadata = $track->getMetadata();
|
||||||
$length = trim($metadata["length"]);
|
$length = trim($metadata["length"]);
|
||||||
|
if (empty($length)) {
|
||||||
|
return new PEAR_Error("Length is empty.");
|
||||||
|
}
|
||||||
if (!Schedule::isScheduleEmptyInRange($p_datetime, $length)) {
|
if (!Schedule::isScheduleEmptyInRange($p_datetime, $length)) {
|
||||||
return null;
|
return new PEAR_Error("Schedule conflict.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert into the table
|
// Insert into the table
|
||||||
|
@ -78,7 +82,11 @@ class ScheduleItem {
|
||||||
." VALUES ($id, 0, TIMESTAMP '$p_datetime', "
|
." VALUES ($id, 0, TIMESTAMP '$p_datetime', "
|
||||||
." (TIMESTAMP '$p_datetime' + INTERVAL '$length'),"
|
." (TIMESTAMP '$p_datetime' + INTERVAL '$length'),"
|
||||||
." {$this->groupId}, $p_audioFileId)";
|
." {$this->groupId}, $p_audioFileId)";
|
||||||
$CC_DBC->query($sql);
|
$result = $CC_DBC->query($sql);
|
||||||
|
if (PEAR::isError($result)) {
|
||||||
|
var_dump($sql);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
return $this->groupId;
|
return $this->groupId;
|
||||||
|
|
||||||
} elseif (!is_null($p_playlistId)){
|
} elseif (!is_null($p_playlistId)){
|
||||||
|
@ -136,9 +144,14 @@ class Schedule {
|
||||||
*
|
*
|
||||||
* @param string $p_datetime
|
* @param string $p_datetime
|
||||||
* @param string $p_length
|
* @param string $p_length
|
||||||
|
*
|
||||||
|
* @return boolean|PEAR_Error
|
||||||
*/
|
*/
|
||||||
public static function isScheduleEmptyInRange($p_datetime, $p_length) {
|
public static function isScheduleEmptyInRange($p_datetime, $p_length) {
|
||||||
global $CC_CONFIG, $CC_DBC;
|
global $CC_CONFIG, $CC_DBC;
|
||||||
|
if (empty($p_length)) {
|
||||||
|
return new PEAR_Error("Schedule::isSchedulerEmptyInRange: param p_length is empty.");
|
||||||
|
}
|
||||||
$sql = "SELECT COUNT(*) FROM ".$CC_CONFIG["scheduleTable"]
|
$sql = "SELECT COUNT(*) FROM ".$CC_CONFIG["scheduleTable"]
|
||||||
." WHERE (starts <= '$p_datetime') "
|
." WHERE (starts <= '$p_datetime') "
|
||||||
." AND (ends >= (TIMESTAMP '$p_datetime' + INTERVAL '$p_length'))";
|
." AND (ends >= (TIMESTAMP '$p_datetime' + INTERVAL '$p_length'))";
|
||||||
|
|
|
@ -459,52 +459,70 @@ class StoredFile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ========= 'factory' methods - should be called to construct StoredFile */
|
/* ========= 'factory' methods - should be called to construct StoredFile */
|
||||||
/**
|
/**
|
||||||
* Create instance of StoredFile object and insert new file
|
* Create instance of StoredFile object and insert new file
|
||||||
*
|
*
|
||||||
* @param array $p_values
|
* @param array $p_values
|
||||||
* "id" - optional, local object id in the tree
|
* "filepath" - required, local path to media file
|
||||||
* "gunid" - optional, unique id, for insert file with gunid
|
* "id" - optional, local object id, will be generated if not given
|
||||||
* "filename" - optional
|
* "gunid" - optional, unique id, for insert file with gunid, will be generated if not given
|
||||||
* "filepath" - local path to media file, not needed for Playlist
|
* "filename" - optional, will use "filepath" if not given
|
||||||
* "metadata" - local path to metadata XML file or XML string
|
* "metadata" - optional, array of extra metadata, will be automatically calculated if not given.
|
||||||
* "filetype" - internal file type
|
* "mime" - optional, MIME type, highly recommended to pass in, will be automatically calculated if not given.
|
||||||
* "mime" - MIME type, highly recommended to pass in
|
* "md5" - optional, MD5 sum, highly recommended to pass in, will be automatically calculated if not given.
|
||||||
* "md5" - MD5 sum, highly recommended to pass in
|
*
|
||||||
* @param boolean $p_copyMedia
|
* @param boolean $p_copyMedia
|
||||||
* copy the media file if true, make symlink if false
|
* copy the media file if true, make symlink if false
|
||||||
|
*
|
||||||
* @return StoredFile|NULL|PEAR_Error
|
* @return StoredFile|NULL|PEAR_Error
|
||||||
*/
|
*/
|
||||||
public static function Insert($p_values, $p_copyMedia=TRUE)
|
public static function Insert($p_values, $p_copyMedia=TRUE)
|
||||||
{
|
{
|
||||||
global $CC_CONFIG, $CC_DBC;
|
global $CC_CONFIG, $CC_DBC;
|
||||||
|
|
||||||
|
if (!isset($p_values["filepath"])) {
|
||||||
|
return new PEAR_Error("StoredFile::Insert: filepath not set.");
|
||||||
|
}
|
||||||
|
if (!file_exists($p_values['filepath'])) {
|
||||||
|
return PEAR::raiseError("StoredFile::Insert: ".
|
||||||
|
"media file not found ({$p_values['filepath']})");
|
||||||
|
}
|
||||||
|
|
||||||
$gunid = isset($p_values['gunid'])?$p_values['gunid']:NULL;
|
$gunid = isset($p_values['gunid'])?$p_values['gunid']:NULL;
|
||||||
|
|
||||||
// Create the StoredFile object
|
// Create the StoredFile object
|
||||||
$storedFile = new StoredFile($gunid);
|
$storedFile = new StoredFile($gunid);
|
||||||
$storedFile->name = isset($p_values['filename']) ? $p_values['filename'] : $storedFile->gunid;
|
|
||||||
|
// Get metadata
|
||||||
|
if (isset($p_values["metadata"])) {
|
||||||
|
$metadata = $p_values['metadata'];
|
||||||
|
} else {
|
||||||
|
$metadata = camp_get_audio_metadata($p_values["filepath"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$storedFile->name = isset($p_values['filename']) ? $p_values['filename'] : $p_values["filepath"];
|
||||||
// NOTE: POSTGRES-SPECIFIC KEYWORD "DEFAULT" BEING USED, WOULD BE "NULL" IN MYSQL
|
// NOTE: POSTGRES-SPECIFIC KEYWORD "DEFAULT" BEING USED, WOULD BE "NULL" IN MYSQL
|
||||||
$storedFile->id = isset($p_values['id']) && is_integer($p_values['id'])?"'".$p_values['id']."'":'DEFAULT';
|
$storedFile->id = isset($p_values['id']) && is_integer($p_values['id'])?"'".$p_values['id']."'":'DEFAULT';
|
||||||
$storedFile->ftype = $p_values['filetype'];
|
$storedFile->ftype = isset($p_values['filetype']) ? strtolower($p_values['filetype']) : "audioclip";
|
||||||
if ($storedFile->ftype == 'playlist') {
|
$storedFile->mime = (isset($p_values["mime"]) ? $p_values["mime"] : NULL );
|
||||||
$storedFile->mime = 'application/smil';
|
// $storedFile->filepath = $p_values['filepath'];
|
||||||
} else {
|
|
||||||
$storedFile->mime = (isset($p_values["mime"]) ? $p_values["mime"] : NULL );
|
|
||||||
}
|
|
||||||
# $storedFile->filepath = $p_values['filepath'];
|
|
||||||
if (isset($p_values['md5'])) {
|
if (isset($p_values['md5'])) {
|
||||||
$storedFile->md5 = $p_values['md5'];
|
$storedFile->md5 = $p_values['md5'];
|
||||||
} elseif (file_exists($p_values['filepath'])) {
|
} elseif (file_exists($p_values['filepath'])) {
|
||||||
# echo "StoredFile::Insert: WARNING: Having to recalculate MD5 value\n";
|
//echo "StoredFile::Insert: WARNING: Having to recalculate MD5 value\n";
|
||||||
$storedFile->md5 = md5_file($p_values['filepath']);
|
$storedFile->md5 = md5_file($p_values['filepath']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for duplicates -- return duplicate
|
||||||
|
$duplicate = StoredFile::RecallByMd5($storedFile->md5);
|
||||||
|
if ($duplicate) {
|
||||||
|
return $duplicate;
|
||||||
|
}
|
||||||
|
|
||||||
$storedFile->exists = FALSE;
|
$storedFile->exists = FALSE;
|
||||||
$emptyState = TRUE;
|
|
||||||
|
|
||||||
// Insert record into the database
|
// Insert record into the database
|
||||||
$escapedName = pg_escape_string($storedFile->name);
|
$escapedName = pg_escape_string($storedFile->name);
|
||||||
|
@ -528,52 +546,22 @@ class StoredFile {
|
||||||
$sql = "SELECT currval('".$CC_CONFIG["filesSequence"]."_seq')";
|
$sql = "SELECT currval('".$CC_CONFIG["filesSequence"]."_seq')";
|
||||||
$storedFile->id = $CC_DBC->getOne($sql);
|
$storedFile->id = $CC_DBC->getOne($sql);
|
||||||
}
|
}
|
||||||
// Insert metadata
|
|
||||||
$metadata = $p_values['metadata'];
|
|
||||||
BasicStor::bsSetMetadataBatch($storedFile->id, $metadata);
|
BasicStor::bsSetMetadataBatch($storedFile->id, $metadata);
|
||||||
|
|
||||||
// $mdataLoc = ($metadata[0]=="/")? "file":"string";
|
|
||||||
// for non-absolute paths:
|
|
||||||
// $mdataLoc = ($metadata[0]!="<")? "file":"string";
|
|
||||||
// if (is_null($metadata) || ($metadata == '') ) {
|
|
||||||
// $metadata = dirname(__FILE__).'/emptyMdata.xml';
|
|
||||||
// $mdataLoc = 'file';
|
|
||||||
// } else {
|
|
||||||
// $emptyState = FALSE;
|
|
||||||
// }
|
|
||||||
// if ( ($mdataLoc == 'file') && !file_exists($metadata)) {
|
|
||||||
// return PEAR::raiseError("StoredFile::Insert: ".
|
|
||||||
// "metadata file not found ($metadata)");
|
|
||||||
// }
|
|
||||||
// $res = $storedFile->md->insert($metadata, $mdataLoc, $storedFile->ftype);
|
|
||||||
// if (PEAR::isError($res)) {
|
|
||||||
// $CC_DBC->query("ROLLBACK");
|
|
||||||
// return $res;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Save media file
|
// Save media file
|
||||||
if (!empty($p_values['filepath'])) {
|
$res = $storedFile->addFile($p_values['filepath'], $p_copyMedia);
|
||||||
if (!file_exists($p_values['filepath'])) {
|
if (PEAR::isError($res)) {
|
||||||
return PEAR::raiseError("StoredFile::Insert: ".
|
echo "StoredFile::Insert: ERROR adding file: '".$res->getMessage()."'\n";
|
||||||
"media file not found ({$p_values['filepath']})");
|
$CC_DBC->query("ROLLBACK");
|
||||||
}
|
return $res;
|
||||||
$res = $storedFile->addFile($p_values['filepath'], $p_copyMedia);
|
}
|
||||||
if (PEAR::isError($res)) {
|
if (empty($storedFile->mime)) {
|
||||||
echo "StoredFile::Insert: ERROR adding file: '".$res->getMessage()."'\n";
|
//echo "StoredFile::Insert: WARNING: Having to recalculate MIME value\n";
|
||||||
$CC_DBC->query("ROLLBACK");
|
$storedFile->setMime($storedFile->getMime());
|
||||||
return $res;
|
|
||||||
}
|
|
||||||
if (empty($storedFile->mime)) {
|
|
||||||
# echo "StoredFile::Insert: WARNING: Having to recalculate MIME value\n";
|
|
||||||
$storedFile->setMime($storedFile->getMime());
|
|
||||||
}
|
|
||||||
$emptyState = FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save state
|
// Save state
|
||||||
if (!$emptyState) {
|
$storedFile->setState('ready');
|
||||||
$res = $storedFile->setState('ready');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Commit changes
|
// Commit changes
|
||||||
$res = $CC_DBC->query("COMMIT");
|
$res = $CC_DBC->query("COMMIT");
|
||||||
|
@ -1160,7 +1148,7 @@ class StoredFile {
|
||||||
* Returns gunIds of the playlists the stored file is in.
|
* Returns gunIds of the playlists the stored file is in.
|
||||||
* TODO update this to work with new tables.
|
* TODO update this to work with new tables.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
public function getPlaylists() {
|
public function getPlaylists() {
|
||||||
global $CC_CONFIG, $CC_DBC;
|
global $CC_CONFIG, $CC_DBC;
|
||||||
|
@ -1176,7 +1164,7 @@ class StoredFile {
|
||||||
|
|
||||||
return $playlists;
|
return $playlists;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,11 +4,11 @@ require_once('DB.php');
|
||||||
require_once('PHPUnit.php');
|
require_once('PHPUnit.php');
|
||||||
require_once 'BasicStorTests.php';
|
require_once 'BasicStorTests.php';
|
||||||
require_once 'SchedulerTests.php';
|
require_once 'SchedulerTests.php';
|
||||||
require_once 'PlayListTests.php';
|
//require_once 'PlayListTests.php';
|
||||||
|
|
||||||
$suite = new PHPUnit_TestSuite("BasicStorTest");
|
$suite = new PHPUnit_TestSuite("BasicStorTest");
|
||||||
$suite->addTestSuite("SchedulerTests");
|
$suite->addTestSuite("SchedulerTests");
|
||||||
$suite->addTestSuite("PlayListTests");
|
//$suite->addTestSuite("PlayListTests");
|
||||||
$result = PHPUnit::run($suite);
|
$result = PHPUnit::run($suite);
|
||||||
|
|
||||||
echo $result->toString();
|
echo $result->toString();
|
||||||
|
|
|
@ -42,41 +42,27 @@ class BasicStorTest extends PHPUnit_TestCase {
|
||||||
//$this->assertTrue(FALSE);
|
//$this->assertTrue(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testPutFile() {
|
function testDeleteAndPutFile() {
|
||||||
$STORAGE_SERVER_PATH = dirname(__FILE__)."/../../";
|
$STORAGE_SERVER_PATH = dirname(__FILE__)."/../../";
|
||||||
$filePath = dirname(__FILE__)."/ex1.mp3";
|
$filePath = dirname(__FILE__)."/ex1.mp3";
|
||||||
$md5sum = md5_file($filePath);
|
|
||||||
$metadata = camp_get_audio_metadata($filePath);
|
$md5 = md5_file($filePath);
|
||||||
if (PEAR::isError($metadata)) {
|
$duplicate = StoredFile::RecallByMd5($md5);
|
||||||
$this->fail($metadata->getMessage());
|
if ($duplicate) {
|
||||||
return;
|
$duplicate->delete();
|
||||||
}
|
}
|
||||||
// bsSetMetadataBatch doesnt like these values
|
|
||||||
unset($metadata['audio']);
|
$values = array("filepath" => $filePath);
|
||||||
unset($metadata['playtime_seconds']);
|
|
||||||
$values = array(
|
|
||||||
"filename" => $metadata['ls:filename'],
|
|
||||||
"filepath" => $filePath,
|
|
||||||
"metadata" => "$STORAGE_SERVER_PATH/var/emptyMdata.xml",
|
|
||||||
"gunid" => NULL,
|
|
||||||
"filetype" => "audioclip",
|
|
||||||
"md5" => $md5sum,
|
|
||||||
"mime" => $metadata['dc:format']
|
|
||||||
);
|
|
||||||
$storedFile = $this->greenbox->bsPutFile($values, false);
|
$storedFile = $this->greenbox->bsPutFile($values, false);
|
||||||
$this->assertFalse(PEAR::isError($storedFile));
|
if (PEAR::isError($storedFile)) {
|
||||||
|
$this->fail("Failed to create StoredFile: ".$storedFile->getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
$id = $storedFile->getId();
|
$id = $storedFile->getId();
|
||||||
if (!is_numeric($id)) {
|
if (!is_numeric($id)) {
|
||||||
$this->fail("StoredFile not created correctly. id = ".$id);
|
$this->fail("StoredFile not created correctly. id = ".$id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = $this->greenbox->bsSetMetadataBatch($storedFile, $metadata);
|
|
||||||
if (PEAR::isError($r)) {
|
|
||||||
$this->fail($r->getMessage());
|
|
||||||
//echo var_export($metadata)."\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,68 +3,80 @@ require_once(dirname(__FILE__)."/../Schedule.php");
|
||||||
|
|
||||||
class SchedulerTests extends PHPUnit_TestCase {
|
class SchedulerTests extends PHPUnit_TestCase {
|
||||||
|
|
||||||
private $groupIdCreated;
|
private $groupIdCreated;
|
||||||
private $storedFileId;
|
private $storedFile;
|
||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
$this->storedFileId = '192';
|
global $CC_CONFIG, $CC_DBC;
|
||||||
|
|
||||||
|
// Clear the files table
|
||||||
|
$sql = "DELETE FROM ".$CC_CONFIG["filesTable"];
|
||||||
|
$CC_DBC->query($sql);
|
||||||
|
|
||||||
|
// Add a file
|
||||||
|
$values = array("filepath" => dirname(__FILE__)."/test10001.mp3");
|
||||||
|
$this->storedFile = StoredFile::Insert($values, false);
|
||||||
|
|
||||||
|
// Clear the schedule table
|
||||||
|
$sql = "DELETE FROM ".$CC_CONFIG["scheduleTable"];
|
||||||
|
$CC_DBC->query($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testDateToId() {
|
||||||
|
$dateStr = "2006-04-02 10:20:08.123456";
|
||||||
|
$id = ScheduleItem::dateToId($dateStr);
|
||||||
|
$expected = "20060402102008123";
|
||||||
|
if ($id != $expected) {
|
||||||
|
$this->fail("Did not convert date to ID correctly #1: $id != $expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
function testDateToId() {
|
$dateStr = "2006-04-02 10:20:08";
|
||||||
$dateStr = "2006-04-02 10:20:08.123456";
|
$id = ScheduleItem::dateToId($dateStr);
|
||||||
$id = ScheduleItem::dateToId($dateStr);
|
$expected = "20060402102008000";
|
||||||
$expected = "20060402102008123";
|
if ($id != $expected) {
|
||||||
if ($id != $expected) {
|
$this->fail("Did not convert date to ID correctly #2: $id != $expected");
|
||||||
$this->fail("Did not convert date to ID correctly #1: $id != $expected");
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$dateStr = "2006-04-02 10:20:08";
|
function testAddAndRemove() {
|
||||||
$id = ScheduleItem::dateToId($dateStr);
|
$i = new ScheduleItem();
|
||||||
$expected = "20060402102008000";
|
$this->groupIdCreated = $i->add('2010-10-10 01:30:23', $this->storedFile->getId());
|
||||||
if ($id != $expected) {
|
if (PEAR::isError($this->groupIdCreated)) {
|
||||||
$this->fail("Did not convert date to ID correctly #2: $id != $expected");
|
$this->fail("Failed to create scheduled item: ". $this->groupIdCreated->getMessage());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testAddAndRemove() {
|
$i = new ScheduleItem($this->groupIdCreated);
|
||||||
$i = new ScheduleItem();
|
$result = $i->remove();
|
||||||
$this->groupIdCreated = $i->add('2010-10-10 01:30:23', $this->storedFileId);
|
if ($result != 1) {
|
||||||
if (!is_numeric($this->groupIdCreated)) {
|
$this->fail("Did not remove item.");
|
||||||
$this->fail("Failed to create scheduled item.");
|
|
||||||
}
|
|
||||||
|
|
||||||
$i = new ScheduleItem($this->groupIdCreated);
|
|
||||||
$result = $i->remove();
|
|
||||||
if ($result != 1) {
|
|
||||||
$this->fail("Did not remove item.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function testIsScheduleEmptyInRange() {
|
function testIsScheduleEmptyInRange() {
|
||||||
$i = new ScheduleItem();
|
$i = new ScheduleItem();
|
||||||
$this->groupIdCreated = $i->add('2011-10-10 01:30:23', $this->storedFileId);
|
$this->groupIdCreated = $i->add('2011-10-10 01:30:23', $this->storedFile->getId());
|
||||||
if (Schedule::isScheduleEmptyInRange('2011-10-10 01:30:23', '00:00:01.432153')) {
|
if (Schedule::isScheduleEmptyInRange('2011-10-10 01:30:23', '00:00:01.432153')) {
|
||||||
$this->fail("Reporting empty schedule when it isnt.");
|
$this->fail("Reporting empty schedule when it isnt.");
|
||||||
}
|
|
||||||
$i->remove();
|
|
||||||
if (!Schedule::isScheduleEmptyInRange('2011-10-10 01:30:23', '00:00:01.432153')) {
|
|
||||||
$this->fail("Reporting booked schedule when it isnt.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
$i->remove();
|
||||||
|
if (!Schedule::isScheduleEmptyInRange('2011-10-10 01:30:23', '00:00:01.432153')) {
|
||||||
|
$this->fail("Reporting booked schedule when it isnt.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function testGetItems() {
|
function testGetItems() {
|
||||||
$i1 = new ScheduleItem();
|
$i1 = new ScheduleItem();
|
||||||
$groupId1 = $i1->add('2008-01-01 12:00:00.000', $this->storedFileId);
|
$groupId1 = $i1->add('2008-01-01 12:00:00.000', $this->storedFile->getId());
|
||||||
$i2 = new ScheduleItem();
|
$i2 = new ScheduleItem();
|
||||||
$i2->addAfter($groupId1, $this->storedFileId);
|
$i2->addAfter($groupId1, $this->storedFile->getId());
|
||||||
$items = Schedule::GetItems("2008-01-01", "2008-01-02");
|
$items = Schedule::GetItems("2008-01-01", "2008-01-02");
|
||||||
if (count($items) != 2) {
|
if (count($items) != 2) {
|
||||||
$this->fail("Wrong number of items returned.");
|
$this->fail("Wrong number of items returned.");
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
$i1->remove();
|
|
||||||
$i2->remove();
|
|
||||||
}
|
}
|
||||||
|
$i1->remove();
|
||||||
|
$i2->remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
Binary file not shown.
Loading…
Reference in New Issue