2016-05-21 21:26:24 +02:00
|
|
|
#!/usr/bin/php
|
2015-07-29 20:31:48 +02:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* handles maintance jobs
|
2016-05-21 21:26:51 +02:00
|
|
|
* should be called on regular basis by cron or something similar
|
2015-07-29 20:31:48 +02:00
|
|
|
* should only be executable by php cli
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (php_sapi_name() !== 'cli') {
|
2016-05-23 11:55:34 +02:00
|
|
|
throw new Exception('cron.php must be called by php-cli');
|
2015-07-29 20:31:48 +02:00
|
|
|
}
|
|
|
|
|
2015-08-23 06:18:05 +02:00
|
|
|
require_once 'classes/poll.php';
|
2016-08-19 00:23:49 +02:00
|
|
|
require_once 'utils/get-config.php';
|
|
|
|
|
2020-01-31 20:22:22 +01:00
|
|
|
$basePath = substr($argv[0], 0, -8);
|
|
|
|
$config = getConfig($basePath);
|
|
|
|
|
|
|
|
// Data directory could be provided as first argument. If not, the configured one should be used.
|
|
|
|
// The configured data dir could be either an absolute or a relative path.
|
|
|
|
$defaultDataDir = $config['dataDir'][0] === '/' ? $config['dataDir'] : $basePath . $config['dataDir'];
|
|
|
|
define('DATA_FOLDER', isset($argv[1]) ? $argv[1] : $defaultDataDir);
|
2015-07-29 20:31:48 +02:00
|
|
|
|
2015-08-23 06:18:05 +02:00
|
|
|
$startTime = time();
|
|
|
|
$pollsProcessed = 0;
|
2015-07-29 20:31:48 +02:00
|
|
|
|
2015-08-23 06:18:05 +02:00
|
|
|
$dataDirHandler = opendir(DATA_FOLDER);
|
|
|
|
if(!$dataDirHandler) {
|
|
|
|
throw new Exception('could not open data dir');
|
2015-07-29 20:31:48 +02:00
|
|
|
}
|
|
|
|
|
2015-08-23 06:18:05 +02:00
|
|
|
while(false !== ($pollId = readdir($dataDirHandler))) {
|
2015-07-29 20:31:48 +02:00
|
|
|
if(
|
2015-08-23 06:18:05 +02:00
|
|
|
$pollId === '.' ||
|
|
|
|
$pollId === '..' ||
|
|
|
|
!is_dir(DATA_FOLDER . $pollId)
|
2015-07-29 20:31:48 +02:00
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-08-23 06:18:05 +02:00
|
|
|
// if expiration date is exceeded
|
|
|
|
// poll gets deleted on restore
|
|
|
|
$poll = Poll::restore($pollId);
|
|
|
|
unset($poll);
|
2015-07-29 20:31:48 +02:00
|
|
|
|
2015-08-23 06:18:05 +02:00
|
|
|
$pollsProcessed ++;
|
2015-07-29 20:31:48 +02:00
|
|
|
}
|
|
|
|
|
2015-08-23 06:18:05 +02:00
|
|
|
echo "Notice: run " . ( time() - $startTime ) . " seconds\n";
|
|
|
|
echo "Notice: processed " . $pollsProcessed . " polls\n";
|