2006-10-19 16:55:07 +02:00
|
|
|
<?php
|
2006-12-08 05:31:20 +01:00
|
|
|
require_once("BasicStor.php");
|
2006-10-19 16:55:07 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* LocStor class
|
|
|
|
*
|
|
|
|
* Local storage interface
|
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @author Tomas Hlava <th@red2head.com>
|
|
|
|
* @author Paul Baranowski <paul@paulbaranowski.org>
|
2006-10-19 16:55:07 +02:00
|
|
|
* @version $Revision$
|
|
|
|
* @package Campcaster
|
|
|
|
* @subpackage StorageServer
|
2006-11-14 20:09:20 +01:00
|
|
|
* @copyright 2006 MDLF, Inc.
|
|
|
|
* @license http://www.gnu.org/licenses/gpl.txt
|
|
|
|
* @link http://www.campware.org
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
|
|
|
class LocStor extends BasicStor {
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------- store */
|
|
|
|
|
|
|
|
/**
|
2007-01-11 20:24:45 +01:00
|
|
|
* Store or replace existing audio clip.
|
|
|
|
*
|
|
|
|
* Sending a file to the storage server is a 3 step process:
|
|
|
|
* 1) Call storeAudioClipOpen
|
|
|
|
* 2) Upload the file to the URL specified
|
|
|
|
* 3) Call storeAudioClipClose
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* session id
|
|
|
|
* @param string $gunid
|
|
|
|
* global unique id
|
|
|
|
* @param string $metadata
|
|
|
|
* metadata XML string
|
|
|
|
* @param string $fname
|
|
|
|
* human readable menmonic file name
|
|
|
|
* with extension corresponding to filetype
|
|
|
|
* @param string $chsum
|
|
|
|
* md5 checksum of media file
|
|
|
|
* @param string $ftype
|
|
|
|
* audioclip | playlist | webstream
|
|
|
|
* @return array
|
|
|
|
* {url:writable URL for HTTP PUT, token:access token}
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2007-01-09 22:11:45 +01:00
|
|
|
protected function storeAudioClipOpen($sessid, $gunid, $metadata,
|
|
|
|
$fname, $chsum, $ftype='audioclip')
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2007-01-09 22:11:45 +01:00
|
|
|
// Check the gunid format
|
2006-12-16 07:36:22 +01:00
|
|
|
if (!BasicStor::CheckGunid($gunid)) {
|
2006-10-19 16:55:07 +02:00
|
|
|
return PEAR::raiseError(
|
|
|
|
"LocStor::storeAudioClipOpen: Wrong gunid ($gunid)"
|
|
|
|
);
|
|
|
|
}
|
2007-01-09 22:11:45 +01:00
|
|
|
|
|
|
|
// Check if we already have this file.
|
2007-01-11 20:24:45 +01:00
|
|
|
$duplicate = StoredFile::RecallByMd5($chsum);
|
|
|
|
if (!empty($chsum) && $duplicate) {
|
2007-01-09 22:11:45 +01:00
|
|
|
return PEAR::raiseError(
|
|
|
|
"LocStor::storeAudioClipOpen: Duplicate file"
|
2007-01-11 20:24:45 +01:00
|
|
|
." - Matched MD5 ($chsum) against '".$duplicate->getName()."'",
|
2007-01-09 22:11:45 +01:00
|
|
|
888);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if specified gunid exists.
|
2007-01-11 20:24:45 +01:00
|
|
|
$storedFile =& StoredFile::RecallByGunid($gunid);
|
2007-01-24 04:04:56 +01:00
|
|
|
if (!is_null($storedFile) && !PEAR::isError($storedFile)) {
|
2006-10-19 16:55:07 +02:00
|
|
|
// gunid exists - do replace
|
2007-01-11 20:24:45 +01:00
|
|
|
$oid = $storedFile->getId();
|
2006-12-16 07:36:22 +01:00
|
|
|
if (($res = BasicStor::Authorize('write', $oid, $sessid)) !== TRUE) {
|
2006-10-19 16:55:07 +02:00
|
|
|
return $res;
|
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
if ($storedFile->isAccessed()) {
|
2006-10-19 16:55:07 +02:00
|
|
|
return PEAR::raiseError(
|
|
|
|
'LocStor::storeAudioClipOpen: is accessed'
|
|
|
|
);
|
|
|
|
}
|
2007-01-24 04:04:56 +01:00
|
|
|
$res = $storedFile->replace($oid, $storedFile->getName(), '', $metadata, 'string');
|
2006-10-19 16:55:07 +02:00
|
|
|
if (PEAR::isError($res)) {
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
} else {
|
2007-01-09 22:11:45 +01:00
|
|
|
// gunid doesn't exist - do insert:
|
|
|
|
$tmpFname = uniqid();
|
2006-10-19 16:55:07 +02:00
|
|
|
$parid = $this->_getHomeDirIdFromSess($sessid);
|
|
|
|
if (PEAR::isError($parid)) {
|
|
|
|
return $parid;
|
|
|
|
}
|
2006-12-16 07:36:22 +01:00
|
|
|
if (($res = BasicStor::Authorize('write', $parid, $sessid)) !== TRUE) {
|
2006-10-19 16:55:07 +02:00
|
|
|
return $res;
|
|
|
|
}
|
2006-12-16 07:36:22 +01:00
|
|
|
$oid = BasicStor::AddObj($tmpFname, $ftype, $parid);
|
2006-10-19 16:55:07 +02:00
|
|
|
if (PEAR::isError($oid)) {
|
|
|
|
return $oid;
|
|
|
|
}
|
2007-01-21 04:31:19 +01:00
|
|
|
$values = array(
|
|
|
|
"id" => $oid,
|
|
|
|
"metadata" => $metadata,
|
|
|
|
"gunid" => $gunid,
|
|
|
|
"filetype" => $ftype);
|
|
|
|
$storedFile =& StoredFile::Insert($values);
|
2007-01-11 20:24:45 +01:00
|
|
|
if (PEAR::isError($storedFile)) {
|
2006-12-20 03:46:29 +01:00
|
|
|
$res = BasicStor::RemoveObj($oid);
|
2007-01-11 20:24:45 +01:00
|
|
|
return $storedFile;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
|
|
|
if (PEAR::isError($res)) {
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
$res = $storedFile->setState('incomplete');
|
2006-10-19 16:55:07 +02:00
|
|
|
if (PEAR::isError($res)) {
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
if ($fname == '') {
|
|
|
|
$fname = "newFile";
|
|
|
|
}
|
|
|
|
$res = $this->bsRenameFile($oid, $fname);
|
|
|
|
if (PEAR::isError($res)) {
|
|
|
|
return $res;
|
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
return $this->bsOpenPut($chsum, $storedFile->gunid);
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Store or replace existing audio clip
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* @param string $token
|
|
|
|
* @return string gunid|PEAR_Error
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function storeAudioClipClose($sessid, $token)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2007-01-11 20:24:45 +01:00
|
|
|
$storedFile =& StoredFile::RecallByToken($token);
|
2007-02-05 15:06:59 +01:00
|
|
|
if (is_null($storedFile) || PEAR::isError($storedFile)) {
|
2007-01-11 20:24:45 +01:00
|
|
|
return $storedFile;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
2006-11-23 08:07:08 +01:00
|
|
|
$arr = $this->bsClosePut($token);
|
|
|
|
if (PEAR::isError($arr)) {
|
2007-01-11 20:24:45 +01:00
|
|
|
$storedFile->delete();
|
2006-11-23 08:07:08 +01:00
|
|
|
return $arr;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
|
|
|
$fname = $arr['fname'];
|
2007-01-11 20:24:45 +01:00
|
|
|
$res = $storedFile->setRawMediaData($fname);
|
2006-10-19 16:55:07 +02:00
|
|
|
if (PEAR::isError($res)) {
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
if (file_exists($fname)) {
|
|
|
|
@unlink($fname);
|
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
$res = $storedFile->setState('ready');
|
2006-10-19 16:55:07 +02:00
|
|
|
if (PEAR::isError($res)) {
|
|
|
|
return $res;
|
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
return $storedFile->gunid;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Check uploaded file
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $token
|
|
|
|
* "put" token
|
|
|
|
* @return array
|
|
|
|
* hash, (status: boolean, size: int - filesize)
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function uploadCheck($token)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
|
|
|
return $this->bsCheckPut($token);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Store webstream
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* session id
|
|
|
|
* @param string $gunid
|
|
|
|
* global unique id
|
|
|
|
* @param string $metadata
|
|
|
|
* metadata XML string
|
|
|
|
* @param string $fname
|
|
|
|
* human readable menmonic file name with extension corresponding to filetype
|
|
|
|
* @param string $url
|
|
|
|
* webstream url
|
|
|
|
* @return string
|
|
|
|
* gunid
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function storeWebstream($sessid, $gunid, $metadata, $fname, $url)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
|
|
|
$a = $this->storeAudioClipOpen(
|
|
|
|
$sessid, $gunid, $metadata, $fname, md5(''), 'webstream');
|
|
|
|
if (PEAR::isError($a)) {
|
|
|
|
return $a;
|
|
|
|
}
|
|
|
|
$gunid = $this->storeAudioClipClose($sessid, $a['token']);
|
|
|
|
if (PEAR::isError($gunid)) {
|
|
|
|
return $gunid;
|
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
$storedFile =& StoredFile::RecallByGunid($gunid);
|
2007-02-05 15:06:59 +01:00
|
|
|
if (is_null($storedFile) || PEAR::isError($storedFile)) {
|
2007-01-11 20:24:45 +01:00
|
|
|
return $storedFile;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
$oid = $storedFile->getId();
|
2006-10-19 16:55:07 +02:00
|
|
|
$r = $this-> bsSetMetadataValue(
|
|
|
|
$oid, 'ls:url', $url, NULL, NULL, 'metadata');
|
|
|
|
if (PEAR::isError($r)) {
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
return $gunid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------- access */
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Make access to audio clip
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* @param string $gunid
|
|
|
|
* @param int $parent
|
|
|
|
* parent token
|
|
|
|
* @return array
|
|
|
|
* with: seekable filehandle, access token
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
public function accessRawAudioData($sessid, $gunid, $parent='0')
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2007-01-11 20:24:45 +01:00
|
|
|
$storedFile =& StoredFile::RecallByGunid($gunid);
|
2007-02-05 15:06:59 +01:00
|
|
|
if (is_null($storedFile) || PEAR::isError($storedFile)) {
|
2007-01-11 20:24:45 +01:00
|
|
|
return $storedFile;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
if (($res = BasicStor::Authorize('read', $storedFile->getId(), $sessid)) !== TRUE) {
|
2006-10-19 16:55:07 +02:00
|
|
|
return $res;
|
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
return $storedFile->accessRawMediaData($parent);
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Release access to audio clip
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* @param string $token
|
|
|
|
* access token
|
|
|
|
* @return boolean|PEAR_Error
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
public function releaseRawAudioData($sessid, $token)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2007-01-11 20:24:45 +01:00
|
|
|
$storedFile =& StoredFile::RecallByToken($token);
|
2007-02-05 15:06:59 +01:00
|
|
|
if (is_null($storedFile) || PEAR::isError($storedFile)) {
|
2007-01-11 20:24:45 +01:00
|
|
|
return $storedFile;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
return $storedFile->releaseRawMediaData($token);
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- download */
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Create and return downloadable URL for audio file
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* session id
|
|
|
|
* @param string $gunid
|
|
|
|
* global unique id
|
|
|
|
* @return array
|
|
|
|
* array with strings:
|
2006-10-19 16:55:07 +02:00
|
|
|
* downloadable URL, download token, chsum, size, filename
|
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function downloadRawAudioDataOpen($sessid, $gunid)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
|
|
|
$ex = $this->existsAudioClip($sessid, $gunid);
|
|
|
|
if (PEAR::isError($ex)) {
|
|
|
|
return $ex;
|
|
|
|
}
|
2006-12-16 07:36:22 +01:00
|
|
|
$id = BasicStor::IdFromGunid($gunid);
|
2006-10-19 16:55:07 +02:00
|
|
|
if (is_null($id) || !$ex) {
|
|
|
|
return PEAR::raiseError(
|
|
|
|
"LocStor::downloadRawAudioDataOpen: gunid not found ($gunid)",
|
|
|
|
GBERR_NOTF
|
|
|
|
);
|
|
|
|
}
|
2006-12-16 07:36:22 +01:00
|
|
|
if (($res = BasicStor::Authorize('read', $id, $sessid)) !== TRUE) {
|
2006-10-19 16:55:07 +02:00
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
return $this->bsOpenDownload($id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Discard downloadable URL for audio file
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $token
|
|
|
|
* download token
|
|
|
|
* @return string
|
|
|
|
* gunid
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function downloadRawAudioDataClose($token)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
|
|
|
return $this->bsCloseDownload($token);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Create and return downloadable URL for metadata
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* session id
|
|
|
|
* @param string $gunid
|
|
|
|
* global unique id
|
|
|
|
* @return array
|
|
|
|
* array with strings:
|
2006-10-19 16:55:07 +02:00
|
|
|
* downloadable URL, download token, chsum, filename
|
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function downloadMetadataOpen($sessid, $gunid)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
|
|
|
// $res = $this->existsAudioClip($sessid, $gunid);
|
|
|
|
// if(PEAR::isError($res)) return $res;
|
2006-12-16 07:36:22 +01:00
|
|
|
$id = BasicStor::IdFromGunid($gunid);
|
2006-10-19 16:55:07 +02:00
|
|
|
if (is_null($id)) {
|
|
|
|
return PEAR::raiseError(
|
|
|
|
"LocStor::downloadMetadataOpen: gunid not found ($gunid)"
|
|
|
|
);
|
|
|
|
}
|
2006-12-16 07:36:22 +01:00
|
|
|
if (($res = BasicStor::Authorize('read', $id, $sessid)) !== TRUE) {
|
2006-10-19 16:55:07 +02:00
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
$res = $this->bsOpenDownload($id, 'metadata');
|
|
|
|
#unset($res['filename']);
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Discard downloadable URL for metadata
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $token
|
|
|
|
* download token
|
|
|
|
* @return string
|
|
|
|
* gunid
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function downloadMetadataClose($token)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
|
|
|
return $this->bsCloseDownload($token, 'metadata');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Return metadata as XML
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* @param string $gunid
|
|
|
|
* @return string|PEAR_Error
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function getAudioClip($sessid, $gunid)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2007-01-11 20:24:45 +01:00
|
|
|
$storedFile =& StoredFile::RecallByGunid($gunid);
|
2007-02-05 15:06:59 +01:00
|
|
|
if (is_null($storedFile) || PEAR::isError($storedFile)) {
|
2007-01-11 20:24:45 +01:00
|
|
|
return $storedFile;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
if (($res = BasicStor::Authorize('read', $storedFile->getId(), $sessid)) !== TRUE) {
|
2006-10-19 16:55:07 +02:00
|
|
|
return $res;
|
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
$md = $this->bsGetMetadata($storedFile->getId());
|
2006-10-19 16:55:07 +02:00
|
|
|
if (PEAR::isError($md)) {
|
|
|
|
return $md;
|
|
|
|
}
|
|
|
|
return $md;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------- search, browse */
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Search in metadata database
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* @param array $criteria
|
|
|
|
* with following structure:<br>
|
2006-10-19 16:55:07 +02:00
|
|
|
* <ul>
|
|
|
|
* <li>filetype - string, type of searched files,
|
|
|
|
* meaningful values: 'audioclip', 'webstream', 'playlist', 'all'</li>
|
|
|
|
* <li>operator - string, type of conditions join
|
|
|
|
* (any condition matches / all conditions match),
|
|
|
|
* meaningful values: 'and', 'or', ''
|
|
|
|
* (may be empty or ommited only with less then 2 items in
|
|
|
|
* "conditions" field)
|
|
|
|
* </li>
|
|
|
|
* <li>limit : int - limit for result arrays (0 means unlimited)</li>
|
|
|
|
* <li>offset : int - starting point (0 means without offset)</li>
|
|
|
|
* <li>orderby : string - metadata category for sorting (optional)
|
2006-11-02 11:09:46 +01:00
|
|
|
* or array of strings for multicolumn orderby
|
|
|
|
* [default: dc:creator, dc:source, dc:title]
|
|
|
|
* </li>
|
|
|
|
* <li>desc : boolean - flag for descending order (optional)
|
|
|
|
* or array of boolean for multicolumn orderby
|
|
|
|
* (it corresponds to elements of orderby field)
|
|
|
|
* [default: all ascending]
|
2006-10-19 16:55:07 +02:00
|
|
|
* </li>
|
|
|
|
* <li>conditions - array of hashes with structure:
|
|
|
|
* <ul>
|
|
|
|
* <li>cat - string, metadata category name</li>
|
|
|
|
* <li>op - string, operator - meaningful values:
|
|
|
|
* 'full', 'partial', 'prefix', '=', '<',
|
|
|
|
* '<=', '>', '>='</li>
|
|
|
|
* <li>val - string, search value</li>
|
|
|
|
* </ul>
|
|
|
|
* </li>
|
|
|
|
* </ul>
|
|
|
|
* @return array of hashes, fields:
|
|
|
|
* <ul>
|
|
|
|
* <li>cnt : integer - number of matching gunids
|
|
|
|
* of files have been found</li>
|
|
|
|
* <li>results : array of hashes:
|
|
|
|
* <ul>
|
|
|
|
* <li>gunid: string</li>
|
|
|
|
* <li>type: string - audioclip | playlist | webstream</li>
|
|
|
|
* <li>title: string - dc:title from metadata</li>
|
|
|
|
* <li>creator: string - dc:creator from metadata</li>
|
2006-10-20 16:51:45 +02:00
|
|
|
* <li>source: string - dc:source from metadata</li>
|
2006-10-19 16:55:07 +02:00
|
|
|
* <li>length: string - dcterms:extent in extent format</li>
|
|
|
|
* </ul>
|
|
|
|
* </li>
|
|
|
|
* </ul>
|
|
|
|
* @see BasicStor::localSearch
|
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function searchMetadata($sessid, $criteria)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2006-12-16 07:36:22 +01:00
|
|
|
if (($res = BasicStor::Authorize('read', $this->storId, $sessid)) !== TRUE) {
|
2006-10-19 16:55:07 +02:00
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
$criteria['resultMode'] = 'xmlrpc';
|
|
|
|
$res = $this->localSearch($criteria, $sessid);
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $criteria
|
|
|
|
* @param mixed $sessid - this variable isnt used
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function localSearch($criteria, $sessid='')
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2006-11-23 08:07:08 +01:00
|
|
|
$limit = intval(isset($criteria['limit']) ? $criteria['limit'] : 0);
|
2006-10-19 16:55:07 +02:00
|
|
|
$offset = intval(isset($criteria['offset']) ? $criteria['offset'] : 0);
|
2006-11-23 08:07:08 +01:00
|
|
|
$res = $this->bsLocalSearch($criteria, $limit, $offset);
|
2006-10-19 16:55:07 +02:00
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Return values of specified metadata category
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $category
|
|
|
|
* metadata category name
|
|
|
|
* with or without namespace prefix (dc:title, author)
|
|
|
|
* @param hash $criteria
|
|
|
|
* see searchMetadata method
|
|
|
|
* @param string $sessid
|
|
|
|
* @return array
|
|
|
|
* hash, fields:
|
2006-10-19 16:55:07 +02:00
|
|
|
* results : array with found values
|
|
|
|
* cnt : integer - number of matching values
|
|
|
|
* @see BasicStor::bsBrowseCategory
|
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function browseCategory($category, $criteria=NULL, $sessid='')
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2006-11-23 08:07:08 +01:00
|
|
|
$limit = intval(isset($criteria['limit']) ? $criteria['limit'] : 0);
|
2006-10-19 16:55:07 +02:00
|
|
|
$offset = intval(isset($criteria['offset']) ? $criteria['offset'] : 0);
|
|
|
|
$res = $this->bsBrowseCategory($category, $limit, $offset, $criteria);
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------- etc. */
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Check if audio clip exists
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* @param string $gunid
|
|
|
|
* @return boolean
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function existsAudioClip($sessid, $gunid)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
|
|
|
$ex = $this->existsFile($sessid, $gunid, 'audioclip');
|
|
|
|
// webstreams are subset of audioclips - moved to BasicStor
|
|
|
|
// if($ex === FALSE ){
|
|
|
|
// $ex = $this->existsFile($sessid, $gunid, 'webstream');
|
|
|
|
// }
|
|
|
|
if ($ex === FALSE ) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (PEAR::isError($ex)) {
|
|
|
|
return $ex;
|
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
$storedFile =& StoredFile::RecallByGunid($gunid);
|
2007-02-05 15:06:59 +01:00
|
|
|
if (is_null($storedFile) || PEAR::isError($storedFile)) {
|
2007-01-11 20:24:45 +01:00
|
|
|
return $storedFile;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
return $storedFile->exists();
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Check if file exists in the storage
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* @param string $gunid
|
|
|
|
* @param string $ftype
|
|
|
|
* internal file type
|
|
|
|
* @return boolean
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function existsFile($sessid, $gunid, $ftype=NULL)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2006-12-16 07:36:22 +01:00
|
|
|
$id = BasicStor::IdFromGunid($gunid);
|
2006-10-19 16:55:07 +02:00
|
|
|
if (is_null($id)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2006-12-16 07:36:22 +01:00
|
|
|
if (($res = BasicStor::Authorize('read', $id, $sessid)) !== TRUE) {
|
2006-10-19 16:55:07 +02:00
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
$ex = $this->bsExistsFile($id, $ftype);
|
|
|
|
return $ex;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Delete existing audio clip
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* @param string $gunid
|
|
|
|
* @param boolean $forced
|
|
|
|
* if true, don't use trash
|
|
|
|
* @return boolean|PEAR_Error
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function deleteAudioClip($sessid, $gunid, $forced=FALSE)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2007-01-11 20:24:45 +01:00
|
|
|
$storedFile =& StoredFile::RecallByGunid($gunid);
|
2007-01-24 04:04:56 +01:00
|
|
|
if (is_null($storedFile)) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
if (PEAR::isError($storedFile)) {
|
|
|
|
if ($storedFile->getCode()==GBERR_FOBJNEX && $forced) {
|
2006-10-19 16:55:07 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
return $storedFile;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
if (($res = BasicStor::Authorize('write', $storedFile->getId(), $sessid)) !== TRUE) {
|
2006-10-19 16:55:07 +02:00
|
|
|
return $res;
|
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
$res = $this->bsDeleteFile($storedFile->getId(), $forced);
|
2006-10-19 16:55:07 +02:00
|
|
|
if (PEAR::isError($res)) {
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Update existing audio clip metadata
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* @param string $gunid
|
|
|
|
* @param string $metadata
|
|
|
|
* metadata XML string
|
|
|
|
* @return boolean|PEAR_Error
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function updateAudioClipMetadata($sessid, $gunid, $metadata)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2007-01-11 20:24:45 +01:00
|
|
|
$storedFile =& StoredFile::RecallByGunid($gunid);
|
2007-02-05 15:06:59 +01:00
|
|
|
if (is_null($storedFile) || PEAR::isError($storedFile)) {
|
2007-01-11 20:24:45 +01:00
|
|
|
return $storedFile;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
if (($res = BasicStor::Authorize('write', $storedFile->getId(), $sessid)) !== TRUE) {
|
2006-10-19 16:55:07 +02:00
|
|
|
return $res;
|
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
return $storedFile->setMetadata($metadata, 'string');
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*====================================================== playlist methods */
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Create a new empty playlist.
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* session ID
|
|
|
|
* @param string $playlistId
|
|
|
|
* playlist global unique ID
|
|
|
|
* @param string $fname
|
|
|
|
* human readable mnemonic file name
|
|
|
|
* @return string
|
|
|
|
* playlist global unique ID
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
public function createPlaylist($sessid, $playlistId, $fname)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
|
|
|
$ex = $this->existsPlaylist($sessid, $playlistId);
|
|
|
|
if (PEAR::isError($ex)) {
|
|
|
|
return $ex;
|
|
|
|
}
|
|
|
|
if ($ex) {
|
|
|
|
return PEAR::raiseError(
|
|
|
|
'LocStor::createPlaylist: already exists'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$tmpFname = uniqid('');
|
|
|
|
$parid = $this->_getHomeDirIdFromSess($sessid);
|
|
|
|
if (PEAR::isError($parid)) {
|
|
|
|
return $parid;
|
|
|
|
}
|
2006-12-16 07:36:22 +01:00
|
|
|
if (($res = BasicStor::Authorize('write', $parid, $sessid)) !== TRUE) {
|
2006-10-19 16:55:07 +02:00
|
|
|
return $res;
|
|
|
|
}
|
2006-12-16 07:36:22 +01:00
|
|
|
$oid = BasicStor::AddObj($tmpFname , 'playlist', $parid);
|
2006-10-19 16:55:07 +02:00
|
|
|
if (PEAR::isError($oid)) {
|
|
|
|
return $oid;
|
|
|
|
}
|
2007-01-21 04:31:19 +01:00
|
|
|
$values = array(
|
|
|
|
"id" => $oid,
|
|
|
|
"metadata" => dirname(__FILE__).'/emptyPlaylist.xml',
|
|
|
|
"gunid" => $playlistId,
|
|
|
|
"filetype" => "playlist");
|
|
|
|
$storedFile = StoredFile::Insert($values);
|
2007-01-11 20:24:45 +01:00
|
|
|
if (PEAR::isError($storedFile)) {
|
2006-12-20 03:46:29 +01:00
|
|
|
$res = BasicStor::RemoveObj($oid);
|
2007-01-11 20:24:45 +01:00
|
|
|
return $storedFile;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
|
|
|
if ($fname == '') {
|
|
|
|
$fname = "newFile.xml";
|
|
|
|
}
|
|
|
|
$res = $this->bsRenameFile($oid, $fname);
|
|
|
|
if (PEAR::isError($res)) {
|
|
|
|
return $res;
|
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
$res = $storedFile->setState('ready');
|
2006-10-19 16:55:07 +02:00
|
|
|
if (PEAR::isError($res)) {
|
|
|
|
return $res;
|
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
$res = $storedFile->setMime('application/smil');
|
2006-10-19 16:55:07 +02:00
|
|
|
if (PEAR::isError($res)) {
|
|
|
|
return $res;
|
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
return $storedFile->gunid;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Open a Playlist metafile for editing.
|
|
|
|
* Open readable URL and mark file as beeing edited.
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* session ID
|
|
|
|
* @param string $playlistId
|
|
|
|
* playlist global unique ID
|
|
|
|
* @return struct
|
2006-10-19 16:55:07 +02:00
|
|
|
* {url:readable URL for HTTP GET, token:access token, chsum:checksum}
|
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
public function editPlaylist($sessid, $playlistId)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
|
|
|
$ex = $this->existsPlaylist($sessid, $playlistId);
|
|
|
|
if (PEAR::isError($ex)) {
|
|
|
|
return $ex;
|
|
|
|
}
|
|
|
|
if (!$ex) {
|
|
|
|
return PEAR::raiseError(
|
|
|
|
'LocStor::editPlaylist: playlist not exists'
|
|
|
|
);
|
|
|
|
}
|
2006-11-21 17:00:50 +01:00
|
|
|
if ($this->isEdited($playlistId) !== FALSE) {
|
2006-10-19 16:55:07 +02:00
|
|
|
return PEAR::raiseError(
|
|
|
|
'LocStor::editPlaylist: playlist already edited'
|
|
|
|
);
|
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
$storedFile =& StoredFile::RecallByGunid($playlistId);
|
2007-02-05 15:06:59 +01:00
|
|
|
if (is_null($storedFile) || PEAR::isError($storedFile)) {
|
2007-01-11 20:24:45 +01:00
|
|
|
return $storedFile;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
$id = $storedFile->getId();
|
2006-12-16 07:36:22 +01:00
|
|
|
if (($res = BasicStor::Authorize('write', $id, $sessid)) !== TRUE) {
|
2006-10-19 16:55:07 +02:00
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
$res = $this->bsOpenDownload($id, 'metadata');
|
|
|
|
if (PEAR::isError($res)) {
|
|
|
|
return $res;
|
|
|
|
}
|
2006-12-16 07:36:22 +01:00
|
|
|
$r = $this->setEditFlag($playlistId, TRUE, $sessid);
|
2006-10-19 16:55:07 +02:00
|
|
|
if (PEAR::isError($r)) {
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
unset($res['filename']);
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Store a new Playlist metafile in place of the old one.
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* session ID
|
|
|
|
* @param string $playlistToken
|
|
|
|
* playlist access token
|
|
|
|
* @param string $newPlaylist
|
|
|
|
* new playlist as XML string
|
|
|
|
* @return string
|
|
|
|
* playlistId
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function savePlaylist($sessid, $playlistToken, $newPlaylist)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
|
|
|
$playlistId = $this->bsCloseDownload($playlistToken, 'metadata');
|
|
|
|
if (PEAR::isError($playlistId)) {
|
|
|
|
return $playlistId;
|
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
$storedFile =& StoredFile::RecallByGunid($playlistId);
|
2007-02-05 15:06:59 +01:00
|
|
|
if (is_null($storedFile) || PEAR::isError($storedFile)) {
|
2007-01-11 20:24:45 +01:00
|
|
|
return $storedFile;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
$res = $storedFile->setMetadata($newPlaylist, 'string', 'playlist');
|
2006-10-19 16:55:07 +02:00
|
|
|
if (PEAR::isError($res)) {
|
|
|
|
return $res;
|
|
|
|
}
|
2006-12-16 07:36:22 +01:00
|
|
|
$r = $this->setEditFlag($playlistId, FALSE, $sessid);
|
2006-10-19 16:55:07 +02:00
|
|
|
if (PEAR::isError($r)) {
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
return $playlistId;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* RollBack playlist changes to the locked state
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $playlistToken
|
|
|
|
* playlist access token
|
|
|
|
* @param string $sessid
|
|
|
|
* session ID
|
|
|
|
* @return string
|
|
|
|
* gunid of playlist
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
public function revertEditedPlaylist($playlistToken, $sessid='')
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
|
|
|
$gunid = $this->bsCloseDownload($playlistToken, 'metadata');
|
|
|
|
if (PEAR::isError($gunid)) {
|
|
|
|
return $gunid;
|
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
$storedFile =& StoredFile::RecallByGunid($gunid);
|
2007-02-05 15:06:59 +01:00
|
|
|
if (is_null($storedFile) || PEAR::isError($storedFile)) {
|
2007-01-11 20:24:45 +01:00
|
|
|
return $storedFile;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
$id = $storedFile->getId();
|
|
|
|
$mdata = $storedFile->getMetadata();
|
2006-10-19 16:55:07 +02:00
|
|
|
if (PEAR::isError($mdata)) {
|
|
|
|
return $mdata;
|
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
$res = $storedFile->setMetadata($mdata, 'string');
|
2006-10-19 16:55:07 +02:00
|
|
|
if (PEAR::isError($res)) {
|
|
|
|
return $res;
|
|
|
|
}
|
2006-12-16 07:36:22 +01:00
|
|
|
$this->setEditFlag($gunid, FALSE, $sessid);
|
2006-10-19 16:55:07 +02:00
|
|
|
return $gunid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Delete a Playlist metafile.
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* session ID
|
|
|
|
* @param string $playlistId
|
|
|
|
* playlist global unique ID
|
|
|
|
* @param boolean $forced
|
|
|
|
* if true don't use trash
|
|
|
|
* @return boolean
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
public function deletePlaylist($sessid, $playlistId, $forced=FALSE)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
|
|
|
$ex = $this->existsPlaylist($sessid, $playlistId);
|
|
|
|
if (PEAR::isError($ex)) {
|
|
|
|
return $ex;
|
|
|
|
}
|
|
|
|
if (!$ex) {
|
|
|
|
if ($forced) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return PEAR::raiseError(
|
|
|
|
'LocStor::deletePlaylist: playlist not exists',
|
|
|
|
GBERR_FILENEX
|
|
|
|
);
|
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
$storedFile =& StoredFile::RecallByGunid($playlistId);
|
2007-02-05 15:06:59 +01:00
|
|
|
if (is_null($storedFile) || PEAR::isError($storedFile)) {
|
2007-01-11 20:24:45 +01:00
|
|
|
return $storedFile;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
if (($res = BasicStor::Authorize('write', $storedFile->getId(), $sessid)) !== TRUE) {
|
2006-10-19 16:55:07 +02:00
|
|
|
return $res;
|
|
|
|
}
|
2007-01-11 20:24:45 +01:00
|
|
|
$res = $this->bsDeleteFile($storedFile->getId(), $forced);
|
2006-10-19 16:55:07 +02:00
|
|
|
if (PEAR::isError($res)) {
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Access (read) a Playlist metafile.
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* session ID
|
|
|
|
* @param string $playlistId
|
|
|
|
* playlist global unique ID
|
|
|
|
* @param boolean $recursive
|
|
|
|
* flag for recursive access content inside playlist
|
|
|
|
* @param int $parent
|
|
|
|
* parent token
|
|
|
|
* @return struct {
|
2006-10-19 16:55:07 +02:00
|
|
|
* url: readable URL for HTTP GET,
|
|
|
|
* token: access token,
|
|
|
|
* chsum: checksum,
|
|
|
|
* content: array of structs - recursive access (optional)
|
|
|
|
* filename: string mnemonic filename
|
|
|
|
* }
|
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
public function accessPlaylist($sessid, $playlistId, $recursive=FALSE, $parent='0')
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
|
|
|
if ($recursive) {
|
2006-12-08 05:31:20 +01:00
|
|
|
require_once("AccessRecur.php");
|
2006-10-19 16:55:07 +02:00
|
|
|
$r = AccessRecur::accessPlaylist($this, $sessid, $playlistId);
|
|
|
|
if (PEAR::isError($r)) {
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
$ex = $this->existsPlaylist($sessid, $playlistId);
|
|
|
|
if (PEAR::isError($ex)) {
|
|
|
|
return $ex;
|
|
|
|
}
|
|
|
|
if (!$ex) {
|
|
|
|
return PEAR::raiseError(
|
|
|
|
"LocStor::accessPlaylist: playlist not found ($playlistId)",
|
|
|
|
GBERR_NOTF
|
|
|
|
);
|
|
|
|
}
|
2006-12-16 07:36:22 +01:00
|
|
|
$id = BasicStor::IdFromGunid($playlistId);
|
|
|
|
if (($res = BasicStor::Authorize('read', $id, $sessid)) !== TRUE) {
|
2006-10-19 16:55:07 +02:00
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
$res = $this->bsOpenDownload($id, 'metadata', $parent);
|
|
|
|
#unset($res['filename']);
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Release the resources obtained earlier by accessPlaylist().
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* session ID
|
|
|
|
* @param string $playlistToken
|
|
|
|
* playlist access token
|
|
|
|
* @param boolean $recursive
|
|
|
|
* flag for recursive access content inside playlist
|
|
|
|
* @return string
|
|
|
|
* playlist ID
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
public function releasePlaylist($sessid, $playlistToken, $recursive=FALSE)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
|
|
|
if ($recursive) {
|
|
|
|
require_once"AccessRecur.php";
|
|
|
|
$r = AccessRecur::releasePlaylist($this, $sessid, $playlistToken);
|
|
|
|
if (PEAR::isError($r)) {
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
return $this->bsCloseDownload($playlistToken, 'metadata');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Create a tarfile with playlist export - playlist and all matching
|
|
|
|
* sub-playlists and media files (if desired)
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* session ID
|
|
|
|
* @param array $plids
|
|
|
|
* array of strings, playlist global unique IDs (one gunid is accepted too)
|
|
|
|
* @param string $type
|
|
|
|
* playlist format, values: lspl | smil | m3u
|
|
|
|
* @param boolean $standalone
|
|
|
|
* if only playlist should be exported or with all related files
|
|
|
|
* @return hasharray with fields:
|
2006-10-19 16:55:07 +02:00
|
|
|
* url string: readable url,
|
|
|
|
* token string: access token
|
|
|
|
* chsum string: md5 checksum,
|
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function exportPlaylistOpen($sessid, $plids, $type='lspl', $standalone=FALSE)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2006-11-23 08:07:08 +01:00
|
|
|
$res = $this->bsExportPlaylistOpen($plids, $type, !$standalone);
|
2006-12-16 07:36:22 +01:00
|
|
|
if (PEAR::isError($res)) {
|
2006-11-23 08:07:08 +01:00
|
|
|
return $res;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
2006-12-16 07:36:22 +01:00
|
|
|
$url = BasicStor::GetUrlPart()."access/".basename($res['fname']);
|
2006-10-19 16:55:07 +02:00
|
|
|
$chsum = md5_file($res['fname']);
|
|
|
|
$size = filesize($res['fname']);
|
|
|
|
return array(
|
|
|
|
'url' => $url,
|
|
|
|
'token' => $res['token'],
|
|
|
|
'chsum' => $chsum,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Close playlist export previously opened by the exportPlaylistOpen method
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $token
|
|
|
|
* access token obtained from exportPlaylistOpen method call
|
|
|
|
* @return boolean|PEAR_Error
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function exportPlaylistClose($token)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
|
|
|
return $this->bsExportPlaylistClose($token);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Open writable handle for import playlist in LS Archive format
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* session id
|
|
|
|
* @param string $chsum
|
|
|
|
* md5 checksum of imported file
|
|
|
|
* @return hasharray with:
|
2006-10-19 16:55:07 +02:00
|
|
|
* url string: writable URL
|
|
|
|
* token string: PUT token
|
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function importPlaylistOpen($sessid, $chsum)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2006-12-16 07:36:22 +01:00
|
|
|
$userid = Alib::GetSessUserId($sessid);
|
|
|
|
if (PEAR::isError($userid)) {
|
2006-11-23 08:07:08 +01:00
|
|
|
return $userid;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
|
|
|
$r = $this->bsOpenPut($chsum, NULL, $userid);
|
|
|
|
if (PEAR::isError($r)) {
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Close import-handle and import playlist
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $token
|
|
|
|
* import token obtained by importPlaylistOpen method
|
|
|
|
* @return string
|
|
|
|
* result file global id (or error object)
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function importPlaylistClose($token)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2006-11-23 08:07:08 +01:00
|
|
|
$arr = $this->bsClosePut($token);
|
|
|
|
if (PEAR::isError($arr)) {
|
|
|
|
return $arr;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
|
|
|
$fname = $arr['fname'];
|
|
|
|
$owner = $arr['owner'];
|
2006-11-23 08:07:08 +01:00
|
|
|
$parid = $this->_getHomeDirId($owner);
|
|
|
|
if (PEAR::isError($parid)) {
|
2006-10-19 16:55:07 +02:00
|
|
|
if (file_exists($fname)) {
|
|
|
|
@unlink($fname);
|
|
|
|
}
|
2006-11-23 08:07:08 +01:00
|
|
|
return $parid;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
2006-11-23 08:07:08 +01:00
|
|
|
$res = $this->bsImportPlaylist($parid, $fname);
|
2006-10-19 16:55:07 +02:00
|
|
|
if (file_exists($fname)) {
|
|
|
|
@unlink($fname);
|
|
|
|
}
|
2006-11-23 08:07:08 +01:00
|
|
|
if (PEAR::isError($res)) {
|
|
|
|
return $res;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
2006-12-16 07:36:22 +01:00
|
|
|
return BasicStor::GunidFromId($res);
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Check whether a Playlist metafile with the given playlist ID exists.
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* session ID
|
|
|
|
* @param string $playlistId
|
|
|
|
* playlist global unique ID
|
|
|
|
* @return boolean
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
public function existsPlaylist($sessid, $playlistId)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
|
|
|
return $this->existsFile($sessid, $playlistId, 'playlist');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Check whether a Playlist metafile with the given playlist ID
|
|
|
|
* is available for editing, i.e., exists and is not marked as
|
|
|
|
* being edited.
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* session ID
|
|
|
|
* @param string $playlistId
|
|
|
|
* playlist global unique ID
|
|
|
|
* @param boolean $getUid
|
|
|
|
* flag for returning editedby uid
|
|
|
|
* @return boolean
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
public function playlistIsAvailable($sessid, $playlistId, $getUid=FALSE)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2006-11-21 17:00:50 +01:00
|
|
|
// $ex = $this->existsPlaylist($sessid, $playlistId);
|
|
|
|
// if (PEAR::isError($ex)) {
|
|
|
|
// return $ex;
|
|
|
|
// }
|
|
|
|
// if (!$ex) {
|
|
|
|
// return PEAR::raiseError(
|
|
|
|
// 'LocStor::playlistIsAvailable: playlist not exists'
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
$ie = $this->isEdited($playlistId);
|
2006-10-19 16:55:07 +02:00
|
|
|
if ($ie === FALSE) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if ($getUid) {
|
|
|
|
return $ie;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------- render methods */
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Render playlist to ogg file (open handle)
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* session id
|
|
|
|
* @param string $plid
|
|
|
|
* playlist gunid
|
|
|
|
* @return hasharray
|
2006-10-19 16:55:07 +02:00
|
|
|
* token: string - render token
|
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function renderPlaylistToFileOpen($sessid, $plid)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2006-12-08 05:31:20 +01:00
|
|
|
require_once("Renderer.php");
|
2006-10-19 16:55:07 +02:00
|
|
|
$r = Renderer::rnRender2FileOpen($this, $plid);
|
|
|
|
if (PEAR::isError($r)) {
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Render playlist to ogg file (check results)
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $token
|
|
|
|
* render token
|
|
|
|
* @return hasharray:
|
2006-10-19 16:55:07 +02:00
|
|
|
* status : string - success | working | fault
|
|
|
|
* url : string - readable url
|
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function renderPlaylistToFileCheck($token)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2006-12-16 07:36:22 +01:00
|
|
|
require_once("Renderer.php");
|
2006-10-19 16:55:07 +02:00
|
|
|
$r = Renderer::rnRender2FileCheck($this, $token);
|
|
|
|
if (PEAR::isError($r)) {
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
return array('status'=>$r['status'], 'url'=>$r['url']);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Render playlist to ogg file (close handle)
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $token
|
|
|
|
* render token
|
|
|
|
* @return boolean status
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function renderPlaylistToFileClose($token)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2006-12-16 07:36:22 +01:00
|
|
|
require_once("Renderer.php");
|
2006-10-19 16:55:07 +02:00
|
|
|
$r = Renderer::rnRender2FileClose($this, $token);
|
|
|
|
if (PEAR::isError($r)) {
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
return array(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Render playlist to storage media clip (open handle)
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* session id
|
|
|
|
* @param string $plid
|
|
|
|
* playlist gunid
|
|
|
|
* @return string
|
|
|
|
* render token
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function renderPlaylistToStorageOpen($sessid, $plid)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2006-12-16 07:36:22 +01:00
|
|
|
require_once("Renderer.php");
|
|
|
|
$owner = Alib::GetSessUserId($sessid);
|
|
|
|
if (PEAR::isError($owner)) {
|
2006-10-19 16:55:07 +02:00
|
|
|
return $owner;
|
|
|
|
}
|
|
|
|
$r = Renderer::rnRender2FileOpen($this, $plid, $owner);
|
|
|
|
if (PEAR::isError($r)) {
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Render playlist to storage media clip (check results)
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $token
|
|
|
|
* render token
|
|
|
|
* @return hasharray:
|
2006-10-19 16:55:07 +02:00
|
|
|
* status : string - success | working | fault
|
|
|
|
* gunid : string - gunid of result file
|
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function renderPlaylistToStorageCheck($token)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2006-12-16 07:36:22 +01:00
|
|
|
require_once("Renderer.php");
|
2006-10-19 16:55:07 +02:00
|
|
|
$r = Renderer::rnRender2StorageCheck($this, $token);
|
|
|
|
if (PEAR::isError($r)) {
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Render playlist to RSS file (open handle)
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* session id
|
|
|
|
* @param string $plid
|
|
|
|
* playlist gunid
|
|
|
|
* @return string
|
|
|
|
* render token
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function renderPlaylistToRSSOpen($sessid, $plid)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2006-12-16 07:36:22 +01:00
|
|
|
global $CC_CONFIG;
|
2006-10-19 16:55:07 +02:00
|
|
|
$token = '123456789abcdeff';
|
2006-12-16 07:36:22 +01:00
|
|
|
$fakeFile = $CC_CONFIG['accessDir']."/$token.rss";
|
2006-10-19 16:55:07 +02:00
|
|
|
file_put_contents($fakeFile, "fake rendered file");
|
|
|
|
return array('token'=>$token);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Render playlist to RSS file (check results)
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $token
|
|
|
|
* render token
|
|
|
|
* @return hasharray :
|
2006-10-19 16:55:07 +02:00
|
|
|
* status : string - success | working | fault
|
|
|
|
* url : string - readable url
|
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function renderPlaylistToRSSCheck($token)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2006-12-16 07:36:22 +01:00
|
|
|
$fakeFile = $CC_CONFIG['accessDir']."/$token.rss";
|
2006-10-19 16:55:07 +02:00
|
|
|
if ($token != '123456789abcdeff' || !file_exists($fakeFile)) {
|
|
|
|
return PEAR::raiseError(
|
|
|
|
"LocStor::renderPlaylistToRSSCheck: invalid token ($token)"
|
|
|
|
);
|
|
|
|
}
|
2006-12-16 07:36:22 +01:00
|
|
|
$fakeFUrl = BasicStor::GetUrlPart()."access/$token.rss";
|
2006-10-19 16:55:07 +02:00
|
|
|
return array(
|
|
|
|
'status'=> 'success',
|
|
|
|
'url' => $fakeFUrl,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Render playlist to RSS file (close handle)
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $token
|
|
|
|
* render token
|
|
|
|
* @return boolean
|
|
|
|
* status
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function renderPlaylistToRSSClose($token)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
|
|
|
if ($token != '123456789abcdeff') {
|
|
|
|
return PEAR::raiseError(
|
|
|
|
"LocStor::renderPlaylistToRSSClose: invalid token"
|
|
|
|
);
|
|
|
|
}
|
2006-12-16 07:36:22 +01:00
|
|
|
$fakeFile = $CC_CONFIG['accessDir']."/$token.rss";
|
2006-10-19 16:55:07 +02:00
|
|
|
unlink($fakeFile);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*================================================= storage admin methods */
|
|
|
|
|
|
|
|
/* ------------------------------------------------------- backup methods */
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Create backup of storage (open handle)
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* session id
|
|
|
|
* @param array $criteria
|
|
|
|
* see search criteria
|
|
|
|
* @return array
|
2006-10-19 16:55:07 +02:00
|
|
|
* token : string - backup token
|
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function createBackupOpen($sessid, $criteria='')
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2006-11-14 20:09:20 +01:00
|
|
|
require_once("Backup.php");
|
|
|
|
$bu = new Backup($this);
|
|
|
|
if (PEAR::isError($bu)) {
|
|
|
|
return $bu;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
|
|
|
$r = $bu->openBackup($sessid,$criteria);
|
|
|
|
if ($r === FALSE) {
|
|
|
|
return PEAR::raiseError(
|
|
|
|
"LocStor::createBackupOpen: false returned from Backup"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Create backup of storage (check results)
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $token
|
|
|
|
* backup token
|
|
|
|
* @return hasharray
|
|
|
|
* with field:
|
2006-10-19 16:55:07 +02:00
|
|
|
* status : string - susccess | working | fault
|
|
|
|
* faultString: string - description of fault
|
|
|
|
* token : stirng - backup token
|
|
|
|
* url : string - access url
|
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function createBackupCheck($token)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2006-11-14 20:09:20 +01:00
|
|
|
require_once("Backup.php");
|
|
|
|
$bu = new Backup($this);
|
|
|
|
if (PEAR::isError($bu)) {
|
|
|
|
return $bu;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
|
|
|
return $bu->checkBackup($token);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Create backup of storage (list results)
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* session id
|
|
|
|
* @param status $stat
|
2006-10-19 16:55:07 +02:00
|
|
|
* if this parameter is not set, then return with all unclosed backups
|
2006-11-14 20:09:20 +01:00
|
|
|
* @return array
|
|
|
|
* array of hasharray with field:
|
2006-10-19 16:55:07 +02:00
|
|
|
* status : string - susccess | working | fault
|
|
|
|
* token : stirng - backup token
|
|
|
|
* url : string - access url
|
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function createBackupList($sessid, $stat='')
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2006-11-14 20:09:20 +01:00
|
|
|
require_once("Backup.php");
|
|
|
|
$bu = new Backup($this);
|
|
|
|
if (PEAR::isError($bu)) {
|
|
|
|
return $bu;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
|
|
|
return $bu->listBackups($stat);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Create backup of storage (close handle)
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $token
|
|
|
|
* backup token
|
|
|
|
* @return boolean
|
|
|
|
* status
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function createBackupClose($token)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2006-11-14 20:09:20 +01:00
|
|
|
require_once("Backup.php");
|
|
|
|
$bu = new Backup($this);
|
|
|
|
if (PEAR::isError($bu)) {
|
|
|
|
return $bu;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
|
|
|
return $bu->closeBackup($token);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------ restore methods */
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Restore a backup file (open handle)
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* session id
|
|
|
|
* @param string $chsum
|
|
|
|
* md5 checksum of imported file
|
2006-11-09 15:38:59 +01:00
|
|
|
* @return array
|
|
|
|
* array with:
|
|
|
|
* url string: writable URL
|
|
|
|
* fname string: writable local filename
|
|
|
|
* token string: PUT token
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function restoreBackupOpen($sessid, $chsum)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2006-12-16 07:36:22 +01:00
|
|
|
$userid = Alib::getSessUserId($sessid);
|
|
|
|
if (PEAR::isError($userid)) {
|
2006-11-14 20:09:20 +01:00
|
|
|
return $userid;
|
2006-11-09 15:38:59 +01:00
|
|
|
}
|
|
|
|
$r = $this->bsOpenPut($chsum, NULL, $userid);
|
|
|
|
if (PEAR::isError($r)) {
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Restore a backup file (close put handle)
|
2006-11-09 15:38:59 +01:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $sessid
|
|
|
|
* session id
|
|
|
|
* @param string $token
|
|
|
|
* "put" token
|
|
|
|
* @return string $token
|
|
|
|
* restore token
|
2006-11-09 15:38:59 +01:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function restoreBackupClosePut($sessid, $token) {
|
2006-11-14 20:09:20 +01:00
|
|
|
$arr = $this->bsClosePut($token);
|
|
|
|
if (PEAR::isError($arr)) {
|
|
|
|
return $arr;
|
2006-11-09 15:38:59 +01:00
|
|
|
}
|
|
|
|
$fname = $arr['fname'];
|
2006-11-14 20:09:20 +01:00
|
|
|
require_once('Restore.php');
|
2006-10-19 16:55:07 +02:00
|
|
|
$rs = new Restore($this);
|
|
|
|
if (PEAR::isError($rs)) {
|
|
|
|
return $rs;
|
|
|
|
}
|
2006-11-09 15:38:59 +01:00
|
|
|
return $rs->openRestore($sessid, $fname);
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
|
|
|
|
2006-11-14 20:09:20 +01:00
|
|
|
|
2006-10-19 16:55:07 +02:00
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Restore a backup file (check state)
|
|
|
|
*
|
|
|
|
* @param string $token
|
|
|
|
* restore token
|
|
|
|
* @return array
|
|
|
|
* status - fields:
|
|
|
|
* token: string - restore token
|
|
|
|
* status: string - working | fault | success
|
|
|
|
* faultString: string - description of fault
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function restoreBackupCheck($token)
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2006-11-14 20:09:20 +01:00
|
|
|
require_once('Restore.php');
|
2006-10-19 16:55:07 +02:00
|
|
|
$rs = new Restore($this);
|
|
|
|
if (PEAR::isError($rs)) {
|
|
|
|
return $rs;
|
|
|
|
}
|
|
|
|
return $rs->checkRestore($token);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-14 20:09:20 +01:00
|
|
|
* Restore a backup file (close handle)
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-14 20:09:20 +01:00
|
|
|
* @param string $token
|
|
|
|
* restore token
|
|
|
|
* @return array
|
|
|
|
* status - fields:
|
|
|
|
* token: string - restore token
|
|
|
|
* status: string - working | fault | success
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function restoreBackupClose($token) {
|
2006-11-14 20:09:20 +01:00
|
|
|
require_once('Restore.php');
|
2006-10-19 16:55:07 +02:00
|
|
|
$rs = new Restore($this);
|
|
|
|
if (PEAR::isError($rs)) {
|
|
|
|
return $rs;
|
|
|
|
}
|
|
|
|
return $rs->closeRestore($token);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*===================================================== auxiliary methods */
|
|
|
|
/**
|
2006-11-21 17:00:50 +01:00
|
|
|
* Dummy method - only returns Campcaster version
|
2006-10-19 16:55:07 +02:00
|
|
|
*
|
2006-11-21 17:00:50 +01:00
|
|
|
* @return string
|
2006-10-19 16:55:07 +02:00
|
|
|
*/
|
2006-12-08 05:31:20 +01:00
|
|
|
protected function getVersion()
|
2006-10-19 16:55:07 +02:00
|
|
|
{
|
2006-11-21 17:00:50 +01:00
|
|
|
return CAMPCASTER_VERSION;
|
2006-10-19 16:55:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // class LocStor
|
|
|
|
?>
|