(#1642, part of #1579) backup XML-RPC and PHP backend

This commit is contained in:
csikosjanos 2006-04-04 15:26:20 +00:00
parent 2d699645dd
commit 75f9440cf6
9 changed files with 641 additions and 128 deletions

View file

@ -0,0 +1,6 @@
<div class="container_elements" style="width: 607px;">
<h1>##Import Playlist##</h1>
{*UIBROWSER->fileForm id=$editItem.id folderId=$editItem.folderId assign="dynform"*}
{include file="sub/dynForm_plain.tpl}
{assign var="_uploadform" value=null}
</div>

View file

@ -136,12 +136,12 @@ class uiSearch
$this->criteria['conditions'] = NULL; $this->criteria['conditions'] = NULL;
$this->criteria['offset'] = NULL; $this->criteria['offset'] = NULL;
$this->criteria['operator'] = UI_SIMPLESEARCH_FILETYPE; $this->criteria['operator'] = UI_SIMPLESEARCH_OPERATOR;
$this->criteria['filetype'] = UI_SIMPLESEARCH_OPERATOR; $this->criteria['filetype'] = UI_SIMPLESEARCH_FILETYPE;
$this->criteria['limit'] = UI_SIMPLESEARCH_LIMIT; $this->criteria['limit'] = UI_SIMPLESEARCH_LIMIT;
$this->criteria['counter'] = UI_SIMPLESEARCH_ROWS; $this->criteria['counter'] = UI_SIMPLESEARCH_ROWS;
$this->criteria['form']['operator'] = 'OR'; ## $criteria['form'] is used for retransfer to form ## $this->criteria['form']['operator'] = 'OR'; ## $criteria['form'] is used for retransfer to form ##
$this->criteria['form']['filetype'] = 'File'; $this->criteria['form']['filetype'] = UI_SIMPLESEARCH_FILETYPE;
$this->criteria['form']['limit'] = UI_SIMPLESEARCH_LIMIT; $this->criteria['form']['limit'] = UI_SIMPLESEARCH_LIMIT;
for ($n = 1; $n<=UI_SIMPLESEARCH_ROWS; $n++) { for ($n = 1; $n<=UI_SIMPLESEARCH_ROWS; $n++) {

View file

@ -0,0 +1,14 @@
#!/bin/bash
# param $1: workdir what we would like to tar
# param $2: output file: the .tar file
# param $3: statusfile
date +\=\=\>%Y%m%d\ %H:%M:%S
echo "backup2.sh: create tarball $1 to $2<=="
echo -n "working" > $3;
touch $2 || { echo -n "fail" > $3; exit 1; }
#sleep 120
cd $1
tar cf $2 * || { echo -n "fail" > $3; exit 1; }
echo -n "success" > $3

View file

@ -0,0 +1,407 @@
<?php
define('BACKUP_EXT', 'tar');
define('ACCESS_TYPE', 'backup');
class Backup {
/**
* string - name of logfile
*/
var $logFile;
/**
* string - session id
*/
var $sessid;
/**
* struct - see search criteria
*/
var $criteria;
/**
* string - token
*/
var $token;
/**
* string - name of statusfile
*/
var $statusFile;
/**
* array - affected gunids
*/
var $ids;
/**
* array - array of affected filenames
*/
var $filenames;
/**
* string - base tmp name
*/
var $tmpName;
/**
* stirng - name of temporary tarball file
*/
var $tmpFile;
/**
* string - name of temporary directory
*/
var $tmpDir;
/**
* string - name of temporary playlist directory
*/
var $tmpDirPlaylist;
/**
* string - name of temporary audioclip directory
*/
var $tmpDirClip;
/**
* string - name of temporary metafile directory
*/
var $tmpDirMeta;
/**
* string - loglevel
*/
var $loglevel = 'debug'; # 'debug';
/**
* greenbox object reference
*/
var $gb;
/**
* Constructor
*
* @param gb: greenbox object reference
*/
function Backup (&$gb) {
$this->gb =& $gb;
$this->token = null;
$this->logFile = $this->gb->bufferDir.'/'.ACCESS_TYPE.'.log';
$this->addLogItem("-I- ".date("Ymd-H:i:s")." construct\n");
}
/**
* Open a backup
* Create a backup file (tarball)
*
* @param sessid : string - session id
* @param criteria : struct - see search criteria
* @return hasharray with field:
* token string: backup token
*/
function openBackup($sessid,$criteria='') {
if ($this->loglevel=='debug') {
$this->addLogItem("-I- ".date("Ymd-H:i:s")." openBackup - sessid:$sessid\n");
}
$this->sessid = $sessid;
$this->criteria = $criteria;
# get ids (and real filenames) which files match with criteria
$this->setIDs($this->gb->localSearch($this->criteria,$this->sessid));
#echo '<XMP>this->ids:'; print_r($this->ids); echo '</XMP>';
# get real filenames
if (is_array($this->ids)) {
$this->setFileNames();
#echo '<XMP>this->filenames:'; print_r($this->filenames); echo '</XMP>';
$this->setEnviroment(true);
# write a status file
file_put_contents($this->statusFile, 'working');
# save the metafile to tmpdir
$hostname = trim(`hostname`);
$ctime = time();
file_put_contents("{$this->tmpDirMeta}/storage.xml",
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n".
"<storage\n".
" type=\"".ACCESS_TYPE."\"\n".
" version=\"1.0\"\n".
" ctime=\"$ctime\"\n".
" hostname=\"$hostname\"\n".
"/>\n"
);
# copy all file to tmpdir
$this->copyAllFiles();
# do everything
$this->doIt();
return array('token'=>$this->token);
} else return false;
}
/**
* check the status of backup
*
* @param token : token
* @return hasharray with field:
* status : string - susccess | working | fault
* token : stirng - backup token
* url : string - access url
*/
function checkBackup($token) {
if ($this->loglevel=='debug') {
$this->addLogItem("-I- ".date("Ymd-H:i:s")." checkBackup - token:$token\n");
}
$this->token = $token;
$this->setEnviroment();
$status = file_get_contents($this->statusFile);
switch ($status) {
case 'success':
$r['url'] = $this->gb->getUrlPart()."access/$token.".BACKUP_EXT;
case 'working':
case 'fault':
$r['status'] = $status;
$r['token'] = $token;
break;
}
return $r;
}
/**
* Close a backup
*
* @param token : token
* @return status : boolean
*/
function closeBackup($token) {
if ($this->loglevel=='debug') {
$this->addLogItem("-I- ".date("Ymd-H:i:s")." closeBackup - token:$token\n");
}
# post procedures
$this->token = $token;
$this->setEnviroment();
$this->gb->bsRelease($token,ACCESS_TYPE);
Backup::rRmDir($this->tmpDir);
unlink($this->statusFile);
unlink($this->tmpFile);
if (is_file($this->tmpName)) unlink($this->tmpName);
return !is_file($this->tmpFile);
}
/**
* list of unclosed backups
*
* @param stat : status (optional)
* if this parameter is not set, then return with all unclosed backups
* @return array of hasharray with field:
* status : string - susccess | working | fault
* token : stirng - backup token
* url : string - access url
*/
function listBackups($stat='') {
if ($this->loglevel=='debug') {
$this->addLogItem("-I- ".date("Ymd-H:i:s")." listBackups - stat:$stat\n");
}
# open temporary dir
$tokens = $this->gb->getTokensByType(ACCESS_TYPE);
# echo '<XMP>tokens:'; print_r($tokens); echo '</XMP>';
foreach ($tokens as $token) {
$st = $this->checkBackup($token);
if ($stat=='' || $st['status']==$stat) {
$r[] = $st;
}
}
return $r;
}
/**
* set the ids from searchResult
*
* @param searchResult : array of gunids
*/
function setIDs($searchResult) {
if ($this->loglevel=='debug') {
$this->addLogItem("-I- ".date("Ymd-H:i:s")." setIDs\n");
}
if (is_array($searchResult['results'])) {
$this->ids = $searchResult['results'];
} else {
$this->addLogItem("-E- ".date("Ymd-H:i:s")." setIDs - the parameter is not array!\n");
return PEAR::raiseError('The IDs variable isn\'t array.');
}
}
/**
* set the filenames from ids
*
*/
function setFilenames () {
if ($this->loglevel=='debug') {
$this->addLogItem("-I- ".date("Ymd-H:i:s")." setFilenames\n");
}
if (is_array($this->ids)) {
foreach ($this->ids as $gunid) {
# get a stored file object of this gunid
$sf = $r = StoredFile::recallByGunid($this->gb, $gunid);
if(PEAR::isError($r)) return $r;
$lid = $this->gb->_idFromGunid($gunid);
if(($res = $this->gb->_authorize('read', $lid, $this->sessid)) !== TRUE){
$this->addLogItem("-E- ".date("Ymd-H:i:s")." setFilenames - authorize gunid:$gunid\n");
return PEAR::raiseError('Backup::setFilenames : Authorize ... error.');
}
# if the file is a playlist then it have only meta file
if (strtolower($sf->md->format)!='playlist') {
$this->filenames[] = array(
'filename' => $sf->_getRealRADFname(), # get real filename of raw media data
'format' => $sf->md->format
);
}
$this->filenames[] = array(
'filename' => $sf->_getRealMDFname(), # get real filename of metadata file
'format' => $sf->md->format
);
if ($this->loglevel=='debug') {
$this->addLogItem("-I- ".date("Ymd-H:i:s")." setFilenames - add file: {$sf->md->format}|".$sf->_getRealMDFname()."\n");
}
}
return $this->filenames;
} else {
$this->addLogItem("-E- ".date("Ymd-H:i:s")." setFilenames - The IDs variable isn't array.\n");
return PEAR::raiseError('Backup::setFilenames : The IDs variable isn\'t array.');
}
}
/**
* Create the trackball - call the shell script
*
*/
function doIt() {
if ($this->loglevel=='debug') {
$this->addLogItem("-I- ".date("Ymd-H:i:s")." doIt\n");
}
$command = dirname(__FILE__)."/../bin/backup.sh".
" {$this->tmpDir}".
" {$this->tmpFile}".
" {$this->statusFile}".
" >> {$this->logFile} &";
$res = system("$command");
sleep(2);
if ($this->loglevel=='debug') {
$this->addLogItem("-I- ".date("Ymd-H:i:s")." doIt - command:$command\n");
}
}
/**
* Copy the real files into the tmp dirs to tar they.
*
*/
function copyAllFiles() {
if ($this->loglevel=='debug') {
$this->addLogItem("-I- ".date("Ymd-H:i:s")." copyAllFiles\n");
}
//echo '<XMP>this->filenames:'; print_r($this->filenames); echo '</XMP>';
foreach ($this->filenames as $v) {
# get the filename from full path
$fn = substr($v['filename'],strrpos($v['filename'],'/'));
switch (strtolower($v['format'])) {
case 'playlist':
# if playlist then copy to the playlist dir
copy($v['filename'],$this->tmpDirPlaylist.$fn);
break;
case 'audioclip':
# if audioclip then copy to the audioclip dir
copy($v['filename'],$this->tmpDirClip.$fn);
break;
}
}
}
/**
* Figure out the enviroment to the backup
*
*/
function setEnviroment($createDir=false) {
if ($this->loglevel=='debug') {
$this->addLogItem("-I- ".date("Ymd-H:i:s")." setEnviroment - createDirs:$createDirs\n");
}
# create a temporary directories
if (is_null($this->token) && $createDir) {
$this->tmpName = tempnam($this->gb->bufferDir, ACCESS_TYPE.'_');
$this->tmpFile = $this->tmpName.'.'.BACKUP_EXT;
$this->tmpDir = $this->tmpName.'.dir';
$this->tmpDirPlaylist = $this->tmpDir. '/playlist';
$this->tmpDirClip = $this->tmpDir. '/audioClip';
$this->tmpDirMeta = $this->tmpDir. '/meta-inf';
touch($this->tmpFile);
mkdir($this->tmpDir);
mkdir($this->tmpDirPlaylist);
mkdir($this->tmpDirClip);
mkdir($this->tmpDirMeta);
$this->genToken();
} else {
$symlink = $this->gb->accessDir.'/'.$this->token.'.'.BACKUP_EXT;
if (is_link($symlink) && is_file(readlink($symlink))) {
$this->tmpName = str_replace('.tar','',readlink($symlink));
$this->tmpFile = $this->tmpName.'.'.BACKUP_EXT;
$this->tmpDir = $this->tmpName.'.dir';
$this->tmpDirPlaylist = $this->tmpDir. '/playlist';
$this->tmpDirClip = $this->tmpDir. '/audioClip';
$this->tmpDirMeta = $this->tmpDir. '/meta-inf';
} else {
$this->addLogItem("-E- ".date("Ymd-H:i:s")." setEnviroment - Corrupt symbolic link.\n");
return false;
}
}
$this->statusFile = $this->gb->accessDir.'/'.$this->token.'.'.BACKUP_EXT.'.status';
if ($this->loglevel=='debug') {
$this->addLogItem("this->tmpName: $this->tmpName\n");
$this->addLogItem("this->tmpFile: $this->tmpFile\n");
$this->addLogItem("this->tmpDir: $this->tmpDir\n");
$this->addLogItem("this->tmpDirPlaylist: $this->tmpDirPlaylist\n");
$this->addLogItem("this->tmpDirClip: $this->tmpDirClip\n");
$this->addLogItem("this->tmpDirMeta: $this->tmpDirMeta\n");
$this->addLogItem("this->token: $this->token\n");
$this->addLogItem("this->statusFile: $this->statusFile\n");
}
}
/**
* generate a new token.
*
*/
function genToken() {
$acc = $this->gb->bsAccess($this->tmpFile, BACKUP_EXT, null, ACCESS_TYPE);
if($this->gb->dbc->isError($acc)){ return $acc; }
$this->token = $acc['token'];
}
/**
* Add a line to the logfile.
*
* @param item : string - the new row of log file
*/
function addLogItem($item) {
$f = fopen ($this->logFile,'a');
fwrite($f,$item);
fclose($f);
//echo file_get_contents($this->logFile)."<BR><BR>\n\n";
}
/**
* Delete a directory recursive
*
* @param dirname : string - path of dir.
*/
function rRmDir($dirname) {
if(is_dir($dirname))
$dir_handle = opendir($dirname);
while($file = readdir($dir_handle)) {
if($file!="." && $file!="..") {
if(!is_dir($dirname."/".$file))
unlink ($dirname."/".$file);
else
Backup::rRmDir($dirname."/".$file);
}
}
closedir($dir_handle);
rmdir($dirname);
return true;
}
}
?>

View file

@ -625,6 +625,23 @@ class BasicStor extends Alib{
$owner = $row; $owner = $row;
} }
/**
* Get tokens by type
*
* @param type: string - access|put|render etc.
* @return array - array of tokens
*/
function getTokensByType($type)
{
$res = $this->dbc->query(
"SELECT TO_HEX(token) AS token FROM {$this->accessTable} WHERE type=?",
array($type));
while ($row = $res->fetchRow()) {
$r[] = $row['token'];
}
return $r;
}
/* -------------------------------------------- metadata methods4metadata */ /* -------------------------------------------- metadata methods4metadata */
/** /**

View file

@ -825,6 +825,21 @@ class GreenBox extends BasicStor{
return array('status'=>$r['status'], 'tmpfile'=>$r['tmpfile']); return array('status'=>$r['status'], 'tmpfile'=>$r['tmpfile']);
} }
/**
* Render playlist to ogg file (list results)
*
* @param status : string - success | working | fault
* if this parameter is not set, then return with all unclosed
* @return array of hasharray:
* status : string - susccess | working | fault
* tmpfile : string - filepath to result temporary file
*/
function renderPlaylistToFileList($status='')
{
require_once "Renderer.php";
return Renderer::rnRender2FileList($this, $status);
}
/** /**
* Render playlist to ogg file (close handle) * Render playlist to ogg file (close handle)
* *
@ -911,6 +926,23 @@ class GreenBox extends BasicStor{
); );
} }
/**
* Render playlist to RSS file (list results)
*
* @param status : string - success | working | fault
* @return array of hasharray:
* status : string - susccess | working | fault
* tmpfile : string - filepath to result temporary file
*/
function renderPlaylistToRSSList($status='')
{
$dummytokens = array ('123456789abcdeff');
foreach ($dummytokens as $token) {
$r[] = renderPlaylistToRSSCheck($token);
}
return $r
}
/** /**
* Render playlist to RSS file (close handle) * Render playlist to RSS file (close handle)
* *
@ -935,84 +967,66 @@ class GreenBox extends BasicStor{
/** /**
* Create backup of storage (open handle) * Create backup of storage (open handle)
* *
* @param sessid : string - session id * @param sessid : string - session id
* @param criteria : struct - see search criteria * @param criteria : struct - see search criteria
* @return hasharray: * @return hasharray:
* token : string - backup token * token : string - backup token
*/ */
function createBackupOpen($sessid, $criteria='') function createBackupOpen($sessid, $criteria='')
{ {
$token = '123456789abcdeff'; require_once "Backup.php";
$tmpn = tempnam($this->bufferDir, 'backup_'); $bu = $r = new Backup($this);
$tmpf = "$tmpn.tar"; if (PEAR::isError($r)) return $r;
$tmpd = "$tmpn.dir"; mkdir($tmpd); return $bu->openBackup($sessid,$criteria);
$tmpdp = "$tmpd/playlist"; mkdir($tmpdp);
$tmpdc = "$tmpd/audioClip"; mkdir($tmpdc);
$tmpdm = "$tmpd/meta-inf"; mkdir($tmpdm);
$ctime = time();
// $hostname = $_SERVER['SERVER_NAME'];
$hostname = trim(`hostname`);
file_put_contents("$tmpdm/storage.xml",
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n".
"<storage\n".
" type=\"backup\"\n".
" version=\"1.0\"\n".
" ctime=\"$ctime\"\n".
" hostname=\"$hostname\"\n".
"/>\n"
);
$res = `cd $tmpd; tar cf $tmpf * --remove-files`;
$fakeFile = "{$this->accessDir}/$token.tar";
rename($tmpf, $fakeFile);
//copy($tmpf, $fakeFile);
rmdir($tmpdp); rmdir($tmpdc); rmdir($tmpdm);
rmdir($tmpd); unlink($tmpn);
return array('token'=>$token);
} }
/** /**
* Create backup of storage (check results) * Create backup of storage (check results)
* *
* @param token : string - backup token * @param token : string - backup token
* @return hasharray: * @return hasharray with field:
* status : string - susccess | working | fault * status : string - susccess | working | fault
* tmpfile : string - filepath to result temporary file * token : stirng - backup token
* metafile : string - archive metafile in XML format * url : string - access url
* faultString : string - error message (use only if status==fault)
*/ */
function createBackupCheck($token) function createBackupCheck($token)
{ {
$fakeFile = "{$this->accessDir}/$token.tar"; require_once "Backup.php";
if($token != '123456789abcdeff' || !file_exists($fakeFile)){ $bu = $r = new Backup($this);
return PEAR::raiseError( if (PEAR::isError($r)) return $r;
"LocStor::createBackupCheck: invalid token ($token)" return $bu->checkBackup($token);
); }
}
$status = 'success'; /**
return array( * Create backup of storage (list results)
'status'=> $status, *
'tmpfile' => $fakeFile, * @param stat : status (optional)
'metafile' => '', * if this parameter is not set, then return with all unclosed backups
'faultString' => ($status==fault ? 'backup process fault' : ''), * @return array of hasharray with field:
); * status : string - susccess | working | fault
* token : stirng - backup token
* url : string - access url
*/
function createBackupList($sessid,$stat='')
{
require_once "Backup.php";
$bu = $r = new Backup($this);
if (PEAR::isError($r)) return $r;
return $bu->listBackups($stat);
} }
/** /**
* Create backup of storage (close handle) * Create backup of storage (close handle)
* *
* @param token : string - backup token * @param token : string - backup token
* @return status : boolean * @return status : boolean
*/ */
function createBackupClose($token) function createBackupClose($token)
{ {
if($token != '123456789abcdeff'){ require_once "Backup.php";
return PEAR::raiseError( $bu = $r = new Backup($this);
"LocStor::createBackupClose: invalid token" if (PEAR::isError($r)) return $r;
); return $bu->closeBackup($token);
}
$fakeFile = "{$this->accessDir}/$token.tar";
unlink($fakeFile);
return TRUE;
} }
/* ============================================== methods for preferences */ /* ============================================== methods for preferences */

View file

@ -824,7 +824,7 @@ class LocStor extends BasicStor{
/** /**
* Render playlist to ogg file (close handle) * Render playlist to ogg file (close handle)
* *
* @param token : string - render token * @param token : string - render token
* @return status : boolean * @return status : boolean
*/ */
function renderPlaylistToFileClose($token) function renderPlaylistToFileClose($token)
@ -839,9 +839,9 @@ class LocStor extends BasicStor{
/** /**
* Render playlist to storage media clip (open handle) * Render playlist to storage media clip (open handle)
* *
* @param sessid : string - session id * @param sessid : string - session id
* @param plid : string - playlist gunid * @param plid : string - playlist gunid
* @return token : string - render token * @return token : string - render token
*/ */
function renderPlaylistToStorageOpen($sessid, $plid) function renderPlaylistToStorageOpen($sessid, $plid)
{ {
@ -859,7 +859,7 @@ class LocStor extends BasicStor{
* @param token : string - render token * @param token : string - render token
* @return hasharray: * @return hasharray:
* status : string - success | working | fault * status : string - success | working | fault
* gunid : string - gunid of result file * gunid : string - gunid of result file
*/ */
function renderPlaylistToStorageCheck($token) function renderPlaylistToStorageCheck($token)
{ {
@ -873,9 +873,9 @@ class LocStor extends BasicStor{
/** /**
* Render playlist to RSS file (open handle) * Render playlist to RSS file (open handle)
* *
* @param sessid : string - session id * @param sessid : string - session id
* @param plid : string - playlist gunid * @param plid : string - playlist gunid
* @return token : string - render token * @return token : string - render token
*/ */
function renderPlaylistToRSSOpen($sessid, $plid) function renderPlaylistToRSSOpen($sessid, $plid)
{ {
@ -888,10 +888,10 @@ class LocStor extends BasicStor{
/** /**
* Render playlist to RSS file (check results) * Render playlist to RSS file (check results)
* *
* @param token : string - render token * @param token : string - render token
* @return hasharray: * @return hasharray :
* status : string - success | working | fault * status : string - success | working | fault
* url : string - readable url * url : string - readable url
*/ */
function renderPlaylistToRSSCheck($token) function renderPlaylistToRSSCheck($token)
{ {
@ -911,7 +911,7 @@ class LocStor extends BasicStor{
/** /**
* Render playlist to RSS file (close handle) * Render playlist to RSS file (close handle)
* *
* @param token : string - render token * @param token : string - render token
* @return status : boolean * @return status : boolean
*/ */
function renderPlaylistToRSSClose($token) function renderPlaylistToRSSClose($token)
@ -932,84 +932,66 @@ class LocStor extends BasicStor{
/** /**
* Create backup of storage (open handle) * Create backup of storage (open handle)
* *
* @param sessid : string - session id * @param sessid : string - session id
* @param criteria : struct - see search criteria * @param criteria : struct - see search criteria
* @return token : string - backup token * @return hasharray:
* token : string - backup token
*/ */
function createBackupOpen($sessid, $criteria) function createBackupOpen($sessid, $criteria='')
{ {
$token = '123456789abcdeff'; require_once "Backup.php";
$tmpn = tempnam($this->bufferDir, 'backup_'); $bu = $r = new Backup($this);
$tmpf = "$tmpn.tar"; if (PEAR::isError($r)) return $r;
$tmpd = "$tmpn.dir"; mkdir($tmpd); return $bu->openBackup($sessid,$criteria);
$tmpdp = "$tmpd/playlist"; mkdir($tmpdp);
$tmpdc = "$tmpd/audioClip"; mkdir($tmpdc);
$tmpdm = "$tmpd/meta-inf"; mkdir($tmpdm);
$ctime = time();
// $hostname = $_SERVER['SERVER_NAME'];
$hostname = trim(`hostname`);
file_put_contents("$tmpdm/storage.xml",
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n".
"<storage\n".
" type=\"backup\"\n".
" version=\"1.0\"\n".
" ctime=\"$ctime\"\n".
" hostname=\"$hostname\"\n".
"/>\n"
);
$res = `cd $tmpd; tar cf $tmpf * --remove-files`;
$fakeFile = "{$this->accessDir}/$token.tar";
rename($tmpf, $fakeFile);
//copy($tmpf, $fakeFile);
rmdir($tmpdp); rmdir($tmpdc); rmdir($tmpdm);
rmdir($tmpd); unlink($tmpn);
return array('token'=>$token);
} }
/** /**
* Create backup of storage (check results) * Create backup of storage (check results)
* *
* @param token : string - backup token * @param token : string - backup token
* @return hasharray: * @return hasharray with field:
* status : string - success | working | fault * status : string - susccess | working | fault
* url : string - readable url * token : stirng - backup token
* metafile : string - archive metafile in XML format * url : string - access url
* faultString : string - error message (use only if status==fault)
*/ */
function createBackupCheck($token) function createBackupCheck($token)
{ {
$fakeFile = "{$this->accessDir}/$token.tar"; require_once "Backup.php";
if($token != '123456789abcdeff' || !file_exists($fakeFile)){ $bu = $r = new Backup($this);
return PEAR::raiseError( if (PEAR::isError($r)) return $r;
"LocStor::createBackupCheck: invalid token ($token)" return $bu->checkBackup($token);
); }
}
$fakeFUrl = $this->getUrlPart()."access/$token.tar"; /**
$status = 'success'; * Create backup of storage (list results)
return array( *
'status'=> $status, * @param stat : status (optional)
'url' => $fakeFUrl, * if this parameter is not set, then return with all unclosed backups
'metafile' => '', * @return array of hasharray with field:
'faultString' => ($status==fault ? 'backup process fault' : ''), * status : string - susccess | working | fault
); * token : stirng - backup token
* url : string - access url
*/
function createBackupList($sessid,$stat='')
{
require_once "Backup.php";
$bu = $r = new Backup($this);
if (PEAR::isError($r)) return $r;
return $bu->listBackups($stat);
} }
/** /**
* Create backup of storage (close handle) * Create backup of storage (close handle)
* *
* @param token : string - backup token * @param token : string - backup token
* @return status : boolean * @return status : boolean
*/ */
function createBackupClose($token) function createBackupClose($token)
{ {
if($token != '123456789abcdeff'){ require_once "Backup.php";
return PEAR::raiseError( $bu = $r = new Backup($this);
"LocStor::createBackupClose: invalid token" if (PEAR::isError($r)) return $r;
); return $bu->closeBackup($token);
}
$fakeFile = "{$this->accessDir}/$token.tar";
unlink($fakeFile);
return TRUE;
} }
/*===================================================== auxiliary methods */ /*===================================================== auxiliary methods */

View file

@ -41,6 +41,7 @@ require_once "LsPlaylist.php";
* @version $Revision: 1949 $ * @version $Revision: 1949 $
* @see LocStor * @see LocStor
*/ */
class Renderer class Renderer
{ {
@ -115,6 +116,28 @@ class Renderer
return array('status'=>$status, 'url'=>$url, 'tmpfile'=>$tmpfile); return array('status'=>$status, 'url'=>$url, 'tmpfile'=>$tmpfile);
} }
/**
* Render playlist to ogg file (list results)
*
* @param gb: greenbox object reference
* @param stat : status (optional)
* if this parameter is not set, then return with all unclosed backups
* @return array of hasharray:
* status : string - success | working | fault
* url : string - readable url
*/
function rnRender2FileList(&$gb,$stat='') {
# open temporary dir
$tokens = $gb->getTokensByType('render');
foreach ($tokens as $token) {
$st = Renderer::rnRender2FileCheck($gb, $token);
if ($stat=='' || $st['status']==$stat) {
$r[] = $st;
}
}
return $r;
}
/** /**
* Render playlist to ogg file (close handle) * Render playlist to ogg file (close handle)
* *

View file

@ -1837,6 +1837,56 @@ class XR_LocStor extends LocStor{
return new XML_RPC_Response(XML_RPC_encode($res)); return new XML_RPC_Response(XML_RPC_encode($res));
} }
/**
* Create backup of storage (list results)
*
* The XML-RPC name of this method is "locstor.createBackupList".
*
* The input parameters are an XML-RPC struct with the following
* fields:
* <ul>
* <li> stat : string - backup status </li>
* </ul>
*
* On success, returns a XML-RPC array of struct with following fields:
* <ul>
* <li> status : string - success | working | fault</li>
* <li> url : string - readable url</li>
* <li> metafile : string - archive metafile in XML format</li>
* <li> faultString : string - error message
* (use only if status==fault) </li>
* </ul>
*
* On errors, returns an XML-RPC error response.
* The possible error codes and error message are:
* <ul>
* <li> 3 - Incorrect parameters passed to method:
* Wanted ... , got ... at param </li>
* <li> 801 - wrong 1st parameter, struct expected.</li>
* <li> 805 - xr_createBackupCheck:
* &lt;message from lower layer&gt; </li>
* </ul>
*
* @param input XMLRPC struct
* @return XMLRPC struct
* @see LocStor::createBackupCheck
*/
// <li> 854 - backup process fault</li>
function xr_createBackupList($stat='')
{
$res = $this->createBackupList($stat);
if(PEAR::isError($res)){
$ec0 = intval($res->getCode());
$ec = ($ec0 == GBERR_BGERR ? 800+$ec0 : 805 );
return new XML_RPC_Response(0, $ec,
"xr_createBackupCheck: ".$res->getMessage().
" ".$res->getUserInfo()
);
}
return new XML_RPC_Response(XML_RPC_encode($res));
}
/** /**
* Create backup of storage (close handle) * Create backup of storage (close handle)
* *