#857 Thanks - fixed handling empty elements.

This commit is contained in:
tomas 2005-04-22 21:34:48 +00:00
parent 366d29a86e
commit ba93af0d0c
3 changed files with 25 additions and 13 deletions

View file

@ -23,7 +23,7 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.38 $ Version : $Revision: 1.39 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/LocStor.php,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/LocStor.php,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -555,7 +555,7 @@ class LocStor extends BasicStor{
if(PEAR::isError($playlistId)){ return $playlistId; } if(PEAR::isError($playlistId)){ return $playlistId; }
$ac =& StoredFile::recallByGunid($this, $playlistId); $ac =& StoredFile::recallByGunid($this, $playlistId);
if(PEAR::isError($ac)){ return $ac; } if(PEAR::isError($ac)){ return $ac; }
$res = $ac->replaceMetaData($newPlaylist, 'string'); $res = $ac->replaceMetaData($newPlaylist, 'string', 'playlist');
if(PEAR::isError($res)){ return $res; } if(PEAR::isError($res)){ return $res; }
$r = $this->_setEditFlag($playlistId, FALSE, $sessid); $r = $this->_setEditFlag($playlistId, FALSE, $sessid);
if(PEAR::isError($r)){ return $r; } if(PEAR::isError($r)){ return $r; }

View file

@ -23,12 +23,12 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.30 $ Version : $Revision: 1.31 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/MetaData.php,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/MetaData.php,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
define('DEBUG', FALSE); define('DEBUG', FALSE);
#define('DEBUG', TRUE); //define('DEBUG', TRUE);
define('MODIFY_LAST_MATCH', TRUE); define('MODIFY_LAST_MATCH', TRUE);
require_once "XML/Util.php"; require_once "XML/Util.php";
@ -122,15 +122,18 @@ class MetaData{
* *
* @param mdata string, local path to metadata XML file or XML string * @param mdata string, local path to metadata XML file or XML string
* @param loc string 'file'|'string' * @param loc string 'file'|'string'
* @param format string, metadata format for validation
* ('audioclip' | 'playlist' | 'webstream' | NULL)
* (NULL = no validation)
* @return true or PEAR::error * @return true or PEAR::error
*/ */
function replace($mdata, $loc='file') function replace($mdata, $loc='file', $format=NULL)
{ {
if($this->exists){ if($this->exists){
$res = $this->delete(); $res = $this->delete();
if(PEAR::isError($res)) return $res; if(PEAR::isError($res)) return $res;
} }
return $this->insert($mdata, $loc); return $this->insert($mdata, $loc, $format);
} }
/** /**
@ -205,7 +208,11 @@ class MetaData{
$transTbl = get_html_translation_table(); $transTbl = get_html_translation_table();
$transTbl = array_flip($transTbl); $transTbl = array_flip($transTbl);
foreach($all as $i=>$v){ foreach($all as $i=>$v){
$all[$i]['value']=strtr($all[$i]['value'], $transTbl); if(!is_null($all[$i]['value'])){
$all[$i]['value'] = strtr($all[$i]['value'], $transTbl);
}else{
$all[$i]['value'] = '';
}
} }
if(PEAR::isError($all)) return $all; if(PEAR::isError($all)) return $all;
return $all; return $all;
@ -246,7 +253,7 @@ class MetaData{
if(!is_null($value)){ if(!is_null($value)){
$sql = " $sql = "
UPDATE {$this->mdataTable} UPDATE {$this->mdataTable}
SET object='$value' SET object='$value', objns='_L'
WHERE id={$mid} WHERE id={$mid}
"; ";
$res = $this->dbc->query($sql); $res = $this->dbc->query($sql);
@ -587,7 +594,7 @@ class MetaData{
$object = $node->content; $object = $node->content;
if(is_null($object) || $object == ''){ if(is_null($object) || $object == ''){
$objns = '_blank'; $objns = '_blank';
$object = 'NULL'; $object = NULL;
}else $objns = '_L'; }else $objns = '_L';
$id = $this->storeRecord($subjns, $subject, $id = $this->storeRecord($subjns, $subject,
$node->ns, $node->name, 'T', $objns, $object); $node->ns, $node->name, 'T', $objns, $object);
@ -620,8 +627,10 @@ class MetaData{
*/ */
function updateRecord($mdid, $object, $objns='_L') function updateRecord($mdid, $object, $objns='_L')
{ {
$objns_sql = (is_null($objns) ? "NULL" : "'$objns'" );
$object_sql = (is_null($object)? "NULL" : "'$object'");
$res = $this->dbc->query("UPDATE {$this->mdataTable} $res = $this->dbc->query("UPDATE {$this->mdataTable}
SET objns = '$objns', object = '$object' SET objns = $objns_sql, object = $object_sql
WHERE gunid = x'{$this->gunid}'::bigint AND id='$mdid' WHERE gunid = x'{$this->gunid}'::bigint AND id='$mdid'
"); ");
if(PEAR::isError($res)) return $res; if(PEAR::isError($res)) return $res;

View file

@ -23,7 +23,7 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.25 $ Version : $Revision: 1.26 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/StoredFile.php,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/StoredFile.php,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -329,12 +329,15 @@ class StoredFile{
* *
* @param metadata string, local path to metadata XML file or XML string * @param metadata string, local path to metadata XML file or XML string
* @param mdataLoc string 'file'|'string' * @param mdataLoc string 'file'|'string'
* @param format string, metadata format for validation
* ('audioclip' | 'playlist' | 'webstream' | NULL)
* (NULL = no validation)
* @return boolean * @return boolean
*/ */
function replaceMetaData($metadata, $mdataLoc='file') function replaceMetaData($metadata, $mdataLoc='file', $format=NULL)
{ {
$this->dbc->query("BEGIN"); $this->dbc->query("BEGIN");
$res = $this->md->replace($metadata, $mdataLoc); $res = $this->md->replace($metadata, $mdataLoc, $format);
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; } if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
$res = $this->dbc->query("COMMIT"); $res = $this->dbc->query("COMMIT");
if(PEAR::isError($res)) return $res; if(PEAR::isError($res)) return $res;