Sindbad~EG File Manager
<?php
/*
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2007 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
/**
* A collection of useful maintenance related methods
* @package GalleryCore
* @subpackage Helpers
* @author Bharat Mediratta <bharat@menalto.com>
* @version $Revision: 15513 $
* @static
*/
class MaintenanceHelper_simple {
/**
* Fetch all the available maintenance tasks
* @return array object GalleryStatus a status code
* array(taskId => object MaintenanceTask, ...)
*/
function fetchTasks() {
/* Get all the option plugins */
list ($ret, $allTaskIds) =
GalleryCoreApi::getAllFactoryImplementationIds('MaintenanceTask');
if ($ret) {
return array($ret, null);
}
$taskInstances = array();
foreach (array_keys($allTaskIds) as $taskId) {
list ($ret, $task) = GalleryCoreApi::newFactoryInstanceById('MaintenanceTask', $taskId);
if ($ret) {
return array($ret, null);
}
$taskInstances[$taskId] = $task;
}
return array(null, $taskInstances);
}
/**
* Return information about the last run of this task.
*
* @param string $taskId
* @return array object GalleryStatus a status code
* array(runId => int,
* timestamp => int,
* success => bool,
* details => string)
*/
function fetchLastRun($taskId) {
list ($ret, $searchResults) = GalleryCoreApi::getMapEntry('GalleryMaintenanceMap',
array('runId', 'timestamp', 'success', 'details'), array('taskId' => $taskId),
array('orderBy' => array('timestamp' => ORDER_DESCENDING),
'limit' => array('count' => 1)));
if ($ret) {
return array($ret, null);
}
$result = $searchResults->nextResult();
$info = null;
if ($searchResults->resultCount() == 1) {
$info = array('runId' => $result[0],
'timestamp' => (int)$result[1],
'success' => (bool)$result[2],
'details' => unserialize($result[3]));
}
return array(null, $info);
}
/**
* Add a new task run to the maintenance map.
*
* @param string $taskId
* @param int $timestamp when the run happened
* @param bool $success task success/failure
* @param array $details string task details
* @return object GalleryStatus a status code
*/
function addRun($taskId, $timestamp, $success, $details) {
global $gallery;
$storage =& $gallery->getStorage();
list ($ret, $runId) = $storage->getUniqueId();
if ($ret) {
return $ret;
}
$ret = GalleryCoreApi::addMapEntry(
'GalleryMaintenanceMap',
array('runId' => $runId,
'taskId' => $taskId,
'timestamp' => $timestamp,
'success' => (int)$success,
'details' => serialize($details)));
if ($ret) {
return $ret;
}
return null;
}
}
?>
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists