14 include_once (
"FDL/Class.Doc.php");
 
   15 include_once (
"WHAT/Class.SessionUtils.php");
 
   20 $usage->setDefinitionText(
"Clean base");
 
   21 $real = (
$usage->addHiddenParameter(
"real", 
"real (yes or no)") == 
"yes");
 
   22 $full = (
$usage->addEmptyParameter(
"full", 
"clean also obsolete permission, log, folder contains"));
 
   32     print "Database not found : action->dbaccess";
 
   46     print "Full clean.\n";
 
   49     print "Basic clean.\n";
 
   65     $tmpScript = tempnam($tmpDir, 
$prefix);
 
   66     if ($tmpScript === 
false) {
 
   67         throw new Exception(sprintf(
"Error creating temporary file in '%s'.", $tmpDir));
 
   69     if (file_put_contents($tmpScript, $script) === 
false) {
 
   70         throw new Exception(sprintf(
"Error writing to temporary file '%s'.", $tmpScript));
 
   77     $sqlDir = implode(DIRECTORY_SEPARATOR, array(
 
   82     if (($fh = opendir($sqlDir)) === 
false) {
 
   83         throw new Exception(sprintf(
"Error opening directory '%s'", $sqlDir));
 
   86     while ((
$file = readdir($fh)) !== 
false) {
 
   90         if (preg_match(sprintf(
'/^%s_.*\.sql$/', preg_quote(
$prefix)) , 
$file) !== 1) {
 
   93         $files[] = implode(DIRECTORY_SEPARATOR, array(
 
   98     uasort($files, 
function (
$a, $b)
 
  100         return strcmp(
$a, $b);
 
  110 PGSERVICE=%s psql --set ON_ERROR_STOP=1 -c 
'\timing' -a -f %s 2>&1 | logger -s -
t %s
 
  111 exit ${PIPESTATUS[0]}
 
  113     $script = sprintf($script, escapeshellarg($pgService) , escapeshellarg($sqlFile) , escapeshellarg(
"cleanContext(" . $action->GetParam(
"CORE_CLIENT") . 
")"));
 
  117     exec(sprintf(
"bash %s 2>&1", escapeshellarg($tmpScript)) , 
$out, 
$ret);
 
  120         throw new Exception(sprintf(
"Error executing SQL file '%s': %s", $sqlFile, join(
"\n", 
$out)));
 
  129     foreach ($sqlFiles as $sqlFile) {
 
  131             printf(
"Executing '%s': ", $sqlFile);
 
  135         catch(\Exception $e) {
 
  136             printf(
"[ERROR]\n%s\n", $e->getMessage());
 
  137             $errors[] = $e->getMessage();
 
  140     if (count($errors) > 0) {
 
  141         throw new Exception(sprintf(
"Errors:\n%s\n", join(
"\n", $errors)));
 
  161         echo sprintf(
"Error: Yikes! we got an empty pubdir?");
 
  165     $maxAge = $action->GetParam(
'CORE_TMPDIR_MAXAGE', 
'');
 
  167         echo sprintf(
"Error: empty CORE_TMPDIR_MAXAGE parameter.");
 
  171     if (!is_numeric($maxAge)) {
 
  172         echo sprintf(
"Error: found non-numeric value '%s' for CORE_TMPDIR_MAXAGE.", $maxAge);
 
  178         echo sprintf(
"Error: empty directory returned by getTmpDir().");
 
  208     $cmd = sprintf(
'find %s -type f -mtime +%s -print0 | xargs -0 --no-run-if-empty rm', escapeshellarg(
$dir) , $maxAge);
 
  211         return sprintf(
"Error: removal of old files from '%s' returned with error: %s", 
$dir, join(
"\n", $output));
 
  214     $cmd = sprintf(
'find %s -type d -empty -mtime +%s -print0 | xargs -0 --no-run-if-empty rmdir', escapeshellarg(
$dir) , $maxAge);
 
  217         return sprintf(
"Error: removal of empty temporary directories from '%s' returned with error: %s", 
$dir, join(
"\n", $output));
 
  228     if (!is_int($days) && !ctype_digit($days)) {
 
  235 -- Delete expired temporary documents
 
  236 DELETE FROM doc WHERE doctype = 
'T' AND cdate < (now() - INTERVAL 
'%d day');
 
  238 -- Delete lingering dochisto entries of temporary documents
 
  239 DELETE FROM dochisto WHERE 
id >= 1000000000 AND NOT EXISTS (SELECT 1 FROM doc WHERE doc.id = dochisto.id);
 
  241 -- Reset temporary 
id sequence to MAX(
id) of temporary documents
 
  242 SELECT SETVAL(
'seq_id_tdoc', (SELECT COALESCE(MAX(
id), 1000000000) FROM doc WHERE doctype = 
'T'));
 
  250     catch(\Exception $e) {
 
  251         printf(
"Error: removal of expired temporary documents returned with error: %s\n", $e->getMessage());
 
static getDate($daydelta=0, $dayhour="", $daymin="", $getlocale=false)
 
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
 
if($dbaccess=="") $duration
 
static destroyTmpFiles($dayInterval=2)
 
static getParameterValue($application, $parameterName)
 
execSqlFile(Action &$action, $sqlFile)
 
foreach($argv as $arg) $cmd
 
getServiceName($dbaccess)
 
basicDbClean(Action &$action)
 
fullDbClean(Action &$action)
 
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
 
mkTmpScript($script, $prefix)
 
cleanOldFiles($dir, $maxAge)
 
Verify arguments for wsh programs. 
 
execSqlFiles(Action &$action, $prefix)