many comments of last pull request applied

This commit is contained in:
jygaulier
2012-05-10 14:15:47 +02:00
parent 00df363964
commit 37adb06965
22 changed files with 686 additions and 837 deletions

View File

@@ -3,7 +3,7 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -20,16 +20,12 @@ use Symfony\Component\Console\Output\OutputInterface;
class task_Scheduler
{
const TASKDELAYTOQUIT = 60;
// how to schedule tasks (choose in 'run' method)
const METHOD_FORK = 'METHOD_FORK';
const METHOD_PROC_OPEN = 'METHOD_PROC_OPEN';
const ERR_ALREADY_RUNNING = 114; // aka EALREADY (Operation already in progress)
private $method;
private $input;
protected $output;
protected function log($message)
@@ -47,6 +43,7 @@ class task_Scheduler
if ($this->input && ! ($this->input->getOption('nolog'))) {
file_put_contents($logdir . "scheduler_l.log", $message . "\n", FILE_APPEND);
}
return $this;
}
@@ -55,7 +52,7 @@ class task_Scheduler
return appbox::get_instance(\bootstrap::getCore())->get_connection();
}
public function run($input=null, OutputInterface $output = null) //, $log = true, $log_tasks = true)
public function run($input=null, OutputInterface $output = null)
{
require_once dirname(__FILE__) . '/../../bootstrap.php';
$this->input = $input;
@@ -134,7 +131,7 @@ class task_Scheduler
if ( ! $task->getPID()) {
/* @var $task task_abstract */
$task->resetCrashCounter();
$task->setState(task_abstract::STATUS_TOSTART);
$task->setState(task_abstract::STATE_TOSTART);
}
}
}
@@ -313,7 +310,7 @@ class task_Scheduler
$this->log(sprintf('Unknow status `%s`', $status));
break;
case task_abstract::STATUS_TORESTART:
case task_abstract::STATE_TORESTART:
if ( ! $taskPoll[$tkey]['task']->getPID()) {
if ($this->method == self::METHOD_PROC_OPEN) {
@fclose($taskPoll[$tkey]["pipes"][1]);
@@ -323,7 +320,7 @@ class task_Scheduler
$taskPoll[$tkey]["process"] = null;
}
if ($schedstatus == 'started') {
$taskPoll[$tkey]["task"]->setState(task_abstract::STATUS_TOSTART);
$taskPoll[$tkey]["task"]->setState(task_abstract::STATE_TOSTART);
}
// trick to start the task immediatly : DON'T break if ending with 'tostart'
// so it will continue with 'tostart' case !
@@ -331,7 +328,7 @@ class task_Scheduler
break;
}
case task_abstract::STATUS_TOSTART:
case task_abstract::STATE_TOSTART:
// if scheduler is 'tostop', don't launch a new task !
if ($schedstatus != 'started')
break;
@@ -384,21 +381,17 @@ class task_Scheduler
);
if ($taskPoll[$tkey]["task"]->getCrashCounter() > 5)
$taskPoll[$tkey]["task"]->setState(task_abstract::STATUS_STOPPED);
$taskPoll[$tkey]["task"]->setState(task_abstract::STATE_STOPPED);
else
$taskPoll[$tkey]["task"]->setState(task_abstract::STATUS_TOSTART);
$taskPoll[$tkey]["task"]->setState(task_abstract::STATE_TOSTART);
}
}
}
elseif ($this->method == self::METHOD_FORK) {
// printf("forking pid %d\n", getmypid());
$pid = pcntl_fork();
if ($pid == -1) {
die("failed to fork");
} elseif ($pid == 0) {
// child
// printf("hello i am child pid=%d\n", getmypid());
// printf("%s %s \n", $taskPoll[$tkey]["cmd"], implode(' ', $taskPoll[$tkey]["args"]));
umask(0);
if (posix_setsid() < 0)
die("Forked process could not detach from terminal\n");
@@ -413,25 +406,18 @@ class task_Scheduler
$this->log(sprintf("exec('%s %s')", $taskPoll[$tkey]["cmd"], implode(' ', $taskPoll[$tkey]["args"])));
pcntl_exec($taskPoll[$tkey]["cmd"], $taskPoll[$tkey]["args"]);
}
else {
// parent
// sleep(2);
}
}
break;
case task_abstract::STATUS_STARTED:
case task_abstract::STATE_STARTED:
$crashed = false;
// If no process, the task is probably manually ran
if ($this->method == self::METHOD_PROC_OPEN) {
// printf("=== %d ===\n", __LINE__);
if ($taskPoll[$tkey]["process"]) {
// printf("=== %d ===\n", __LINE__);
$taskPoll[$tkey]["killat"] = NULL;
if (is_resource($taskPoll[$tkey]["process"])) {
// printf("=== %d ===\n", __LINE__);
$proc_status = proc_get_status($taskPoll[$tkey]["process"]);
if ($proc_status['running'])
$runningtask ++;
@@ -439,14 +425,12 @@ class task_Scheduler
$crashed = true;
}
else {
// printf("=== %d ===\n", __LINE__);
$crashed = true;
}
}
}
if ( ! $crashed && ! $taskPoll[$tkey]['task']->getPID()) {
// printf("=== %d ===\n", __LINE__);
$crashed = true;
}
@@ -454,7 +438,6 @@ class task_Scheduler
$taskPoll[$tkey]["killat"] = NULL;
$runningtask ++;
} else {
// printf("=== %d ===\n", __LINE__);
// crashed !
$taskPoll[$tkey]["task"]->incrementCrashCounter();
@@ -473,13 +456,13 @@ class task_Scheduler
);
if ($taskPoll[$tkey]["task"]->getCrashCounter() > 5)
$taskPoll[$tkey]["task"]->setState(task_abstract::STATUS_STOPPED);
$taskPoll[$tkey]["task"]->setState(task_abstract::STATE_STOPPED);
else
$taskPoll[$tkey]["task"]->setState(task_abstract::STATUS_TOSTART);
$taskPoll[$tkey]["task"]->setState(task_abstract::STATE_TOSTART);
}
break;
case task_abstract::STATUS_TOSTOP:
case task_abstract::STATE_TOSTOP:
if ($taskPoll[$tkey]["killat"] === NULL)
$taskPoll[$tkey]["killat"] = time() + self::TASKDELAYTOQUIT;
@@ -525,13 +508,6 @@ class task_Scheduler
)
);
}
/*
unlink($lockdir . 'task_' . $taskPoll[$tkey]['task']->getID() . '.lock');
$taskPoll[$tkey]["task"]->incrementCrashCounter();
// $taskPoll[$tkey]["task"]->set_pid(null);
$taskPoll[$tkey]["task"]->setState(task_abstract::STATUS_STOPPED);
*/
} else {
$this->log(
sprintf(
@@ -549,13 +525,13 @@ class task_Scheduler
, $taskPoll[$tkey]["task"]->getID()
)
);
$taskPoll[$tkey]["task"]->setState(task_abstract::STATUS_STOPPED);
$taskPoll[$tkey]["task"]->setState(task_abstract::STATE_STOPPED);
}
break;
case task_abstract::STATUS_STOPPED:
case task_abstract::STATUS_TODELETE:
case task_abstract::STATE_STOPPED:
case task_abstract::STATE_TODELETE:
if ($this->method == self::METHOD_PROC_OPEN) {
if ($taskPoll[$tkey]["process"]) {
@fclose($taskPoll[$tkey]["pipes"][1]);

View File

@@ -5,12 +5,12 @@ abstract class task_abstract
const LAUCHED_BY_BROWSER = 1;
const LAUCHED_BY_COMMANDLINE = 2;
const STATUS_TOSTOP = 'tostop';
const STATUS_STARTED = 'started';
const STATUS_TOSTART = 'tostart';
const STATUS_TORESTART = 'torestart';
const STATUS_STOPPED = 'stopped';
const STATUS_TODELETE = 'todelete';
const STATE_TOSTOP = 'tostop';
const STATE_STARTED = 'started';
const STATE_TOSTART = 'tostart';
const STATE_TORESTART = 'torestart';
const STATE_STOPPED = 'stopped';
const STATE_TODELETE = 'todelete';
const RUNNER_MANUAL = 'manual';
const RUNNER_SCHEDULER = 'scheduler';
@@ -24,7 +24,6 @@ abstract class task_abstract
const ERR_ALREADY_RUNNING = 114; // aka EALREADY (Operation already in progress)
protected $suicidable = false;
protected $launched_by = 0;
/**
@@ -75,11 +74,8 @@ abstract class task_abstract
* @var <type>
*/
protected $maxmegs;
protected $runner;
private $input;
private $output;
/**
@@ -88,25 +84,15 @@ abstract class task_abstract
* @var <type>
*/
protected $title;
protected $settings;
protected $crash_counter;
protected $status;
protected $active;
protected $debug = false;
protected $completed_percentage;
protected $period = 60;
protected $taskid = NULL;
protected $system = ''; // "DARWIN", "WINDOWS" , "LINUX"...
protected $argt = array(
"--help" => array("set" => false, "values" => array(), "usage" => " (no help available)")
);
@@ -114,13 +100,14 @@ abstract class task_abstract
public function getState()
{
$conn = connection::getPDOConnection();
$sql = 'SELECT status FROM task2 WHERE task_id = :taskid LIMIT 1';
$sql = 'SELECT status FROM task2 WHERE task_id = :taskid';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':taskid' => $this->taskid));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ( ! $row)
throw new Exception('Unknown task id');
return $row['status'];
}
@@ -142,12 +129,12 @@ abstract class task_abstract
public function setState($status)
{
$av_status = array(
self::STATUS_STARTED
, self::STATUS_TOSTOP
, self::STATUS_STOPPED
, self::STATUS_TORESTART
, self::STATUS_TOSTART
, self::STATUS_TODELETE
self::STATE_STARTED
, self::STATE_TOSTOP
, self::STATE_STOPPED
, self::STATE_TORESTART
, self::STATE_TOSTART
, self::STATE_TODELETE
);
if ( ! in_array($status, $av_status)) {
@@ -293,7 +280,7 @@ abstract class task_abstract
return('');
}
$sql = 'SELECT crashed, pid, status, active, settings, name, completed, runner
FROM task2 WHERE task_id = :taskid LIMIT 1';
FROM task2 WHERE task_id = :taskid';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':taskid' => $this->getID()));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
@@ -394,6 +381,7 @@ abstract class task_abstract
}
fclose($fd);
}
return $pid;
}
@@ -408,13 +396,10 @@ abstract class task_abstract
if ($this->running) {// && $this->records_done == 0)
$when_started = time() - $when_started;
if ($when_started < $this->period) {
// $conn = connection::getPDOConnection();
// $conn->close();
// unset($conn);
for ($t = $this->period - $when_started; $this->running && $t > 0; $t -- ) { // DON'T do sleep($this->period - $when_started) because it prevents ticks !
$s = $this->getState();
if ($s == self::STATUS_TOSTOP) {
$this->setState(self::STATUS_STOPPED);
if ($s == self::STATE_TOSTOP) {
$this->setState(self::STATE_STOPPED);
$this->running = FALSE;
} else {
sleep(1);
@@ -456,7 +441,7 @@ abstract class task_abstract
flock($tasklock, LOCK_SH);
$this->setRunner($runner);
$this->setState(self::STATUS_STARTED);
$this->setState(self::STATE_STARTED);
// run the real code of the task -into the task's class- (may throw an exception)
$exception = NULL;
@@ -473,11 +458,11 @@ abstract class task_abstract
@unlink($lockfile);
switch ($this->getState()) {
case self::STATUS_TODELETE:
case self::STATE_TODELETE:
$this->delete();
break;
case self::STATUS_TOSTOP:
$this->setState(self::STATUS_STOPPED);
case self::STATE_TOSTOP:
$this->setState(self::STATE_STOPPED);
break;
}
@@ -509,8 +494,7 @@ abstract class task_abstract
{
if ($this->getRunner() == self::RUNNER_SCHEDULER && ++ $this->loop >= $this->maxloops) {
$this->log(sprintf(('%d loops done, restarting'), $this->loop));
$this->setState(self::STATUS_TORESTART);
// $this->return_xxxvalue = self::RETURNSTATUS_TORESTART;
$this->setState(self::STATE_TORESTART);
$this->running = false;
}
@@ -529,7 +513,6 @@ abstract class task_abstract
$lastt = $t;
echo "\n" . memory_get_usage() . " -- " . memory_get_usage(true) . "\n";
// print($s);
}
public function log($message)
@@ -609,7 +592,6 @@ abstract class task_abstract
return($t);
}
public function getID()
{
return $this->taskid;

View File

@@ -34,8 +34,10 @@ abstract class task_appboxAbstract extends task_abstract
if ($this->getRunner() == self::RUNNER_SCHEDULER) {
$this->log(("Warning : abox connection lost, restarting in 10 min."));
for ($t = 60 * 10; $this->running && $t; $t -- ) // DON'T do sleep(600) because it prevents ticks !
// DON'T do sleep(600) because it prevents ticks !
for ($t = 60 * 10; $this->running && $t; $t -- ) {
sleep(1);
}
// because connection is lost we cannot change status to 'torestart'
// anyway the current status 'running' with no pid
// will enforce the scheduler to restart the task
@@ -50,7 +52,7 @@ abstract class task_appboxAbstract extends task_abstract
$this->setLastExecTime();
try {
$sql = 'SELECT task2.* FROM task2 WHERE task_id = :taskid LIMIT 1';
$sql = 'SELECT settings FROM task2 WHERE task_id = :taskid';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':taskid' => $this->getID()));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
@@ -82,18 +84,18 @@ abstract class task_appboxAbstract extends task_abstract
case self::STATE_MAXMEGSREACHED:
case self::STATE_MAXRECSDONE:
if ($this->getRunner() == self::RUNNER_SCHEDULER) {
$this->setState(self::STATUS_TORESTART);
$this->setState(self::STATE_TORESTART);
$this->running = FALSE;
}
break;
case self::STATUS_TOSTOP:
$this->setState(self::STATUS_TOSTOP);
case self::STATE_TOSTOP:
$this->setState(self::STATE_TOSTOP);
$this->running = FALSE;
break;
case self::STATUS_TODELETE: // formal 'suicidable'
$this->setState(self::STATUS_TODELETE);
case self::STATE_TODELETE: // formal 'suicidable'
$this->setState(self::STATE_TODELETE);
$this->running = FALSE;
break;
@@ -164,9 +166,9 @@ abstract class task_appboxAbstract extends task_abstract
// $this->check_task_status();
try {
$status = $this->getState();
if ($status == self::STATUS_TOSTOP) {
if ($status == self::STATE_TOSTOP) {
$this->running = FALSE;
$ret = self::STATUS_TOSTOP;
$ret = self::STATE_TOSTOP;
}
} catch (Exception $e) {
$this->running = FALSE;
@@ -174,11 +176,11 @@ abstract class task_appboxAbstract extends task_abstract
if ( ! $this->running)
break;
} // foreach($rs as $row)
}
//
// if nothing was done, at least check the status
if (count($rs) == 0 && $this->running) {
// $this->check_memory_usage();
$current_memory = memory_get_usage();
if ($current_memory >> 20 >= $this->maxmegs) {
$this->log(sprintf("Max memory (%s M) reached (current is %s M)", $this->maxmegs, $current_memory));
@@ -192,12 +194,11 @@ abstract class task_appboxAbstract extends task_abstract
$ret = self::STATE_MAXRECSDONE;
}
// $this->check_task_status();
try {
$status = $this->getState();
if ($status == self::STATUS_TOSTOP) {
if ($status == self::STATE_TOSTOP) {
$this->running = FALSE;
$ret = self::STATUS_TOSTOP;
$ret = self::STATE_TOSTOP;
}
} catch (Exception $e) {
$this->running = FALSE;

View File

@@ -37,13 +37,15 @@ abstract class task_databoxAbstract extends task_abstract
while ($this->running) {
try {
$conn = connection::getPDOConnection();
} catch (Exception $e) {
} catch (PDOException $e) {
$this->log($e->getMessage());
if ($this->getRunner() == self::RUNNER_SCHEDULER) {
$this->log(("Warning : abox connection lost, restarting in 10 min."));
for ($t = 60 * 10; $this->running && $t; $t -- ) // DON'T do sleep(600) because it prevents ticks !
// DON'T do sleep(600) because it prevents ticks !
for ($t = 60 * 10; $this->running && $t; $t -- ) {
sleep(1);
}
// because connection is lost we cannot change status to 'torestart'
// anyway the current status 'running' with no pid
// will enforce the scheduler to restart the task
@@ -51,6 +53,7 @@ abstract class task_databoxAbstract extends task_abstract
// runner = manual : can't restart so simply quit
}
$this->running = FALSE;
return;
}
@@ -91,27 +94,22 @@ abstract class task_databoxAbstract extends task_abstract
$process_ret = $this->processSbas();
// printf("%s (%d) process_ret=%s \n", __FILE__, __LINE__, var_export($process_ret, true));
// $this->check_current_xxxstate();
switch ($process_ret) {
case self::STATE_MAXMEGSREACHED:
case self::STATE_MAXRECSDONE:
if ($this->getRunner() == self::RUNNER_SCHEDULER) {
$this->setState(self::STATUS_TORESTART);
$this->setState(self::STATE_TORESTART);
$this->running = FALSE;
}
break;
case self::STATUS_TOSTOP:
$this->setState(self::STATUS_TOSTOP);
case self::STATE_TOSTOP:
$this->setState(self::STATE_TOSTOP);
$this->running = FALSE;
break;
case self::STATUS_TODELETE: // formal 'suicidable'
case self::STATE_TODELETE: // formal 'suicidable'
// DO NOT SUICIDE IN THE LOOP, may have to work on other sbas !!!
// $this->setState(self::STATUS_TODELETE);
// $this->log('task will self delete');
// $this->running = FALSE;
$task_must_delete = TRUE;
break;
@@ -120,16 +118,17 @@ abstract class task_databoxAbstract extends task_abstract
}
$this->flushRecordsSbas();
} // foreach sbas
}
$this->incrementLoops();
$this->pause($duration);
} // while($this->running)
}
if ($task_must_delete) {
$this->setState(self::STATUS_TODELETE);
$this->setState(self::STATE_TODELETE);
$this->log('task will self delete');
}
return;
}
@@ -174,7 +173,6 @@ abstract class task_databoxAbstract extends task_abstract
// post-process
$this->postProcessOneContent($databox, $row);
// $this->check_memory_usage();
$current_memory = memory_get_usage();
if ($current_memory >> 20 >= $this->maxmegs) {
$this->log(sprintf("Max memory (%s M) reached (actual is %s M)", $this->maxmegs, $current_memory));
@@ -188,29 +186,23 @@ abstract class task_databoxAbstract extends task_abstract
$ret = self::STATE_MAXRECSDONE;
}
// $this->check_task_status();
try {
$status = $this->getState();
// printf("%s (%d) status=%s \n", __FILE__, __LINE__, var_export($status, true));
if ($status == self::STATUS_TOSTOP) {
if ($status == self::STATE_TOSTOP) {
$this->running = FALSE;
$ret = self::STATUS_TOSTOP;
$ret = self::STATE_TOSTOP;
}
} catch (Exception $e) {
$this->running = FALSE;
// $this->task_status = self::STATUS_TOSTOP;
// $this->return_xxxvalue = self::RETURNSTATUS_STOPPED;
}
// if($this->task_status == self::STATUS_TOSTOP)
// $this->running = false;
if ( ! $this->running)
break;
} // foreach($rs as $row)
}
//
// if nothing was done, at least check the status
if (count($rs) == 0 && $this->running) {
// $this->check_memory_usage();
$current_memory = memory_get_usage();
if ($current_memory >> 20 >= $this->maxmegs) {
$this->log(sprintf("Max memory (%s M) reached (current is %s M)", $this->maxmegs, $current_memory));
@@ -224,20 +216,14 @@ abstract class task_databoxAbstract extends task_abstract
$ret = self::STATE_MAXRECSDONE;
}
// $this->check_task_status();
try {
$status = $this->getState();
// printf("%s (%d) status=%s \n", __FILE__, __LINE__, var_export($status, true));
if ($status == self::STATUS_TOSTOP) {
if ($status == self::STATE_TOSTOP) {
$this->running = FALSE;
$ret = self::STATUS_TOSTOP;
// $this->task_status = self::STATUS_TOSTOP;
// $this->return_xxxvalue = self::RETURNSTATUS_STOPPED;
$ret = self::STATE_TOSTOP;
}
} catch (Exception $e) {
$this->running = FALSE;
// $this->task_status = self::STATUS_TOSTOP;
// $this->return_xxxvalue = self::RETURNSTATUS_STOPPED;
}
}
@@ -250,7 +236,7 @@ abstract class task_databoxAbstract extends task_abstract
if ($rowstodo > 0)
$this->setProgress(0, 0);
return($ret);
return $ret;
}
}

View File

@@ -22,7 +22,6 @@ class task_manager
const STATUS_SCHED_TOSTOP = 'tostop';
protected $appbox;
protected $tasks;
public function __construct(appbox &$appbox)

View File

@@ -2,7 +2,7 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -10,7 +10,6 @@
/**
*
* @package task_manager
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
@@ -102,7 +101,7 @@ class task_period_archive extends task_abstract
$ptype = substr($pname, 0, 3);
$pname = substr($pname, 4);
$pvalue = $parm2[$pname];
if ($ns = $dom->getElementsByTagName($pname)->item(0)) {
if (($ns = $dom->getElementsByTagName($pname)->item(0))) {
// le champ existait dans le xml, on supprime son ancienne valeur (tout le contenu)
while (($n = $ns->firstChild))
$ns->removeChild($n);
@@ -234,13 +233,13 @@ class task_period_archive extends task_abstract
</select>
<br/>
<br/>
<?php echo _('task::_common_:hotfolder') ?>
<?php echo _('task::_common_:hotfolder') ?>
<input type="text" name="hotfolder" style="width:400px;" onchange="chgxmltxt(this, 'hotfolder');" value=""><br/>
<br/>
<?php echo _('task::_common_:periodicite de la tache') ?>&nbsp;:&nbsp;
<?php echo _('task::_common_:periodicite de la tache') ?>&nbsp;:&nbsp;
<input type="text" name="period" style="width:40px;" onchange="chgxmltxt(this, 'period');" value="">&nbsp;<?php echo _('task::_common_:secondes (unite temporelle)') ?><br/>
<br/>
<?php echo _('task::archive:delai de \'repos\' avant traitement') ?>&nbsp;:&nbsp;
<?php echo _('task::archive:delai de \'repos\' avant traitement') ?>&nbsp;:&nbsp;
<input type="text" name="cold" style="width:40px;" onchange="chgxmltxt(this, 'cold');" value="">&nbsp;<?php echo _('task::_common_:secondes (unite temporelle)') ?><br/>
<br/>
<input type="checkbox" name="move_archived" onchange="chgxmlck(this, 'move_archived');">&nbsp;<?php echo _('task::archive:deplacer les fichiers archives dans _archived') ?>
@@ -386,11 +385,11 @@ class task_period_archive extends task_abstract
for ($t = 60 * 10; $this->running && $t; $t -- ) // DON'T do sleep(600) because it prevents ticks !
sleep(1);
$this->setState(self::STATUS_TORESTART);
$this->setState(self::STATE_TORESTART);
} else {
$this->log(sprintf(('Error : missing hotfolder \'%s\', stopping.'), $path_in));
// runner = manual : can't restart so simply quit
$this->setState(self::STATUS_STOPPED);
$this->setState(self::STATE_STOPPED);
}
$this->running = FALSE;
return;
@@ -426,17 +425,17 @@ class task_period_archive extends task_abstract
for ($t = 60 * 10; $this->running && $t; $t -- ) // DON'T do sleep(600) because it prevents ticks !
sleep(1);
$this->setState(self::STATUS_TORESTART);
$this->setState(self::STATE_TORESTART);
} else {
$this->log(sprintf(('Error : error fetching task \'%d\', stopping.'), $this->getID()));
// runner = manual : can't restart so simply quit
$this->setState(self::STATUS_STOPPED);
$this->setState(self::STATE_STOPPED);
}
$this->running = FALSE;
return;
}
if ($row['status'] == self::STATUS_TOSTOP) {
if ($row['status'] == self::STATE_TOSTOP) {
$this->running = FALSE;
return;
}
@@ -449,39 +448,27 @@ class task_period_archive extends task_abstract
switch ($r) {
case 'TOSTOP':
$this->setState(self::STATUS_STOPPED);
$this->setState(self::STATE_STOPPED);
$this->running = FALSE;
break;
case 'WAIT':
$this->setState(self::STATUS_STOPPED);
$this->setState(self::STATE_STOPPED);
$this->running = FALSE;
break;
case 'BAD':
$this->setState(self::STATUS_STOPPED);
$this->setState(self::STATE_STOPPED);
$this->running = FALSE;
break;
case 'NORECSTODO':
$duration = time() - $duration;
if ($duration < ($period + $cold)) {
/*
printf("will close a conn in 5sec...\n");
sleep(5);
$conn->close();
unset($conn);
printf("conn closed, waiting 5sec\n");
sleep(5);
*/
for ($i = 0; $i < (($period + $cold) - $duration) && $this->running; $i ++ ) {
$s = $this->getState();
if ($s == self::STATUS_TOSTOP) {
$this->setState(self::STATUS_STOPPED);
if ($s == self::STATE_TOSTOP) {
$this->setState(self::STATE_STOPPED);
$this->running = FALSE;
} else {
// $conn->close();
// unset($conn);
sleep(1);
// $conn = connection::getPDOConnection();
}
}
}
@@ -489,14 +476,14 @@ class task_period_archive extends task_abstract
case 'MAXRECSDONE':
case 'MAXMEMORY':
case 'MAXLOOP':
if ($row['status'] == self::STATUS_STARTED && $this->getRunner() !== self::RUNNER_MANUAL) {
$this->setState(self::STATUS_TORESTART);
if ($row['status'] == self::STATE_STARTED && $this->getRunner() !== self::RUNNER_MANUAL) {
$this->setState(self::STATE_TORESTART);
$this->running = FALSE;
}
break;
default:
if ($row['status'] == self::STATUS_STARTED) {
$this->setState(self::STATUS_STOPPED);
if ($row['status'] == self::STATE_STARTED) {
$this->setState(self::STATE_STOPPED);
$this->running = FALSE;
}
break;
@@ -513,8 +500,6 @@ class task_period_archive extends task_abstract
*/
function archiveHotFolder($server_coll_id)
{
// $this->filesToIgnore = array('.', '..', 'Thumbs.db', '');
clearstatcache();
$conn = connection::getPDOConnection();
@@ -570,7 +555,7 @@ class task_period_archive extends task_abstract
while ($cold > 0) {
$s = $this->getState();
if ($s == self::STATUS_TOSTOP)
if ($s == self::STATE_TOSTOP)
return('TOSTOP');
sleep(2);
$cold -= 2;
@@ -724,7 +709,7 @@ class task_period_archive extends task_abstract
while (($file = $listFolder->read()) !== NULL) {
if (time() - $time0 >= 2) { // each 2 secs, check the status of the task
$s = $this->getState();
if ($s == self::STATUS_TOSTOP) {
if ($s == self::STATE_TOSTOP) {
$nnew = 'TOSTOP'; // since we will return a string...
break; // ...we can check it against numerical result
}
@@ -779,7 +764,7 @@ class task_period_archive extends task_abstract
* @param <type> $depth
* @return <type>
*/
function listFilesPhase2($dom, $node, $path, $depth=0)
function listFilesPhase2($dom, $node, $path, $depth = 0)
{
static $iloop = 0;
if ($depth == 0)
@@ -877,7 +862,7 @@ class task_period_archive extends task_abstract
* @param <type> $depth
* @return <type>
*/
function makePairs($dom, $node, $path, $path_archived, $path_error, $inGrp=false, $depth=0)
function makePairs($dom, $node, $path, $path_archived, $path_error, $inGrp = false, $depth = 0)
{
static $iloop = 0;
if ($depth == 0)
@@ -903,7 +888,6 @@ class task_period_archive extends task_abstract
if ($n->getAttribute('isdir') == '1') {
if (($grpSettings = $this->getGrpSettings($name)) !== FALSE) { // get 'caption', 'representation'
// this is a grp folder, we check it
$dnl = $xpath->query('./file[@name=".grouping.xml"]', $n);
if ($dnl->length == 1) {
// this group is old (don't care about any linked files), just flag it
@@ -1010,7 +994,7 @@ class task_period_archive extends task_abstract
* @param <type> $depth
* @return <type>
*/
function removeBadGroups($dom, $node, $path, $path_archived, $path_error, $depth=0)
function removeBadGroups($dom, $node, $path, $path_archived, $path_error, $depth = 0)
{
static $iloop = 0;
if ($depth == 0)
@@ -1033,11 +1017,6 @@ class task_period_archive extends task_abstract
if ($n->getAttribute('isdir')) {
// a dir
// if($n->getAttribute('error') && $this->move_error)
// {
// @mkdir($path_error . '/' . $name);
// }
$ret |= $this->removeBadGroups($dom, $n, $path . '/' . $name
, $path_archived . '/' . $name
, $path_error . '/' . $name
@@ -1086,7 +1065,7 @@ class task_period_archive extends task_abstract
* @param <type> $depth
* @return <type>
*/
function archive($dom, $node, $path, $path_archived, $path_error, $depth=0)
function archive($dom, $node, $path, $path_archived, $path_error, $depth = 0)
{
static $iloop = 0;
if ($depth == 0)
@@ -1125,7 +1104,6 @@ class task_period_archive extends task_abstract
$this->archiveFile($dom, $n, $path, $path_archived, $path_error, $nodesToDel, 0); // 0 = no grp
}
}
// printf("========== %s === %s ====== \n", __LINE__, var_export($nodesToDel, true));
foreach ($nodesToDel as $n)
$n->parentNode->removeChild($n);
@@ -1153,7 +1131,7 @@ class task_period_archive extends task_abstract
* @param <type> $depth
* @return <type>
*/
function bubbleResults($dom, $node, $path, $depth=0)
function bubbleResults($dom, $node, $path, $depth = 0)
{
static $iloop = 0;
if ($depth == 0)
@@ -1212,7 +1190,7 @@ class task_period_archive extends task_abstract
* @param <type> $depth
* @return <type>
*/
function moveFiles($dom, $node, $path, $path_archived, $path_error, $depth=0)
function moveFiles($dom, $node, $path, $path_archived, $path_error, $depth = 0)
{
static $iloop = 0;
if ($depth == 0)
@@ -1567,7 +1545,7 @@ class task_period_archive extends task_abstract
* @param <type> $grp_rid
* @return <type>
*/
function archiveFile($dom, $node, $path, $path_archived, $path_error, &$nodesToDel, $grp_rid=0)
function archiveFile($dom, $node, $path, $path_archived, $path_error, &$nodesToDel, $grp_rid = 0)
{
$match = $node->getAttribute('match');
if ($match == '*')
@@ -1823,7 +1801,7 @@ class task_period_archive extends task_abstract
* @param <type> $attributes
* @param <type> $depth
*/
function setAllChildren($dom, $node, $attributes, $depth=0)
function setAllChildren($dom, $node, $attributes, $depth = 0)
{
static $iloop = 0;
if ($depth == 0)

View File

@@ -2,7 +2,7 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -381,7 +381,7 @@ class task_period_cindexer extends task_abstract
}
if ( ! file_exists($cmd) || ! is_executable($cmd)) {
$this->setState(self::STATUS_STOPPED);
$this->setState(self::STATE_STOPPED);
$this->log(sprintf(_('task::cindexer:file \'%s\' does not exists'), $cmd));
throw new Exception('cindexer executable not found', self::ERR_EXECUTABLE_NOT_FOUND);
return;
@@ -442,8 +442,6 @@ class task_period_cindexer extends task_abstract
$nullfile = $this->system == 'WINDOWS' ? 'NUL' : '/dev/null';
$descriptors = array();
// $descriptors[1] = array("file", $logdir . "/phraseanet_indexer_" . $this->getID() . ".log", "a+");
// $descriptors[2] = array("file", $logdir . "/phraseanet_indexer_" . $this->getID() . ".error.log", "a+");
$descriptors[1] = array("file", $nullfile, "a+");
$descriptors[2] = array("file", $nullfile, "a+");
@@ -465,7 +463,7 @@ class task_period_cindexer extends task_abstract
$this->running = true;
while ($this->running) {
if ($this->getState() == self::STATUS_TOSTOP && $this->socket > 0) {
if ($this->getState() == self::STATE_TOSTOP && $this->socket > 0) {
// must quit task, so send 'Q' to port 127.0.0.1:XXXX to cindexer
if ( ! $qsent && (($sock = socket_create(AF_INET, SOCK_STREAM, 0)) !== false)) {
if (socket_connect($sock, '127.0.0.1', $this->socket) === true) {
@@ -487,10 +485,10 @@ class task_period_cindexer extends task_abstract
// the cindexer died
if ($qsent == 'Q') {
$this->log(_('task::cindexer:the cindexer clean-quit'));
$this->new_status = self::STATUS_STOPPED;
$this->new_status = self::STATE_STOPPED;
} elseif ($qsent == 'K') {
$this->log(_('task::cindexer:the cindexer has been killed'));
$this->new_status = self::STATUS_STOPPED;
$this->new_status = self::STATE_STOPPED;
} else {
$this->log(_('task::cindexer:the cindexer crashed'));
$this->exception = new Exception('cindexer crashed', self::ERR_CRASHED);
@@ -536,7 +534,6 @@ class task_period_cindexer extends task_abstract
} elseif ($pid == 0) {
// child
umask(0);
// openlog('MyLog', LOG_PID | LOG_PERROR, LOG_LOCAL0);
if (($err = posix_setsid()) < 0) {
$this->exception = new Exception('cindexer can\'t detach from terminal', $err);
} else {
@@ -562,7 +559,7 @@ class task_period_cindexer extends task_abstract
}
}
if ($this->getState() == self::STATUS_TOSTOP) {
if ($this->getState() == self::STATE_TOSTOP) {
posix_kill($pid, ($sigsent = SIGINT));
sleep(2);
}
@@ -572,10 +569,10 @@ class task_period_cindexer extends task_abstract
// child (indexer) has exited
if ($sigsent == SIGINT) {
$this->log(_('task::cindexer:the cindexer clean-quit'));
$this->new_status = self::STATUS_STOPPED;
$this->new_status = self::STATE_STOPPED;
} elseif ($sigsent == SIGKILL) {
$this->log(_('task::cindexer:the cindexer has been killed'));
$this->new_status = self::STATUS_STOPPED;
$this->new_status = self::STATE_STOPPED;
} else {
$this->log(_('task::cindexer:the cindexer crashed'));
$this->exception = new Exception('cindexer crashed', self::ERR_CRASHED);
@@ -601,5 +598,3 @@ class task_period_cindexer extends task_abstract
sleep(2);
}
}
// class

View File

@@ -18,9 +18,7 @@
class task_period_emptyColl extends task_appboxAbstract
{
protected $base_id;
protected $suicidable = true;
protected $total_records = 0;
public function getName()
@@ -47,9 +45,8 @@ class task_period_emptyColl extends task_appboxAbstract
protected function retrieveContent(appbox $appbox)
{
if ( ! $this->base_id) {
$this->current_state = self::STATE_FINISHED;
return;
$this->setState(self::STATE_STOPPED);
return array();
}
$collection = collection::get_from_base_id($this->base_id);
$this->total_records = $collection->get_record_amount();
@@ -58,7 +55,7 @@ class task_period_emptyColl extends task_appboxAbstract
$this->setProgress($this->records_done, $this->total_records);
if ($this->total_records == 0) {
$this->current_state = self::STATE_FINISHED;
$this->setState(self::STATE_STOPPED);
$this->log('Job finished');
}

View File

@@ -17,9 +17,7 @@
class task_period_ftp extends task_appboxAbstract
{
protected $proxy;
protected $proxyport;
protected $debug;
/**
@@ -566,8 +564,7 @@ class task_period_ftp extends task_appboxAbstract
{
$conn = $appbox->get_connection();
$sql = 'SELECT crash, nbretry FROM ftp_export'
. ' WHERE id = :export_id';
$sql = 'SELECT crash, nbretry FROM ftp_export WHERE id = :export_id';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':export_id' => $id));

View File

@@ -2,7 +2,7 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -17,25 +17,15 @@
class task_period_ftpPull extends task_appboxAbstract
{
protected $debug = false;
protected $proxy;
protected $proxyport;
protected $host;
protected $port;
protected $user;
protected $password;
protected $ssl;
protected $passive;
protected $ftppath;
protected $localpath;
public function getName()
@@ -108,6 +98,7 @@ class task_period_ftpPull extends task_appboxAbstract
<?php echo $form ?>.ssl.checked = <?php echo p4field::isyes($sxml->ssl) ? "true" : 'false' ?>;
<?php echo $form ?>.passive.checked = <?php echo p4field::isyes($sxml->passive) ? "true" : 'false' ?>;
</script>
<?php
return("");
} else { // ... so we NEVER come here
@@ -134,6 +125,7 @@ class task_period_ftpPull extends task_appboxAbstract
setDirty();
}
</script>
<?php
}
@@ -203,11 +195,11 @@ class task_period_ftpPull extends task_appboxAbstract
if ($parm["xml"] === null) {
// pas de xml 'raw' : on accepte les champs 'graphic view'
if ($domTaskSettings = DOMDocument::loadXML($taskrow["settings"])) {
if (($domTaskSettings = DOMDocument::loadXML($taskrow["settings"]))) {
$xmlchanged = false;
foreach (array("proxy", "proxyport", "period", "host", "port", "user", "password", "ssl", "passive", "localpath", "ftppath") as $f) {
if ($parm[$f] !== NULL) {
if ($ns = $domTaskSettings->getElementsByTagName($f)->item(0)) {
if (($ns = $domTaskSettings->getElementsByTagName($f)->item(0))) {
// le champ existait dans le xml, on supprime son ancienne valeur (tout le contenu)
while (($n = $ns->firstChild))
$ns->removeChild($n);
@@ -228,8 +220,9 @@ class task_period_ftpPull extends task_appboxAbstract
}
// si on doit changer le xml, on verifie qu'il est valide
if ($parm["xml"] && ! DOMDocument::loadXML($parm["xml"]))
if ($parm["xml"] && ! DOMDocument::loadXML($parm["xml"])) {
return(false);
}
$sql = "";
$params = array(':task_id' => $taskid);
@@ -295,7 +288,7 @@ class task_period_ftpPull extends task_appboxAbstract
$this->running = FALSE;
}
if ( ! $this->running) {
$this->set_status(self::STATUS_STOPPED);
$this->set_status(self::STATE_STOPPED);
return array();
}
@@ -308,14 +301,16 @@ class task_period_ftpPull extends task_appboxAbstract
$todo = count($list_1);
$this->setProgress($done, $todo);
if ($this->debug)
if ($this->debug) {
echo "attente de 25sec pour avoir les fichiers froids...\n";
}
for ($t = 25; $this->running && $t > 0; $t -- ) { // DON'T do sleep($this->period - $when_started) because it prevents ticks !
$s = $this->getState();
if ($s == self::STATUS_TOSTOP) {
if ($s == self::STATE_TOSTOP) {
if (isset($ftp) && $ftp instanceof ftpclient)
$ftp->close();
$this->set_status(self::STATUS_STOPPED);
$this->set_status(self::STATE_STOPPED);
$this->running = FALSE;
return array();
}
@@ -379,3 +374,4 @@ class task_period_ftpPull extends task_appboxAbstract
}
}

View File

@@ -2,7 +2,7 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -448,11 +448,8 @@ class task_period_outofdate extends task_abstract
// ======================================================================================================
protected $sxTaskSettings = null; // les settings de la tache en simplexml
private $connbas = null; // cnx a la base
private $msg = "";
private $sbas_id;
protected function run2()
@@ -529,11 +526,11 @@ class task_period_outofdate extends task_abstract
switch ($r) {
case 'WAIT':
$ret = self::STATUS_STOPPED;
$this->setState(self::STATE_STOPPED);
$this->running = false;
break;
case 'BAD':
$ret = self::STATUS_STOPPED;
$this->setState(self::STATE_STOPPED);
$this->running = false;
break;
case 'NORECSTODO':
@@ -546,21 +543,21 @@ class task_period_outofdate extends task_abstract
case 'MAXRECSDONE':
case 'MAXMEMORY':
case 'MAXLOOP':
if ($row['status'] == self::STATUS_STARTED && $this->getRunner() !== self::RUNNER_MANUAL) {
$ret = self::STATUS_TORESTART;
if ($row['status'] == self::STATE_STARTED && $this->getRunner() !== self::RUNNER_MANUAL) {
$this->setState(self::STATE_TORESTART);
$this->running = false;
}
break;
default:
if ($row['status'] == self::STATUS_STARTED) {
$ret = self::STATUS_STOPPED;
if ($row['status'] == self::STATE_STARTED) {
$this->setState(self::STATE_STOPPED);
$this->running = false;
}
break;
}
}
} else {
$ret = self::STATUS_STOPPED;
$this->setState(self::STATE_STOPPED);
$this->running = false;
}
$loop ++;

View File

@@ -2,7 +2,7 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -141,6 +141,7 @@ class task_period_subdef extends task_databoxAbstract
<?php echo $form ?>.maxrecs.value = "<?php echo p4string::MakeString($sxml->maxrecs, "js", '"') ?>";
<?php echo $form ?>.maxmegs.value = "<?php echo p4string::MakeString($sxml->maxmegs, "js", '"') ?>";
</script>
<?php
return("");
}
@@ -261,7 +262,7 @@ class task_period_subdef extends task_databoxAbstract
, $this->sbas_id, $record_id));
$record = new record_adapter($this->sbas_id, $record_id);
$record->generate_subdefs($databox, null, $this->debug);
$record->generate_subdefs($databox, null);
$this->recs_to_write[] = $record->get_record_id();

View File

@@ -2,7 +2,7 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -10,7 +10,6 @@
/**
*
* @package task_manager
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
@@ -117,12 +116,12 @@ class task_period_workflow01 extends task_databoxAbstract
<?php echo $form ?>.period.value = "<?php echo p4string::MakeString($sxml->period, "js", '"') ?>";
parent.calccmd();
</script>
<?php
return("");
}
else { // ... so we NEVER come here
// bad xml
return("BAD XML");
}
}
@@ -283,16 +282,16 @@ class task_period_workflow01 extends task_databoxAbstract
ob_start();
?>
<form name="graphicForm" onsubmit="return(false);" method="post">
<?php echo _('task::outofdate:Base') ?>&nbsp;:&nbsp;
<?php echo _('task::outofdate:Base') ?>&nbsp;:&nbsp;
<select onchange="chgsbas(this);setDirty();" name="sbas_id">
<option value="">...</option>
<?php
$sbas_ids = $user->ACL()->get_granted_sbas(array('bas_manage'));
foreach ($sbas_ids as $databox) {
print('<option value="' . $databox->get_sbas_id() . '">' . p4string::MakeString($databox->get_viewname(), "form") . '</option>');
}
?>
<?php
$sbas_ids = $user->ACL()->get_granted_sbas(array('bas_manage'));
foreach ($sbas_ids as $databox) {
print('<option value="' . $databox->get_sbas_id() . '">' . p4string::MakeString($databox->get_viewname(), "form") . '</option>');
}
?>
</select>
&nbsp;
@@ -300,9 +299,9 @@ class task_period_workflow01 extends task_databoxAbstract
<br/>
<br/>
<?php echo _('task::_common_:periodicite de la tache') ?>&nbsp;:&nbsp;
<?php echo _('task::_common_:periodicite de la tache') ?>&nbsp;:&nbsp;
<input type="text" name="period" style="width:40px;" onchange="chgxmltxt(this, 'period');" value="">
<?php echo _('task::_common_:minutes (unite temporelle)') ?><br/>
<?php echo _('task::_common_:minutes (unite temporelle)') ?><br/>
<br/>
<table id="OUTOFDATETAB" style="margin-right:10px; ">
@@ -348,11 +347,8 @@ class task_period_workflow01 extends task_databoxAbstract
return(_("task::outofdate:deplacement de docs suivant valeurs de champs 'date'"));
}
protected $status_origine;
protected $coll_origine;
protected $status_destination;
protected $coll_destination;
protected function loadSettings(SimpleXMLElement $sx_task_settings)
@@ -382,28 +378,28 @@ class task_period_workflow01 extends task_databoxAbstract
$sql_s = $sql_w = '';
$sql_parms = array();
if ($this->coll_origine != '') {
$sql_w .= ($sql_w ? ' AND ' : '')
. '(coll_id=:coll_org)';
$sql_w .= ($sql_w ? ' AND ' : '') . '(coll_id=:coll_org)';
$sql_parms[':coll_org'] = $this->coll_origine;
}
if ($this->status_origine != '') {
$x = explode('_', $this->status_origine);
if (count($x) !== 2)
throw new Exception('Error in settings for status origine');
if (count($x) !== 2) {
throw new Exception('Error in settings for status origin');
}
$sql_w .= ($sql_w ? ' AND ' : '')
. '((status >> :stat_org_n & 1) = :stat_org_v)';
$sql_parms[':stat_org_n'] = $x[0];
$sql_parms[':stat_org_v'] = $x[1];
}
if ($this->coll_destination != '') {
$sql_s .= ($sql_s ? ', ' : '')
. 'coll_id=:coll_dst';
$sql_s .= ($sql_s ? ', ' : '') . 'coll_id=:coll_dst';
$sql_parms[':coll_dst'] = $this->coll_destination;
}
if ($this->status_destination != '') {
$x = explode('_', $this->status_destination);
if (count($x) !== 2)
if (count($x) !== 2) {
throw new Exception('Error in settings for status destination');
}
$sql_s .= ($sql_s ? ', ' : '');
if ((int) $x[1] === 0)
$sql_s .= 'status = status &~(1 << :stat_dst)';
@@ -491,6 +487,7 @@ class task_period_workflow01 extends task_databoxAbstract
} catch (Exception $e) {
}
return p4string::jsonencode($retjs);
}
}

View File

@@ -16,14 +16,12 @@ use PHPExiftool\Writer;
/**
*
* @package task_manager
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class task_period_writemeta extends task_databoxAbstract
{
protected $clear_doc;
protected $metasubdefs = array();
function help()
@@ -61,7 +59,7 @@ class task_period_writemeta extends task_databoxAbstract
$ptype = substr($pname, 0, 3);
$pname = substr($pname, 4);
$pvalue = $parm2[$pname];
if ($ns = $dom->getElementsByTagName($pname)->item(0)) {
if (($ns = $dom->getElementsByTagName($pname)->item(0))) {
// le champ existait dans le xml, on supprime son ancienne valeur (tout le contenu)
while (($n = $ns->firstChild))
$ns->removeChild($n);