code formating

This commit is contained in:
jygaulier
2012-05-15 14:19:40 +02:00
parent 22c492f69d
commit 823a3ed89e
20 changed files with 550 additions and 399 deletions

View File

@@ -730,11 +730,13 @@ class API_V1_adapter extends API_V1_Abstract
$options->set_bases($params['bases'], $user->ACL());
if ( ! is_array($params['fields']))
if ( ! is_array($params['fields'])) {
$params['fields'] = array();
}
$options->set_fields($params['fields']);
if ( ! is_array($params['status']))
if ( ! is_array($params['status'])) {
$params['status'] = array();
}
$options->set_status($params['status']);
$options->set_search_type($params['search_type']);
$options->set_record_type($params['recordtype']);
@@ -938,15 +940,19 @@ class API_V1_adapter extends API_V1_Abstract
$datas = strrev($record->get_status());
if ( ! is_array($status))
if ( ! is_array($status)) {
throw new API_V1_exception_badrequest();
}
foreach ($status as $n => $value) {
if ($n > 63 || $n < 4)
if ($n > 63 || $n < 4) {
throw new API_V1_exception_badrequest();
if ( ! in_array($value, array('0', '1')))
}
if ( ! in_array($value, array('0', '1'))) {
throw new API_V1_exception_badrequest();
if ( ! isset($status_bits[$n]))
}
if ( ! isset($status_bits[$n])) {
throw new API_V1_exception_badrequest ();
}
$datas = substr($datas, 0, ($n - 1)) . $value . substr($datas, ($n + 1));
}
@@ -1076,8 +1082,9 @@ class API_V1_adapter extends API_V1_Abstract
$name = $request->get('name');
if (trim(strip_tags($name)) === '')
if (trim(strip_tags($name)) === '') {
throw new API_V1_exception_badrequest ();
}
$user = $this->core->getAuthenticatedUser();
@@ -1472,10 +1479,11 @@ class API_V1_adapter extends API_V1_Abstract
*/
protected function list_embedable_media(media_subdef &$media, registryInterface &$registry)
{
if ($media->get_permalink() instanceof media_Permalink_Adapter)
if ($media->get_permalink() instanceof media_Permalink_Adapter) {
$permalink = $this->list_permalink($media->get_permalink(), $registry);
else
} else {
$permalink = null;
}
return array(
'permalink' => $permalink,
@@ -1600,8 +1608,9 @@ class API_V1_adapter extends API_V1_Abstract
$expires_on_atom = $basket->getValidation()->getExpires();
if ($expires_on_atom instanceof DateTime)
if ($expires_on_atom instanceof DateTime) {
$expires_on_atom = $expires_on_atom->format(DATE_ATOM);
}
$user = \User_Adapter::getInstance($this->appbox->get_session()->get_usr_id(), $this->appbox);

View File

@@ -59,10 +59,11 @@ class module_console_taskrun extends Command
{
if ($this->task) {
$this->task->log(sprintf("signal %s received", $signo));
if ($signo == SIGTERM)
if ($signo == SIGTERM) {
$this->task->setRunning(false);
}
}
}
public function execute(InputInterface $input, OutputInterface $output)
{
@@ -72,8 +73,9 @@ class module_console_taskrun extends Command
}
$task_id = (int) $input->getArgument('task_id');
if ($task_id <= 0 || strlen($task_id) !== strlen($input->getArgument('task_id')))
if ($task_id <= 0 || strlen($task_id) !== strlen($input->getArgument('task_id'))) {
throw new \RuntimeException('Argument must be an Id.');
}
$appbox = \appbox::get_instance(\bootstrap::getCore());
$task_manager = new task_manager($appbox);
@@ -82,21 +84,23 @@ class module_console_taskrun extends Command
if ($input->getOption('runner') === task_abstract::RUNNER_MANUAL) {
$schedStatus = $task_manager->getSchedulerState();
if ($schedStatus && $schedStatus['status'] == 'running' && $schedStatus['pid'])
if ($schedStatus && $schedStatus['status'] == 'running' && $schedStatus['pid']) {
$this->shedulerPID = $schedStatus['pid'];
$runner = task_abstract::RUNNER_MANUAL;
}
else {
$runner = task_abstract::RUNNER_MANUAL;
} else {
$runner = task_abstract::RUNNER_SCHEDULER;
$schedStatus = $task_manager->getSchedulerState();
if ($schedStatus && $schedStatus['status'] == 'running' && $schedStatus['pid'])
if ($schedStatus && $schedStatus['status'] == 'running' && $schedStatus['pid']) {
$this->shedulerPID = $schedStatus['pid'];
}
}
register_tick_function(array($this, 'tick_handler'), true);
declare(ticks = 1);
if (function_exists('pcntl_signal'))
if (function_exists('pcntl_signal')) {
pcntl_signal(SIGTERM, array($this, 'sig_handler'));
}
try {
$this->task->run($runner, $input, $output);
@@ -121,12 +125,12 @@ class module_console_taskrun extends Command
if (time() - $start > 0) {
if ($this->shedulerPID) {
if ( ! posix_kill($this->shedulerPID, 0)) {
if (method_exists($this->task, 'signal'))
if (method_exists($this->task, 'signal')) {
$this->task->signal('SIGNAL_SCHEDULER_DIED');
else
} else {
$this->task->setState(task_abstract::STATE_TOSTOP);
}
}
$start = time();
}

View File

@@ -78,7 +78,8 @@ class task_Scheduler
$lockdir = $registry->get('GV_RootPath') . 'tmp/locks/';
for ($try = 1; true; $try ++ ) {
if (($schedlock = fopen(($lockfile = ($lockdir . 'scheduler.lock')), 'a+'))) {
$lockfile = ($lockdir . 'scheduler.lock');
if (($schedlock = fopen($lockfile, 'a+')) != FALSE) {
if (flock($schedlock, LOCK_EX | LOCK_NB) === FALSE) {
$this->log(sprintf("failed to lock '%s' (try=%s/4)", $lockfile, $try));
if ($try == 4) {
@@ -107,8 +108,9 @@ class task_Scheduler
$this->log(sprintf("running scheduler with method %s", $this->method));
if ($this->method == self::METHOD_FORK)
if ($this->method == self::METHOD_FORK) {
pcntl_signal(SIGCHLD, SIG_IGN);
}
$logdir = $registry->get('GV_RootPath') . 'logs/';
@@ -136,16 +138,11 @@ class task_Scheduler
}
}
$tlist = array();
$schedstatus = 'started';
$runningtask = 0;
$connwaslost = false;
$last_log_check = array();
while ($schedstatus == 'started' || $runningtask > 0) {
while (1) {
try {
@@ -154,15 +151,17 @@ class task_Scheduler
} catch (ErrorException $e) {
$ping = false;
}
if ($ping)
if ($ping) {
break;
}
unset($conn);
if ( ! $connwaslost) {
$this->log(sprintf("Warning : abox connection lost, restarting in 10 min."));
}
for ($i = 0; $i < 60 * 10; $i ++ )
for ($i = 0; $i < 60 * 10; $i ++ ) {
sleep(1);
}
try {
$conn = appbox::get_instance(\bootstrap::getCore())->get_connection();
} catch (ErrorException $e) {
@@ -181,7 +180,7 @@ class task_Scheduler
$connwaslost = false;
}
// printf("%d \n", __LINE__);
$schedstatus = '';
$row = NULL;
try {
@@ -216,10 +215,10 @@ class task_Scheduler
logs::rotate($logdir . "scheduler_o.log");
logs::rotate($logdir . "scheduler_e.log");
// printf("%d \n", __LINE__);
// initialy, all tasks are supposed to be removed from the poll
foreach ($taskPoll as $tkey => $task)
foreach ($taskPoll as $tkey => $task) {
$taskPoll[$tkey]["todel"] = true;
}
foreach ($task_manager->getTasks(true) as $task) {
$tkey = "t_" . $task->getID();
@@ -236,16 +235,18 @@ class task_Scheduler
case "WINDOWS":
$cmd = $phpcli;
$args = array('-f', $registry->get('GV_RootPath') . 'bin/console', '--', '-q', 'task:run', $task->getID(), '--runner=scheduler');
if ($this->input && ($this->input->getOption('notasklog')))
if ($this->input && ($this->input->getOption('notasklog'))) {
$args[] = 'notasklog';
}
break;
default:
case "DARWIN":
case "LINUX":
$cmd = $phpcli;
$args = array('-f', $registry->get('GV_RootPath') . 'bin/console', '--', '-q', 'task:run', $task->getID(), '--runner=scheduler');
if ($this->input && ($this->input->getOption('notasklog')))
if ($this->input && ($this->input->getOption('notasklog'))) {
$args[] = 'notasklog';
}
break;
}
@@ -330,8 +331,9 @@ class task_Scheduler
case task_abstract::STATE_TOSTART:
// if scheduler is 'tostop', don't launch a new task !
if ($schedstatus != 'started')
if ($schedstatus != 'started') {
break;
}
$taskPoll[$tkey]["killat"] = NULL;
@@ -380,28 +382,24 @@ class task_Scheduler
)
);
if ($taskPoll[$tkey]["task"]->getCrashCounter() > 5)
if ($taskPoll[$tkey]["task"]->getCrashCounter() > 5) {
$taskPoll[$tkey]["task"]->setState(task_abstract::STATE_STOPPED);
else
} else {
$taskPoll[$tkey]["task"]->setState(task_abstract::STATE_TOSTART);
}
}
}
elseif ($this->method == self::METHOD_FORK) {
} elseif ($this->method == self::METHOD_FORK) {
$pid = pcntl_fork();
if ($pid == -1) {
die("failed to fork");
} elseif ($pid == 0) {
umask(0);
if (posix_setsid() < 0)
if (posix_setsid() < 0) {
die("Forked process could not detach from terminal\n");
}
fclose(STDIN);
fclose(STDOUT);
fclose(STDERR);
$fdIN = fopen($nullfile, 'r');
$fdOUT = fopen($logdir . "task_o_" . $taskPoll[$tkey]["task"]->getID() . ".log", 'a+');
$fdERR = fopen($logdir . "task_e_" . $taskPoll[$tkey]["task"]->getID() . ".log", 'a+');
// todo (if possible) : redirecting stdin, stdout to log files ?
$this->log(sprintf("exec('%s %s')", $taskPoll[$tkey]["cmd"], implode(' ', $taskPoll[$tkey]["args"])));
pcntl_exec($taskPoll[$tkey]["cmd"], $taskPoll[$tkey]["args"]);
@@ -419,12 +417,12 @@ class task_Scheduler
if (is_resource($taskPoll[$tkey]["process"])) {
$proc_status = proc_get_status($taskPoll[$tkey]["process"]);
if ($proc_status['running'])
if ($proc_status['running']) {
$runningtask ++;
else
} else {
$crashed = true;
}
else {
} else {
$crashed = true;
}
}
@@ -455,17 +453,19 @@ class task_Scheduler
)
);
if ($taskPoll[$tkey]["task"]->getCrashCounter() > 5)
if ($taskPoll[$tkey]["task"]->getCrashCounter() > 5) {
$taskPoll[$tkey]["task"]->setState(task_abstract::STATE_STOPPED);
else
} else {
$taskPoll[$tkey]["task"]->setState(task_abstract::STATE_TOSTART);
}
}
break;
case task_abstract::STATE_TOSTOP:
if ($taskPoll[$tkey]["killat"] === NULL)
if ($taskPoll[$tkey]["killat"] === NULL) {
$taskPoll[$tkey]["killat"] = time() + self::TASKDELAYTOQUIT;
}
$pid = $taskPoll[$tkey]['task']->getPID();
if ($pid) {
@@ -545,9 +545,10 @@ class task_Scheduler
}
}
for ($i = 0; $i < $sleeptime; $i ++ )
for ($i = 0; $i < $sleeptime; $i ++ ) {
sleep(1);
}
}
$sql = "UPDATE sitepreff SET schedstatus='stopped', schedpid='0'";
$stmt = $conn->prepare($sql);

View File

@@ -101,8 +101,9 @@ abstract class task_abstract
$stmt->execute(array(':taskid' => $this->taskid));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ( ! $row)
if ( ! $row) {
throw new Exception('Unknown task id');
}
return $row['status'];
}
@@ -281,8 +282,9 @@ abstract class task_abstract
$stmt->execute(array(':taskid' => $this->getID()));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ( ! $row)
if ( ! $row) {
throw new Exception('Unknown task id');
}
$this->title = $row['name'];
$this->crash_counter = (int) $row['crashed'];
$this->active = ! ! $row['active'];
@@ -367,7 +369,7 @@ abstract class task_abstract
$registry = registry::get_instance();
system_file::mkdir($lockdir = $registry->get('GV_RootPath') . 'tmp/locks/');
if (($fd = fopen(($lockfile = ($lockdir . 'task_' . $taskid . '.lock')), 'a+'))) {
if (($fd = fopen(($lockfile = ($lockdir . 'task_' . $taskid . '.lock')), 'a+')) != FALSE) {
if (flock($fd, LOCK_EX | LOCK_NB) === FALSE) {
// already locked ? : task running
$pid = fgets($fd);
@@ -389,7 +391,7 @@ abstract class task_abstract
protected function pause($when_started = 0)
{
$this->log($this->records_done . ' records done');
if ($this->running) {// && $this->records_done == 0)
if ($this->running) { // && $this->records_done == 0)
$when_started = time() - $when_started;
if ($when_started < $this->period) {
for ($t = $this->period - $when_started; $this->running && $t > 0; $t -- ) { // DON'T do sleep($this->period - $when_started) because it prevents ticks !
@@ -411,12 +413,12 @@ abstract class task_abstract
$this->output = $output;
$taskid = $this->getID();
$conn = connection::getPDOConnection();
$registry = registry::get_instance();
system_file::mkdir($lockdir = $registry->get('GV_RootPath') . 'tmp/locks/');
$locker = true;
$tasklock = fopen(($lockfile = ($lockdir . 'task_' . $taskid . '.lock')), 'a+');
$lockfile = ($lockdir . 'task_' . $taskid . '.lock');
$tasklock = fopen($lockfile, 'a+');
if (flock($tasklock, LOCK_EX | LOCK_NB, $locker) === FALSE) {
$this->log("runtask::ERROR : task already running.");
@@ -463,28 +465,33 @@ abstract class task_abstract
}
// if something went wrong, report
if ($exception)
if ($exception) {
throw($exception);
}
}
abstract protected function run2();
protected function loadSettings(SimpleXMLElement $sx_task_settings)
{
$this->period = (int) $sx_task_settings->period;
if ($this->period <= 0 || $this->period >= 60 * 60)
if ($this->period <= 0 || $this->period >= 60 * 60) {
$this->period = 60;
}
$this->maxrecs = (int) $sx_task_settings->maxrecs;
if ($sx_task_settings->maxrecs < 10 || $sx_task_settings->maxrecs > 1000)
if ($sx_task_settings->maxrecs < 10 || $sx_task_settings->maxrecs > 1000) {
$this->maxrecs = 100;
}
$this->maxmegs = (int) $sx_task_settings->maxmegs;
if ($sx_task_settings->maxmegs < 16 || $sx_task_settings->maxmegs > 512)
if ($sx_task_settings->maxmegs < 16 || $sx_task_settings->maxmegs > 512) {
$this->maxmegs = 24;
}
$this->record_buffer_size = (int) $sx_task_settings->flush;
if ($sx_task_settings->flush < 1 || $sx_task_settings->flush > 100)
if ($sx_task_settings->flush < 1 || $sx_task_settings->flush > 100) {
$this->record_buffer_size = 10;
}
}
protected function incrementLoops()
{
@@ -500,8 +507,9 @@ abstract class task_abstract
{
static $lastt = null;
$t = explode(' ', ($ut = microtime()));
if ($lastt === null)
if ($lastt === null) {
$lastt = $t;
}
$dt = ($t[0] - $lastt[0]) + ($t[1] - $lastt[1]);
$m = memory_get_usage() >> 10;
@@ -547,8 +555,9 @@ abstract class task_abstract
*/
public static function create(appbox $appbox, $class_name, $settings = null)
{
if ( ! class_exists($class_name))
if ( ! class_exists($class_name)) {
throw new Exception('Unknown task class');
}
$sql = 'INSERT INTO task2
(task_id, usr_id_owner, status, crashed, active,
@@ -558,10 +567,11 @@ abstract class task_abstract
:name, "0000/00/00 00:00:00", :class, :settings)';
if ($settings && ! DOMDocument::loadXML($settings))
if ($settings && ! DOMDocument::loadXML($settings)) {
throw new Exception('settings invalide');
elseif ( ! $settings)
} elseif ( ! $settings) {
$settings = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<tasksettings>\n</tasksettings>";
}
$params = array(
':active' => 1
@@ -582,8 +592,9 @@ abstract class task_abstract
{
global $argc, $argv;
$t = "usage: " . $argv[0] . " [options]\noptions:\n";
foreach ($this->argt as $n => $v)
foreach ($this->argt as $n => $v) {
$t .= "\t" . $n . $v["usage"] . "\n";
}
return($t);
}

View File

@@ -67,8 +67,9 @@ abstract class task_appboxAbstract extends task_abstract
}
if ($row) {
if ( ! $this->running)
if ( ! $this->running) {
break;
}
$appbox = appbox::get_instance(\bootstrap::getCore());
try {
@@ -119,8 +120,6 @@ abstract class task_appboxAbstract extends task_abstract
{
$ret = self::STATE_OK;
$conn = $appbox->get_connection();
$tsub = array();
try {
// get the records to process
$rs = $this->retrieveContent($appbox);
@@ -132,8 +131,9 @@ abstract class task_appboxAbstract extends task_abstract
$rowstodo = count($rs);
$rowsdone = 0;
if ($rowstodo > 0)
if ($rowstodo > 0) {
$this->setProgress(0, $rowstodo);
}
foreach ($rs as $row) {
try {
@@ -174,9 +174,10 @@ abstract class task_appboxAbstract extends task_abstract
$this->running = FALSE;
}
if ( ! $this->running)
if ( ! $this->running) {
break;
}
}
//
// if nothing was done, at least check the status
if (count($rs) == 0 && $this->running) {
@@ -205,8 +206,9 @@ abstract class task_appboxAbstract extends task_abstract
}
}
if ($rowstodo > 0)
if ($rowstodo > 0) {
$this->setProgress(0, 0);
}
return $ret;
}

View File

@@ -79,8 +79,9 @@ abstract class task_databoxAbstract extends task_abstract
}
foreach ($rs as $row) { // every sbas
if ( ! $this->running)
if ( ! $this->running) {
break;
}
$this->sbas_id = (int) $row['sbas_id'];
$this->log('This task works now on ' . phrasea::sbas_names($this->sbas_id));
@@ -140,7 +141,6 @@ abstract class task_databoxAbstract extends task_abstract
{
$ret = self::STATE_OK;
$tsub = array();
$connbas = false;
try {
@@ -156,8 +156,9 @@ abstract class task_databoxAbstract extends task_abstract
$rowstodo = count($rs);
$rowsdone = 0;
if ($rowstodo > 0)
if ($rowstodo > 0) {
$this->setProgress(0, $rowstodo);
}
foreach ($rs as $row) {
try {
@@ -196,9 +197,10 @@ abstract class task_databoxAbstract extends task_abstract
$this->running = FALSE;
}
if ( ! $this->running)
if ( ! $this->running) {
break;
}
}
//
// if nothing was done, at least check the status
if (count($rs) == 0 && $this->running) {
@@ -233,8 +235,9 @@ abstract class task_databoxAbstract extends task_abstract
unset($connbas);
}
if ($rowstodo > 0)
if ($rowstodo > 0) {
$this->setProgress(0, 0);
}
return $ret;
}

View File

@@ -33,8 +33,9 @@ class task_manager
public function getTasks($refresh = false)
{
if ($this->tasks && ! $refresh)
if ($this->tasks && ! $refresh) {
return $this->tasks;
}
$sql = "SELECT task2.* FROM task2 ORDER BY task_id ASC";
$stmt = $this->appbox->get_connection()->prepare($sql);
@@ -51,8 +52,9 @@ class task_manager
$row['pid'] = NULL;
$classname = $row['class'];
if ( ! class_exists($classname))
if ( ! class_exists($classname)) {
continue;
}
try {
// if( ($lock = fopen( $lockdir . 'task.'.$row['task_id'].'.lock', 'a+')) )
// {
@@ -129,7 +131,7 @@ class task_manager
$pid = NULL;
$lockdir = $appbox->get_registry()->get('GV_RootPath') . 'tmp/locks/';
if (($schedlock = fopen($lockdir . 'scheduler.lock', 'a+'))) {
if (($schedlock = fopen($lockdir . 'scheduler.lock', 'a+')) != FALSE) {
if (flock($schedlock, LOCK_EX | LOCK_NB) === FALSE) {
// already locked : running !
$pid = trim(fgets($schedlock, 512));
@@ -159,12 +161,12 @@ class task_manager
$tasks = array();
foreach ($taskdir as $path) {
if (($hdir = @opendir($path))) {
$tskin = array();
if (($hdir = @opendir($path)) != FALSE) {
$max = 9999;
while (($max -- > 0) && (($file = readdir($hdir)) !== false)) {
if ( ! is_file($path . '/' . $file) || substr($file, 0, 1) == "." || substr($file, -10) != ".class.php")
if ( ! is_file($path . '/' . $file) || substr($file, 0, 1) == "." || substr($file, -10) != ".class.php") {
continue;
}
$classname = 'task_period_' . substr($file, 0, strlen($file) - 10);

View File

@@ -77,10 +77,11 @@ class task_period_apibridge extends task_appboxAbstract
$this->log("process " . $element->get_id() . " with status " . $element->get_status());
if ($element->get_status() == Bridge_Element::STATUS_PENDING)
if ($element->get_status() == Bridge_Element::STATUS_PENDING) {
$this->upload_element($element);
else
} else {
$this->update_element($element);
}
} catch (Exception $e) {
$sql = 'UPDATE bridge_elements SET status = :status WHERE id = :id';

View File

@@ -101,10 +101,11 @@ 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)) != NULL) {
// le champ existait dans le xml, on supprime son ancienne valeur (tout le contenu)
while (($n = $ns->firstChild))
while (($n = $ns->firstChild)) {
$ns->removeChild($n);
}
} else {
// le champ n'existait pas dans le xml, on le cree
$ns = $dom->documentElement->appendChild($dom->createElement($pname));
@@ -134,16 +135,18 @@ class task_period_archive extends task_abstract
*/
public function xml2graphic($xml, $form)
{
if (($sxml = simplexml_load_string($xml))) { // in fact XML IS always valid here...
if (($sxml = simplexml_load_string($xml)) != FALSE) { // in fact XML IS always valid here...
// ... but we could check for safe values (ex. 0 < period < 3600)
if ((int) ($sxml->period) < 10)
if ((int) ($sxml->period) < 10) {
$sxml->period = 10;
elseif ((int) ($sxml->period) > 300)
} elseif ((int) ($sxml->period) > 300) {
$sxml->period = 300;
if ((int) ($sxml->cold) < 5)
}
if ((int) ($sxml->cold) < 5) {
$sxml->cold = 5;
elseif ((int) ($sxml->cold) > 3600)
} elseif ((int) ($sxml->cold) > 3600) {
$sxml->cold = 3600;
}
?>
<script type="text/javascript">
var i;
@@ -165,8 +168,7 @@ class task_period_archive extends task_abstract
</script>
<?php
return("");
}
else { // ... so we NEVER come here
} else { // ... so we NEVER come here
// bad xml
return("BAD XML");
}
@@ -295,9 +297,10 @@ class task_period_archive extends task_abstract
$collection = null;
foreach ($databox->get_collections() as $coll) {
$this->TColls['c' . $coll->get_coll_id()] = $coll->get_coll_id();
if ($base_id == $coll->get_base_id())
if ($base_id == $coll->get_base_id()) {
$collection = $coll;
}
}
$server_coll_id = $collection->get_coll_id();
@@ -307,18 +310,20 @@ class task_period_archive extends task_abstract
$this->cold = 60;
if (($this->sxBasePrefs = simplexml_load_string($collection->get_prefs()))) {
if (($this->sxBasePrefs = simplexml_load_string($collection->get_prefs())) != FALSE) {
$this->sxBasePrefs["id"] = $base_id;
$do_it = true;
$this->period = (int) ($this->sxTaskSettings->period);
if ($this->period <= 0 || $this->period >= 60 * 60)
if ($this->period <= 0 || $this->period >= 60 * 60) {
$this->period = 60;
}
$this->cold = (int) ($this->sxTaskSettings->cold);
if ($this->cold <= 0 || $this->cold >= 60 * 60)
if ($this->cold <= 0 || $this->cold >= 60 * 60) {
$this->cold = 60;
}
// check the data-repository exists
$pathhd = (string) ($this->sxBasePrefs->path);
@@ -333,15 +338,16 @@ class task_period_archive extends task_abstract
// load masks
if ($this->sxTaskSettings->files && $this->sxTaskSettings->files->file) {
foreach ($this->sxTaskSettings->files->file as $ft)
foreach ($this->sxTaskSettings->files->file as $ft) {
$this->tmask[] = array(
"mask" => (string) $ft["mask"]
, "caption" => (string) $ft["caption"]
, "accept" => (string) $ft["accept"]
);
}
}
if ($this->sxTaskSettings->files && $this->sxTaskSettings->files->grouping) {
foreach ($this->sxTaskSettings->files->grouping as $ft)
foreach ($this->sxTaskSettings->files->grouping as $ft) {
$this->tmaskgrp[] = array(
"mask" => (string) $ft["mask"]
, "caption" => (string) $ft["caption"]
@@ -349,6 +355,7 @@ class task_period_archive extends task_abstract
, "accept" => (string) $ft["accept"]
);
}
}
if (count($this->tmask) == 0) {
// no mask defined : accept all kind of files
$this->tmask[] = array("mask" => ".*", "caption" => "", "accept" => "");
@@ -410,13 +417,14 @@ class task_period_archive extends task_abstract
$this->move_error = p4field::isyes($this->sxTaskSettings->move_error);
$period = (int) ($this->sxTaskSettings->period);
if ($period <= 0 || $period >= 60 * 60)
if ($period <= 0 || $period >= 60 * 60) {
$period = 60;
}
$cold = (int) ($this->sxTaskSettings->cold);
if ($cold <= 0 || $cold >= 60 * 60)
if ($cold <= 0 || $cold >= 60 * 60) {
$cold = 60;
}
else {
} else {
throw new Exception(sprintf('Error fetching or reading settings of the task \'%d\'', $this->getID()));
}
} catch (Exception $e) {
@@ -443,8 +451,9 @@ class task_period_archive extends task_abstract
$duration = time();
$r = $this->archiveHotFolder($server_coll_id);
if ($loop > 10)
if ($loop > 10) {
$r = 'MAXLOOP';
}
switch ($r) {
case 'TOSTOP':
@@ -550,13 +559,15 @@ class task_period_archive extends task_abstract
}
$cold = (int) ($this->sxTaskSettings->cold);
if ($cold <= 0 || $cold >= 60 * 60)
if ($cold <= 0 || $cold >= 60 * 60) {
$cold = 60;
}
while ($cold > 0) {
$s = $this->getState();
if ($s == self::STATE_TOSTOP)
if ($s == self::STATE_TOSTOP) {
return('TOSTOP');
}
sleep(2);
$cold -= 2;
}
@@ -682,15 +693,16 @@ class task_period_archive extends task_abstract
try {
$listFolder = new CListFolder($path);
if (($sxDotPhrasea = @simplexml_load_file($path . '/.phrasea.xml'))) {
if (($sxDotPhrasea = @simplexml_load_file($path . '/.phrasea.xml')) != FALSE) {
// on gere le magicfile
if (($magicfile = trim((string) ($sxDotPhrasea->magicfile))) != '') {
$magicmethod = strtoupper($sxDotPhrasea->magicfile['method']);
if ($magicmethod == 'LOCK' && file_exists($path . '/' . $magicfile))
if ($magicmethod == 'LOCK' && file_exists($path . '/' . $magicfile)) {
return;
elseif ($magicmethod == 'UNLOCK' && ! file_exists($path . '/' . $magicfile))
} elseif ($magicmethod == 'UNLOCK' && ! file_exists($path . '/' . $magicfile)) {
return;
}
}
// on gere le changement de collection
if (($new_cid = $sxDotPhrasea['collection']) != '') {
@@ -716,11 +728,13 @@ class task_period_archive extends task_abstract
$time0 = time();
}
if (($iloop ++ % 100) == 0)
if (($iloop ++ % 100) == 0) {
usleep(1000);
}
if ($this->isIgnoredFile($file))
if ($this->isIgnoredFile($file)) {
continue;
}
if (is_dir($path . '/' . $file)) {
$n = $node->appendChild($dom->createElement('file'));
@@ -738,8 +752,9 @@ class task_period_archive extends task_abstract
$n = $node->appendChild($dom->createElement('file'));
$n->setAttribute('name', $file);
$stat = stat($path . '/' . $file);
foreach (array("size", "ctime", "mtime") as $k)
foreach (array("size", "ctime", "mtime") as $k) {
$n->setAttribute($k, $stat[$k]);
}
$nnew ++;
}
$n->setAttribute('cid', $server_coll_id);
@@ -767,8 +782,9 @@ class task_period_archive extends task_abstract
function listFilesPhase2($dom, $node, $path, $depth = 0)
{
static $iloop = 0;
if ($depth == 0)
if ($depth == 0) {
$iloop = 0;
}
$nnew = 0;
@@ -777,32 +793,36 @@ class task_period_archive extends task_abstract
$xp = new DOMXPath($dom);
if (($sxDotPhrasea = @simplexml_load_file($path . '/.phrasea.xml'))) {
if (($sxDotPhrasea = @simplexml_load_file($path . '/.phrasea.xml')) != FALSE) {
// on gere le magicfile
if (($magicfile = trim((string) ($sxDotPhrasea->magicfile))) != '') {
$magicmethod = strtoupper($sxDotPhrasea->magicfile['method']);
if ($magicmethod == 'LOCK' && file_exists($path . '/' . $magicfile))
if ($magicmethod == 'LOCK' && file_exists($path . '/' . $magicfile)) {
return;
elseif ($magicmethod == 'UNLOCK' && ! file_exists($path . '/' . $magicfile))
} elseif ($magicmethod == 'UNLOCK' && ! file_exists($path . '/' . $magicfile)) {
return;
}
}
}
// on gere le magicfile
if (($magicfile = trim((string) @($sxDotPhrasea->magicfile))) != '') {
$magicmethod = strtoupper($sxDotPhrasea->magicfile['method']);
if ($magicmethod == 'LOCK' && file_exists($path . '/' . $magicfile))
if ($magicmethod == 'LOCK' && file_exists($path . '/' . $magicfile)) {
return;
elseif ($magicmethod == 'UNLOCK' && ! file_exists($path . '/' . $magicfile))
} elseif ($magicmethod == 'UNLOCK' && ! file_exists($path . '/' . $magicfile)) {
return;
}
}
while (($file = $listFolder->read()) !== NULL) {
if ($this->isIgnoredFile($file))
if ($this->isIgnoredFile($file)) {
continue;
}
if (($iloop ++ % 100) == 0)
if (($iloop ++ % 100) == 0) {
usleep(500);
}
$dnl = @$xp->query('./file[@name="' . $file . '"]', $node);
if ($dnl && $dnl->length == 0) {
@@ -865,24 +885,29 @@ class task_period_archive extends task_abstract
function makePairs($dom, $node, $path, $path_archived, $path_error, $inGrp = false, $depth = 0)
{
static $iloop = 0;
if ($depth == 0)
if ($depth == 0) {
$iloop = 0;
}
if ($depth == 0 && ($node->getAttribute('temperature') == 'hot' || $node->getAttribute('cid') == '-1'))
if ($depth == 0 && ($node->getAttribute('temperature') == 'hot' || $node->getAttribute('cid') == '-1')) {
return;
}
$xpath = new DOMXPath($dom); // useful
for ($n = $node->firstChild; $n; $n = $n->nextSibling) {
if (($iloop ++ % 100) == 0)
if (($iloop ++ % 100) == 0) {
usleep(1000);
}
// make xml lighter (free ram)
foreach (array("size", "ctime", "mtime") as $k)
foreach (array("size", "ctime", "mtime") as $k) {
$n->removeAttribute($k);
}
if ($n->getAttribute('temperature') == 'hot' || $n->getAttribute('cid') == '-1')
if ($n->getAttribute('temperature') == 'hot' || $n->getAttribute('cid') == '-1') {
continue;
}
$name = $n->getAttribute('name');
if ($n->getAttribute('isdir') == '1') {
@@ -940,8 +965,9 @@ class task_period_archive extends task_abstract
$this->setAllChildren($dom, $n, array('error' => '1'));
// bubble to the top
for ($nn = $n; $nn && $nn->nodeType == XML_ELEMENT_NODE; $nn = $nn->parentNode)
for ($nn = $n; $nn && $nn->nodeType == XML_ELEMENT_NODE; $nn = $nn->parentNode) {
$nn->setAttribute('error', '1');
}
// ... as the existing linked file(s) ...
foreach ($flink as $linkName => $v) {
@@ -961,22 +987,24 @@ class task_period_archive extends task_abstract
} else {
// this is a file
if ( ! $n->getAttribute('match')) { // because match can be set before
if ($name == '.phrasea.xml')
if ($name == '.phrasea.xml') {
$n->setAttribute('match', '*'); // special file(s) always ok
else
} else {
$this->checkMatch($dom, $n);
}
}
}
}
// scan again for unmatched files
for ($n = $node->firstChild; $n; $n = $n->nextSibling) {
if ( ! $n->getAttribute('isdir') == '1' && ! $n->getAttribute('match')) {
// still no match, now it's an error (bubble to the top)
for ($nn = $n; $nn && $nn->nodeType == XML_ELEMENT_NODE; $nn = $nn->parentNode)
for ($nn = $n; $nn && $nn->nodeType == XML_ELEMENT_NODE; $nn = $nn->parentNode) {
$nn->setAttribute('error', '1');
}
}
}
return;
}
@@ -997,8 +1025,9 @@ class task_period_archive extends task_abstract
function removeBadGroups($dom, $node, $path, $path_archived, $path_error, $depth = 0)
{
static $iloop = 0;
if ($depth == 0)
if ($depth == 0) {
$iloop = 0;
}
$ret = false;
@@ -1007,11 +1036,13 @@ class task_period_archive extends task_abstract
$nodesToDel = array();
for ($n = $node->firstChild; $n; $n = $n->nextSibling) {
if (($iloop ++ % 20) == 0)
if (($iloop ++ % 20) == 0) {
usleep(1000);
}
if ($n->getAttribute('temperature') == 'hot') // do not move hotfiles
continue;
if ($n->getAttribute('temperature') == 'hot') {
continue; // do not move hotfiles
}
$name = $n->getAttribute('name');
@@ -1045,8 +1076,9 @@ class task_period_archive extends task_abstract
}
}
foreach ($nodesToDel as $n)
foreach ($nodesToDel as $n) {
$n->parentNode->removeChild($n);
}
return;
}
@@ -1068,19 +1100,23 @@ class task_period_archive extends task_abstract
function archive($dom, $node, $path, $path_archived, $path_error, $depth = 0)
{
static $iloop = 0;
if ($depth == 0)
if ($depth == 0) {
$iloop = 0;
}
if ($node->getAttribute('temperature') == 'hot')
if ($node->getAttribute('temperature') == 'hot') {
return;
}
$nodesToDel = array();
for ($n = $node->firstChild; $n; $n = $n->nextSibling) {
if (($iloop ++ % 20) == 0)
if (($iloop ++ % 20) == 0) {
usleep(1000);
}
if ($n->getAttribute('temperature') == 'hot')
if ($n->getAttribute('temperature') == 'hot') {
continue;
}
if ($n->getAttribute('cid') == '-1') {
$n->setAttribute('error', '1');
@@ -1104,17 +1140,19 @@ class task_period_archive extends task_abstract
$this->archiveFile($dom, $n, $path, $path_archived, $path_error, $nodesToDel, 0); // 0 = no grp
}
}
foreach ($nodesToDel as $n)
foreach ($nodesToDel as $n) {
$n->parentNode->removeChild($n);
}
// at the end of recursion, restore the magic file (create or delete it)
if (($magicfile = $node->getAttribute('magicfile')) != '') {
$magicmethod = $node->getAttribute('magicmethod');
if ($magicmethod == 'LOCK')
if ($magicmethod == 'LOCK') {
file_put_contents($path . '/' . $magicfile, '');
elseif ($magicmethod == 'UNLOCK')
} elseif ($magicmethod == 'UNLOCK') {
unlink($path . '/' . $magicfile);
}
}
return;
}
@@ -1134,23 +1172,27 @@ class task_period_archive extends task_abstract
function bubbleResults($dom, $node, $path, $depth = 0)
{
static $iloop = 0;
if ($depth == 0)
if ($depth == 0) {
$iloop = 0;
}
if ($node->getAttribute('temperature') == 'hot')
if ($node->getAttribute('temperature') == 'hot') {
return;
}
$ret = 0;
for ($n = $node->firstChild; $n; $n = $n->nextSibling) {
if (($iloop ++ % 20) == 0)
if (($iloop ++ % 20) == 0) {
usleep(1000);
}
if ($n->getAttribute('name') == '.phrasea.xml' || $n->getAttribute('name') == '.grouping.xml') {
// special files stay in place AND are copied into 'archived'
$n->setAttribute('keep', '1');
if (p4field::isyes($this->sxTaskSettings->copy_spe))
if (p4field::isyes($this->sxTaskSettings->copy_spe)) {
$n->setAttribute('archived', '1');
}
}
// else
// {
// if(!$n->getAttribute('isdir') && ($n->getAttribute('temperature') == 'cold' && !$n->getAttribute('archived')))
@@ -1158,21 +1200,28 @@ class task_period_archive extends task_abstract
// $n->setAttribute('error', '1');
// }
// }
if ($n->getAttribute('keep') == '1')
if ($n->getAttribute('keep') == '1') {
$ret |= 1;
if ($n->getAttribute('archived') == '1')
}
if ($n->getAttribute('archived') == '1') {
$ret |= 2;
if ($n->getAttribute('error') == '1')
}
if ($n->getAttribute('error') == '1') {
$ret |= 4;
if ($n->getAttribute('isdir') == '1')
}
if ($n->getAttribute('isdir') == '1') {
$ret |= $this->bubbleResults($dom, $n, $path . '/' . $n->getAttribute('name'), $depth + 1);
}
if ($ret & 1)
}
if ($ret & 1) {
$node->setAttribute('keep', '1');
if ($ret & 2)
}
if ($ret & 2) {
$node->setAttribute('archived', '1');
if ($ret & 4)
}
if ($ret & 4) {
$node->setAttribute('error', '1');
}
return($ret);
}
@@ -1193,71 +1242,43 @@ class task_period_archive extends task_abstract
function moveFiles($dom, $node, $path, $path_archived, $path_error, $depth = 0)
{
static $iloop = 0;
if ($depth == 0)
if ($depth == 0) {
$iloop = 0;
}
$ret = false;
if ($depth == 0 && $node->getAttribute('temperature') == 'hot') // if root of hotfolder if hot, die...
if ($depth == 0 && $node->getAttribute('temperature') == 'hot') { // if root of hotfolder if hot, die...
return($ret);
}
//printf("%s : \n", __LINE__);
$nodesToDel = array();
for ($n = $node->firstChild; $n; $n = $n->nextSibling) {
if (($iloop ++ % 20) == 0)
if (($iloop ++ % 20) == 0) {
usleep(1000);
}
if ($n->getAttribute('temperature') == 'hot') // do not move hotfiles
if ($n->getAttribute('temperature') == 'hot') { // do not move hotfiles
continue;
}
//printf("%s : \n", __LINE__);
$name = $n->getAttribute('name');
//printf("----------------\n file %s : \n ", $path.'/'.$name);
//$fp = fopen('php://stdin', 'r');
//fgets($fp);
//fclose($fp);
if ($n->getAttribute('isdir')) {
// printf("%s : ('%s', '%s')\n", __LINE__, $path_archived, $path_error);
// $new_path_archived = $new_path_error = null;
// if($n->getAttribute('archived') && $this->move_archived)
// {
// @mkdir($new_path_archived = ($path_archived . '/' . $name));
// if(!is_dir($new_path_archived))
// {
// $rootpath = p4string::delEndSlash(trim((string)($this->sxTaskSettings->hotfolder)));
// $subpath = substr($new_path_archived, strlen($rootpath));
//
// $this->log("error subfolder '".$subpath."' does not exits");
// }
// }
//
// if($n->getAttribute('error') && $this->move_error)
// {
// @mkdir($new_path_error = ($path_error . '/' . $name));
// if(!is_dir($new_path_error))
// {
// $rootpath = p4string::delEndSlash(trim((string)($this->sxTaskSettings->hotfolder)));
// $subpath = substr($new_path_error, strlen($rootpath));
//
// $this->log("error subfolder '".$subpath."' does not exists");
// }
// }
$ret |= $this->moveFiles($dom, $n, $path . '/' . $name
, $path_archived . '/' . $name
, $path_error . '/' . $name
, $depth + 1);
if ( ! $n->firstChild)
if ( ! $n->firstChild) {
$nodesToDel[] = $n;
}
// ----- JY 20100318 : DO NOT DELETE EMPTY FOLDERS ANYMORE, AS THEY MAY DISAPEAR TOO SOON -----
// if(!$n->getAttribute('keep'))
// @rmdir($path.'/'.$name);
// --------------------------------------------------------------------------------------------
}
else {
//printf("%s : \n", __LINE__);
} else {
$rootpath = p4string::delEndSlash(trim((string) ($this->sxTaskSettings->hotfolder)));
$subpath = substr($path, strlen($rootpath));
@@ -1273,7 +1294,6 @@ class task_period_archive extends task_abstract
}
if ($n->getAttribute('error') && $this->move_error) {
// printf("%s : \n", __LINE__);
$this->log(sprintf(('copy \'%s\' to \'error\''), $subpath . '/' . $name));
@mkdir($path_error, 0755, true);
@@ -1282,11 +1302,9 @@ class task_period_archive extends task_abstract
$nodesToDel[] = $n;
$ret = true;
}
//printf("-> copy to %s \n", $path_error.'/'.$name);
}
if ( ! $n->getAttribute('keep')) {
//printf("-> unlink %s \n", $path.'/'.$name);
$this->log(sprintf(('delete \'%s\''), $subpath . '/' . $name));
if (@unlink($path . '/' . $name)) {
// $n->parentNode->removeChild($n);
@@ -1298,8 +1316,9 @@ class task_period_archive extends task_abstract
}
}
foreach ($nodesToDel as $n)
foreach ($nodesToDel as $n) {
$n->parentNode->removeChild($n);
}
return($ret);
}
@@ -1315,10 +1334,11 @@ class task_period_archive extends task_abstract
for ($n = $node; $n; $n = $n->parentNode) {
if ($n->nodeType == XML_ELEMENT_NODE) {
$n->setAttribute('temperature', 'hot');
if ($n->hasAttribute('pxml'))
if ($n->hasAttribute('pxml')) {
break;
}
}
}
return;
}
@@ -1374,7 +1394,7 @@ class task_period_archive extends task_abstract
$this->log(sprintf(('representation from \'%s\''), $representationFileName));
}
if (($cap = $node->getAttribute('grp_caption'))) {
if (($cap = $node->getAttribute('grp_caption')) != '') {
$dnl = $xpath->query('./file[@name="' . $cap . '"]', $node->parentNode);
$captionFileNode = $dnl->item(0);
$captionFileName = $cap;
@@ -1399,15 +1419,19 @@ class task_period_archive extends task_abstract
$meta = $system_file->extract_metadatas($databox->get_meta_structure(), $caption_file);
$stat0 = $stat1 = "0";
if ($this->sxBasePrefs->status)
if ($this->sxBasePrefs->status) {
$stat0 = (string) ($this->sxBasePrefs->status);
if ($this->sxTaskSettings->status)
}
if ($this->sxTaskSettings->status) {
$stat1 = (string) ($this->sxTaskSettings->status);
}
if ( ! $stat0)
if ( ! $stat0) {
$stat0 = '0';
if ( ! $stat1)
}
if ( ! $stat1) {
$stat1 = '0';
}
try {
@@ -1427,8 +1451,9 @@ class task_period_archive extends task_abstract
if ($genericdoc)
if ($genericdoc) {
unlink($genericdoc);
}
file_put_contents($groupingFile, '<?xml version="1.0" encoding="ISO-8859-1" ?><record grouping="' . $rid . '" />');
$n = $node->appendChild($dom->createElement('file'));
@@ -1449,8 +1474,9 @@ class task_period_archive extends task_abstract
if ($this->move_archived) {
$this->log(sprintf(('copy \'%s\' to \'archived\''), $subpath . '/' . $captionFileName));
if ( ! is_dir($path_archived))
if ( ! is_dir($path_archived)) {
@mkdir($path_archived, 0755, true);
}
@copy($path . '/' . $captionFileName, $path_archived . '/' . $captionFileName);
}
@unlink($path . '/' . $captionFileName);
@@ -1463,8 +1489,9 @@ class task_period_archive extends task_abstract
if ($this->move_archived) {
$this->log(sprintf(('copy \'%s\' to \'archived\''), $subpath . '/' . $representationFileName));
if ( ! is_dir($path_archived))
if ( ! is_dir($path_archived)) {
@mkdir($path_archived, 0755, true);
}
@copy($path . '/' . $representationFileName, $path_archived . '/' . $representationFileName);
}
@unlink($path . '/' . $representationFileName);
@@ -1527,8 +1554,9 @@ class task_period_archive extends task_abstract
$this->archiveFile($dom, $n, $path, $path_archived, $path_error, $nodesToDel, $grp_rid);
}
}
foreach ($nodesToDel as $n)
foreach ($nodesToDel as $n) {
$n->parentNode->removeChild($n);
}
return;
}
@@ -1548,8 +1576,9 @@ class task_period_archive extends task_abstract
function archiveFile($dom, $node, $path, $path_archived, $path_error, &$nodesToDel, $grp_rid = 0)
{
$match = $node->getAttribute('match');
if ($match == '*')
if ($match == '*') {
return;
}
$file = $node->getAttribute('name');
$cid = $node->getAttribute('cid');
@@ -1571,7 +1600,7 @@ class task_period_archive extends task_abstract
$node->setAttribute('error', '1');
return;
} elseif (($match != '.')) { // match='.' : the file does not have a separate caption
} elseif ($match != '.') { // match='.' : the file does not have a separate caption
$xpath = new DOMXPath($dom);
$dnl = $xpath->query('./file[@name="' . $match . '"]', $node->parentNode);
// in fact, xquery has been done in checkMatch, setting match='?' if caption does not exists...
@@ -1612,20 +1641,26 @@ class task_period_archive extends task_abstract
$subpath = substr($path, strlen($rootpath));
$this->log(sprintf(("Archiving file '%s'"), $subpath . '/' . $file));
if ($captionFileName !== NULL)
if ($captionFileName !== NULL) {
$this->log(sprintf(' ' . (" (caption in '%s')"), $captionFileName));
if ($grp_rid !== 0)
}
if ($grp_rid !== 0) {
$this->log(sprintf(' ' . (" into GRP rid=%s"), $grp_rid));
}
$stat0 = $stat1 = "0";
if ($this->sxBasePrefs->status)
if ($this->sxBasePrefs->status) {
$stat0 = (string) ($this->sxBasePrefs->status);
if ($this->sxTaskSettings->status)
}
if ($this->sxTaskSettings->status) {
$stat1 = (string) ($this->sxTaskSettings->status);
if ( ! $stat0)
}
if ( ! $stat0) {
$stat0 = '0';
if ( ! $stat1)
}
if ( ! $stat1) {
$stat1 = '0';
}
$system_file = new system_file($path . '/' . $file);
@@ -1649,8 +1684,9 @@ class task_period_archive extends task_abstract
$hexstat = '';
if ($meta['status'] !== NULL) {
$s = strrev($meta['status']) . str_repeat('0', 64);
for ($a = 0; $a < 4; $a ++ )
for ($a = 0; $a < 4; $a ++ ) {
$hexstat = substr('0000' . base_convert(strrev(substr($s, $a << 4, 16)), 2, 16), -4) . $hexstat;
}
} else {
$hexstat = '0';
}
@@ -1675,8 +1711,9 @@ class task_period_archive extends task_abstract
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ($row && uuid::is_valid($row['uuid']))
if ($row && uuid::is_valid($row['uuid'])) {
$uuid = $row['uuid'];
}
} catch (Exception $e) {
}
@@ -1687,8 +1724,9 @@ class task_period_archive extends task_abstract
$error_file = p4file::check_file_error($system_file->getPathname(), $sbas_id, $file);
$status = databox_status::operation_or($stat0, $stat1);
if ($meta['status'])
if ($meta['status']) {
$status = databox_status::operation_or($status, $meta['status']);
}
if ( ! $system_file->is_new_in_base(phrasea::sbasFromBas($base_id)) || count($error_file) > 0) {
$this->log(sprintf(("Trying to move to lazaret")));
@@ -1737,15 +1775,17 @@ class task_period_archive extends task_abstract
$this->archivedFiles ++;
$node->setAttribute('archived', '1');
if ($captionFileNode)
if ($captionFileNode) {
$captionFileNode->setAttribute('archived', '1');
}
} catch (Exception $e) {
$this->log(("Error : can't insert record : " . $e->getMessage()));
$node->setAttribute('error', '1');
if ($captionFileNode)
if ($captionFileNode) {
$captionFileNode->setAttribute('error', '1');
}
}
}
if ($node->getAttribute('archived') && $this->move_archived) {
$this->log(sprintf(('copy \'%s\' to \'archived\''), $subpath . '/' . $file));
@@ -1804,18 +1844,22 @@ class task_period_archive extends task_abstract
function setAllChildren($dom, $node, $attributes, $depth = 0)
{
static $iloop = 0;
if ($depth == 0)
if ($depth == 0) {
$iloop = 0;
}
foreach ($attributes as $a => $v)
foreach ($attributes as $a => $v) {
$node->setAttribute($a, $v);
}
if (($iloop ++ % 100) == 0)
if (($iloop ++ % 100) == 0) {
usleep(1000);
}
for ($n = $node->firstChild; $n; $n = $n->nextSibling)
for ($n = $node->firstChild; $n; $n = $n->nextSibling) {
$this->setAllChildren($dom, $n, $attributes, $depth + 1);
}
}
/**
*
@@ -1834,9 +1878,10 @@ class task_period_archive extends task_abstract
if (preg_match($preg_maskgrp, $file)) {
$matched = $maskgrp;
}
if ($matched)
if ($matched) {
break;
}
}
return($matched);
}
@@ -1859,13 +1904,15 @@ class CListFolder
{
$this->list = array();
if ($hdir = opendir($path)) {
while (false !== ($file = readdir($hdir)))
while (false !== ($file = readdir($hdir))) {
$this->list[] = $file;
}
closedir($hdir);
if ($sorted)
if ($sorted) {
natcasesort($this->list);
}
}
}
/**
* Destructor

View File

@@ -70,8 +70,9 @@ class task_period_batchupload extends task_appboxAbstract
try {
$databox = databox::get_instance($sbas_id);
$path = $registry->get('GV_RootPath') . 'tmp/batches/' . $batch_id . '/';
if ( ! is_dir($path))
if ( ! is_dir($path)) {
throw new Exception(sprintf(('Batch directory \'%s\' does not exist'), $path));
}
$user = User_Adapter::getInstance($usr_id, $appbox);
$auth = new Session_Authentication_None($user);

View File

@@ -135,10 +135,11 @@ class task_period_cindexer 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)) != NULL) {
// le champ existait dans le xml, on supprime son ancienne valeur (tout le contenu)
while (($n = $ns->firstChild))
while (($n = $ns->firstChild)) {
$ns->removeChild($n);
}
} else {
// le champ n'existait pas dans le xml, on le cr<63>e
$ns = $dom->documentElement->appendChild($dom->createElement($pname));
@@ -167,7 +168,7 @@ class task_period_cindexer extends task_abstract
*/
public function xml2graphic($xml, $form)
{
if (($sxml = simplexml_load_string($xml))) { // in fact XML IS always valid here...
if (($sxml = simplexml_load_string($xml)) != FALSE) { // in fact XML IS always valid here...
?>
<script type="text/javascript">
<?php echo $form ?>.binpath.value = "<?php echo p4string::MakeString($sxml->binpath, "js", '"') ?>";
@@ -200,8 +201,9 @@ class task_period_cindexer extends task_abstract
public function printInterfaceJS()
{
$appname = 'phraseanet_indexer';
if ($this->system == 'WINDOWS')
if ($this->system == 'WINDOWS') {
$appname .= '.exe';
}
?>
<script type="text/javascript">
function calccmd()
@@ -273,8 +275,9 @@ class task_period_cindexer extends task_abstract
public function printInterfaceHTML()
{
$appname = 'phraseanet_indexer';
if ($this->system == 'WINDOWS')
if ($this->system == 'WINDOWS') {
$appname .= '.exe';
}
ob_start();
?>
<form name="graphicForm" onsubmit="return(false);" method="post">
@@ -388,28 +391,39 @@ class task_period_cindexer extends task_abstract
}
$args = array();
if ($this->host)
if ($this->host) {
$args[] = '-h=' . $this->host;
if ($this->port)
}
if ($this->port) {
$args[] = '-P=' . $this->port;
if ($this->base)
}
if ($this->base) {
$args[] = '-b=' . $this->base;
if ($this->user)
}
if ($this->user) {
$args[] = '-u=' . $this->user;
if ($this->password)
}
if ($this->password) {
$args[] = '-p=' . $this->password;
if ($this->socket)
}
if ($this->socket) {
$args[] = '--socket=' . $this->socket;
if ($this->use_sbas)
}
if ($this->use_sbas) {
$args[] = '-o';
if ($this->charset)
}
if ($this->charset) {
$args[] = '--default-character-set=' . $this->charset;
if ($this->debugmask > 0)
}
if ($this->debugmask > 0) {
$args[] = '-d=' . $this->debugmask;
if ($this->nolog)
}
if ($this->nolog) {
$args[] = '-n';
if ($this->winsvc_run)
}
if ($this->winsvc_run) {
$args[] = '--run';
}
$registry = registry::get_instance();
$logdir = p4string::addEndSlash($registry->get('GV_RootPath') . 'logs');
@@ -430,12 +444,14 @@ class task_period_cindexer extends task_abstract
break;
}
if ($this->new_status !== NULL)
if ($this->new_status !== NULL) {
$this->setState($this->new_status);
}
if ($this->exception)
if ($this->exception) {
throw $this->exception;
}
}
private function run_with_proc_open($cmd, $args)
{
@@ -453,9 +469,10 @@ class task_period_cindexer extends task_abstract
$pid = NULL;
if (is_resource($process)) {
$proc_status = proc_get_status($process);
if ($proc_status['running'])
if ($proc_status['running']) {
$pid = $proc_status['pid'];
}
}
$qsent = '';
$timetokill = NULL;
$sock = NULL;
@@ -469,8 +486,9 @@ class task_period_cindexer extends task_abstract
if (socket_connect($sock, '127.0.0.1', $this->socket) === true) {
socket_write($sock, 'Q', 1);
socket_write($sock, "\r\n", strlen("\r\n"));
for ($i = 0; $this->running && $i < 5; $i ++ )
for ($i = 0; $this->running && $i < 5; $i ++ ) {
sleep(1);
}
$qsent = 'Q';
$timetokill = time() + 10;
} else {
@@ -506,9 +524,10 @@ class task_period_cindexer extends task_abstract
}
}
}
for ($i = 0; $this->running && $i < 5; $i ++ )
for ($i = 0; $this->running && $i < 5; $i ++ ) {
sleep(1);
}
}
if ($sock) {
socket_close($sock);
@@ -516,9 +535,10 @@ class task_period_cindexer extends task_abstract
}
foreach (array_keys($pipes) as $offset) {
if (is_resource($pipes[$offset]))
if (is_resource($pipes[$offset])) {
fclose($pipes[$offset]);
}
}
proc_terminate($process); // sigint
proc_close($process);
@@ -526,8 +546,6 @@ class task_period_cindexer extends task_abstract
private function run_with_fork($cmd, $args)
{
$nullfile = $this->system == 'WINDOWS' ? 'NUL' : '/dev/null';
$pid = pcntl_fork();
if ($pid == -1) {
$this->exception = new Exception('cindexer can\'t fork', self::ERR_CANT_FORK);
@@ -561,6 +579,7 @@ class task_period_cindexer extends task_abstract
if ($this->getState() == self::STATE_TOSTOP) {
posix_kill($pid, ($sigsent = SIGINT));
$timetokill = time() + 10;
sleep(2);
}
@@ -583,7 +602,6 @@ class task_period_cindexer extends task_abstract
if ($sigsent == SIGINT && time() > $timetokill) {
// must kill cindexer
$this->log(_('task::cindexer:killing the cindexer'));
$qsent = 'K';
posix_kill($pid, ($sigsent = SIGKILL));
}
sleep(2);
@@ -594,7 +612,7 @@ class task_period_cindexer extends task_abstract
private function run_with_exec($cmd, $args)
{
$x = pcntl_exec($cmd, $args);
pcntl_exec($cmd, $args);
sleep(2);
}
}

View File

@@ -51,16 +51,17 @@ class task_period_ftp extends task_appboxAbstract
, "proxyport"
, "period"
);
if (($dom = @DOMDocument::loadXML($oldxml))) {
if (($dom = @DOMDocument::loadXML($oldxml)) != FALSE) {
$xmlchanged = false;
foreach (array("str:proxy", "str:proxyport", "str:period") as $pname) {
$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)) != NULL) {
// le champ existait dans le xml, on supprime son ancienne valeur (tout le contenu)
while (($n = $ns->firstChild))
while (($n = $ns->firstChild)) {
$ns->removeChild($n);
}
} else {
// le champ n'existait pas dans le xml, on le cree
$dom->documentElement->appendChild($dom->createTextNode("\t"));
@@ -91,7 +92,7 @@ class task_period_ftp extends task_appboxAbstract
*/
public function xml2graphic($xml, $form)
{
if (($sxml = simplexml_load_string($xml))) { // in fact XML IS always valid here...
if (($sxml = simplexml_load_string($xml)) != FALSE) { // in fact XML IS always valid here...
// ... but we could check for safe values (ex. 0 < period < 3600)
?>
<script type="text/javascript">
@@ -178,14 +179,15 @@ class task_period_ftp 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"])) != FALSE) {
$xmlchanged = false;
foreach (array("proxy", "proxyport", "period") as $f) {
if ($parm[$f] !== NULL) {
if (($ns = $domTaskSettings->getElementsByTagName($f)->item(0))) {
if (($ns = $domTaskSettings->getElementsByTagName($f)->item(0)) != NULL) {
// le champ existait dans le xml, on supprime son ancienne valeur (tout le contenu)
while (($n = $ns->firstChild))
while (($n = $ns->firstChild)) {
$ns->removeChild($n);
}
} else {
// le champ n'existait pas dans le xml, on le cree
$domTaskSettings->documentElement->appendChild($domTaskSettings->createTextNode("\t"));
@@ -197,10 +199,11 @@ class task_period_ftp extends task_appboxAbstract
$xmlchanged = true;
}
}
if ($xmlchanged)
if ($xmlchanged) {
$parm["xml"] = $domTaskSettings->saveXML();
}
}
}
// si on doit changer le xml, on verifie qu'il est valide
if ($parm["xml"] && ! @DOMDocument::loadXML($parm["xml"])) {
@@ -299,9 +302,10 @@ class task_period_ftp extends task_appboxAbstract
$stmt->closeCursor();
foreach ($rs as $rowtask) {
if (isset($ftp_exports[$rowtask["ftp_export_id"]]))
if (isset($ftp_exports[$rowtask["ftp_export_id"]])) {
$ftp_exports[$rowtask["ftp_export_id"]]["files"][] = $rowtask;
}
}
return $ftp_exports;
}
@@ -324,17 +328,19 @@ class task_period_ftp extends task_appboxAbstract
$ftpLog = $ftp_user_name . "@" . p4string::addEndSlash($ftp_server) . $ftp_export["destfolder"];
if ($ftp_export["crash"] == 0) {
$state .= $line = sprintf(
$line = sprintf(
_('task::ftp:Etat d\'envoi FTP vers le serveur' .
' "%1$s" avec le compte "%2$s" et pour destination le dossier : "%3$s"') . PHP_EOL
, $ftp_server
, $ftp_user_name
, $ftp_export["destfolder"]
);
$state .= $line;
if ($this->debug)
if ($this->debug) {
echo $line;
}
}
$state .= $line = sprintf(
_("task::ftp:TENTATIVE no %s, %s")
@@ -342,8 +348,9 @@ class task_period_ftp extends task_appboxAbstract
, " (" . date('r') . ")"
) . PHP_EOL;
if ($this->debug)
if ($this->debug) {
echo $line;
}
if (($ses_id = phrasea_create_session($usr_id)) == null) {
echo "Unable to create session\n";
@@ -398,13 +405,15 @@ class task_period_ftp extends task_appboxAbstract
$obj = array();
$basefolder = '';
if ( ! in_array(trim($ftp_export["destfolder"]), array('.', './', '')))
if ( ! in_array(trim($ftp_export["destfolder"]), array('.', './', ''))) {
$basefolder = p4string::addEndSlash($ftp_export["destfolder"]);
}
$basefolder .= $ftp_export["foldertocreate"];
if (in_array(trim($basefolder), array('.', './', '')))
if (in_array(trim($basefolder), array('.', './', ''))) {
$basefolder = '/';
}
foreach ($ftp_export['files'] as $fileid => $file) {
$base_id = $file["base_id"];
@@ -480,8 +489,9 @@ class task_period_ftp extends task_appboxAbstract
, basename($localfile), $record_id
, phrasea::sbas_names(phrasea::sbasFromBas($base_id))) . "\n<br/>";
if ($this->debug)
if ($this->debug) {
echo $line;
}
$done = $file['error'];
@@ -494,8 +504,9 @@ class task_period_ftp extends task_appboxAbstract
}
if ($ftp_export['logfile']) {
if ($this->debug)
if ($this->debug) {
echo "\nlogfile \n";
}
$date = new DateTime();
$remote_file = $date->format('U');
@@ -539,8 +550,9 @@ class task_period_ftp extends task_appboxAbstract
} catch (Exception $e) {
$state .= $line = $e . "\n";
if ($this->debug)
if ($this->debug) {
echo $line;
}
$sql = "UPDATE ftp_export SET crash=crash+1,date=now()"
. " WHERE id = :export_id";
@@ -653,10 +665,11 @@ class task_period_ftp extends task_appboxAbstract
$stmt->closeCursor();
if ($row) {
if ($row['crash'] >= $row['nbretry'])
if ($row['crash'] >= $row['nbretry']) {
$connection_status = _('Des difficultes ont ete rencontres a la connection au serveur distant');
else
} else {
$connection_status = _('La connection vers le serveur distant est OK');
}
$text_mail_sender = $row['text_mail_sender'];
$text_mail_receiver = $row['text_mail_receiver'];

View File

@@ -80,7 +80,7 @@ class task_period_ftpPull extends task_appboxAbstract
public function xml2graphic($xml, $form)
{
if (($sxml = simplexml_load_string($xml))) { // in fact XML IS always valid here...
if (($sxml = simplexml_load_string($xml)) != FALSE) { // in fact XML IS always valid here...
// ... but we could check for safe values (ex. 0 < period < 3600)
?>
<script type="text/javascript">
@@ -194,11 +194,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"])) != FALSE) {
$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)) != NULL) {
// le champ existait dans le xml, on supprime son ancienne valeur (tout le contenu)
while (($n = $ns->firstChild))
$ns->removeChild($n);

View File

@@ -74,10 +74,11 @@ class task_period_outofdate 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)) != NULL) {
// le champ existait dans le xml, on supprime son ancienne valeur (tout le contenu)
while (($n = $ns->firstChild))
while (($n = $ns->firstChild)) {
$ns->removeChild($n);
}
} else {
// le champ n'existait pas dans le xml, on le cree
$dom->documentElement->appendChild($dom->createTextNode("\t"));
@@ -105,15 +106,17 @@ class task_period_outofdate extends task_abstract
// ====================================================================
public function xml2graphic($xml, $form)
{
if (($sxml = simplexml_load_string($xml))) { // in fact XML IS always valid here...
if (($sxml = simplexml_load_string($xml)) != FALSE) { // in fact XML IS always valid here...
// ... but we could check for safe values
if ((int) ($sxml->period) < 10)
if ((int) ($sxml->period) < 10) {
$sxml->period = 10;
elseif ((int) ($sxml->period) > 1440) // 1 jour
} elseif ((int) ($sxml->period) > 1440) { // 1 jour
$sxml->period = 1440;
}
if ((string) ($sxml->delay) == '')
if ((string) ($sxml->delay) == '') {
$sxml->delay = 0;
}
?>
<script type="text/javascript">
var i;
@@ -155,8 +158,7 @@ class task_period_outofdate extends task_abstract
</script>
<?php
return("");
}
else { // ... so we NEVER come here
} else { // ... so we NEVER come here
// bad xml
return("BAD XML");
}
@@ -199,7 +201,6 @@ class task_period_outofdate extends task_abstract
// ====================================================================
public function printInterfaceJS()
{
global $parm;
?>
<script type="text/javascript">
@@ -324,8 +325,6 @@ class task_period_outofdate extends task_abstract
// ====================================================================
public function printInterfaceHTML()
{
global $usr_id;
$appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session();
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
@@ -469,13 +468,13 @@ class task_period_outofdate extends task_abstract
// ici la tache tourne tant qu'elle est active
$last_exec = 0;
$loop = 0;
while ($this->running) {
if ( ! $conn->ping()) {
$this->log(("Warning : abox connection lost, restarting in 10 min."));
for ($i = 0; $i < 60 * 10; $i ++ )
for ($i = 0; $i < 60 * 10; $i ++ ) {
sleep(1);
}
$this->running = false;
return(self::STATUS_TORESTART);
@@ -483,12 +482,14 @@ class task_period_outofdate extends task_abstract
try {
$connbas = connection::getPDOConnection($this->sbas_id);
if ( ! $connbas->ping())
if ( ! $connbas->ping()) {
throw new Exception('Mysql has gone away');
}
} catch (Exception $e) {
$this->log(("dbox connection lost, restarting in 10 min."));
for ($i = 0; $i < 60 * 10; $i ++ )
for ($i = 0; $i < 60 * 10; $i ++ ) {
sleep(1);
}
$this->running = false;
return(self::STATUS_TORESTART);
@@ -496,8 +497,6 @@ class task_period_outofdate extends task_abstract
$this->setLastExecTime();
$databox = databox::get_instance($this->sbas_id);
$sql = "SELECT * FROM task2 WHERE task_id = :task_id";
$stmt = $conn->prepare($sql);
$stmt->execute(array(':task_id' => $this->getID()));
@@ -509,12 +508,12 @@ class task_period_outofdate extends task_abstract
$ret = self::STATUS_STOPPED;
$this->running = false;
} else {
if (($this->sxTaskSettings = simplexml_load_string($row['settings']))) {
if (($this->sxTaskSettings = simplexml_load_string($row['settings'])) != FALSE) {
$period = (int) ($this->sxTaskSettings->period);
if ($period <= 0 || $period >= 24 * 60)
if ($period <= 0 || $period >= 24 * 60) {
$period = 60;
}
else {
} else {
$period = 60;
}
$this->connbas = connection::getPDOConnection($this->sbas_id);
@@ -579,10 +578,10 @@ class task_period_outofdate extends task_abstract
$stmt->closeCursor();
$nchanged += $n;
if ($n > 0)
if ($n > 0) {
$this->log(sprintf("SQL='%s' ; parms=%s - %s changes", $xsql['sql'], var_export($xsql['params']), $n));
}
else {
} else {
$this->log(sprintf("ERROR SQL='%s' ; parms=%s", $xsql['sql'], var_export($xsql['params'], true)));
}
} catch (ErrorException $e) {
@@ -608,27 +607,30 @@ class task_period_outofdate extends task_abstract
if (($field1 = trim($this->sxTaskSettings->field1)) != '') {
$date1 = time();
if (($delta = (int) ($this->sxTaskSettings->fieldDv1)) > 0) {
if ($this->sxTaskSettings->fieldDs1 == '-')
if ($this->sxTaskSettings->fieldDs1 == '-') {
$date1 += 86400 * $delta;
else
} else {
$date1 -= 86400 * $delta;
}
}
$date1 = date("YmdHis", $date1);
}
// test : DATE 2
if (($field2 = trim($this->sxTaskSettings->field2)) != '') {
$date2 = time();
if (($delta = (int) ($this->sxTaskSettings->fieldDv2)) > 0) {
if ($this->sxTaskSettings->fieldDs2 == '-')
if ($this->sxTaskSettings->fieldDs2 == '-') {
$date2 += 86400 * $delta;
else
} else {
$date2 -= 86400 * $delta;
}
}
$date2 = date("YmdHis", $date2);
}
$sqlset = $params = $tmp_params = array();
$sqlwhere = array();
for ($i = 0; $i <= 2; $i ++ ) {
$sqlwhere[$i] = '';
$sqlset[$i] = '';
@@ -771,9 +773,10 @@ class task_period_outofdate extends task_abstract
$meta_struct = $databox->get_meta_structure();
foreach ($meta_struct as $meta) {
if (mb_strtolower($meta->get_type()) == 'date')
if (mb_strtolower($meta->get_type()) == 'date') {
$ret['date_fields'][] = $meta->get_name();
}
}
$status = $databox->get_statusbits();
foreach ($status as $n => $stat) {
@@ -783,8 +786,9 @@ class task_period_outofdate extends task_abstract
$ret['status_bits'][] = array('n' => $n, 'value' => 1, 'label' => $labelon);
}
foreach ($databox->get_collections() as $collection)
foreach ($databox->get_collections() as $collection) {
$ret['collections'][] = array('id' => $collection->get_coll_id(), 'name' => $collection->get_name());
}
} catch (Exception $e) {
}

View File

@@ -77,9 +77,10 @@ class task_period_subdef extends task_databoxAbstract
$ptype = substr($pname, 0, 3);
$pname = substr($pname, 4);
$pvalue = $parm2[$pname];
if (($ns = $dom->getElementsByTagName($pname)->item(0))) {
while (($n = $ns->firstChild))
if (($ns = $dom->getElementsByTagName($pname)->item(0)) != NULL) {
while (($n = $ns->firstChild)) {
$ns->removeChild($n);
}
} else {
$ns = $dom->documentElement->appendChild($dom->createElement($pname));
}
@@ -107,32 +108,38 @@ class task_period_subdef extends task_databoxAbstract
*/
public function xml2graphic($xml, $form)
{
if (($sxml = simplexml_load_string($xml))) {
if ((int) ($sxml->period) < 10)
if (($sxml = simplexml_load_string($xml)) != FALSE) {
if ((int) ($sxml->period) < 10) {
$sxml->period = 10;
elseif ((int) ($sxml->period) > 300)
} elseif ((int) ($sxml->period) > 300) {
$sxml->period = 300;
}
if ((string) ($sxml->flush) == '')
if ((string) ($sxml->flush) == '') {
$sxml->flush = 10;
elseif ((int) ($sxml->flush) < 1)
} elseif ((int) ($sxml->flush) < 1) {
$sxml->flush = 1;
elseif ((int) ($sxml->flush) > 100)
} elseif ((int) ($sxml->flush) > 100) {
$sxml->flush = 100;
}
if ((string) ($sxml->maxrecs) == '')
if ((string) ($sxml->maxrecs) == '') {
$sxml->maxrecs = 100;
if ((int) ($sxml->maxrecs) < 10)
}
if ((int) ($sxml->maxrecs) < 10) {
$sxml->maxrecs = 10;
elseif ((int) ($sxml->maxrecs) > 500)
} elseif ((int) ($sxml->maxrecs) > 500) {
$sxml->maxrecs = 500;
}
if ((string) ($sxml->maxmegs) == '')
if ((string) ($sxml->maxmegs) == '') {
$sxml->maxmegs = 6;
if ((int) ($sxml->maxmegs) < 3)
}
if ((int) ($sxml->maxmegs) < 3) {
$sxml->maxmegs = 3;
elseif ((int) ($sxml->maxmegs) > 32)
} elseif ((int) ($sxml->maxmegs) > 32) {
$sxml->maxmegs = 32;
}
?>
<script type="text/javascript">
<?php echo $form ?>.period.value = "<?php echo p4string::MakeString($sxml->period, "js", '"') ?>";
@@ -143,8 +150,7 @@ class task_period_subdef extends task_databoxAbstract
<?php
return("");
}
else {
} else {
return("BAD XML");
}
}

View File

@@ -112,8 +112,9 @@ class task_period_upgradetov32 extends task_abstract
$stmt->closeCursor();
$total = 0;
if ($row)
if ($row) {
$total = $row['total'];
}
$sql = 'SELECT COUNT(record_id) as total FROM record WHERE migrated = 1';
$stmt = $connbas->prepare($sql);
@@ -122,8 +123,9 @@ class task_period_upgradetov32 extends task_abstract
$stmt->closeCursor();
$done = 0;
if ($row)
if ($row) {
$done = $row['total'];
}
$this->setProgress($done, $total);
@@ -195,8 +197,9 @@ class task_period_upgradetov32 extends task_abstract
$document = $record->get_subdef('document');
foreach ($document->readTechnicalDatas() as $name => $value) {
if (is_null($value))
if (is_null($value)) {
continue;
}
$stmt->execute(array(
':record_id' => $record->get_record_id()
@@ -239,7 +242,7 @@ class task_period_upgradetov32 extends task_abstract
$metadatas = array();
if ($sxe = simplexml_load_string($row['xml'])) {
if (($sxe = simplexml_load_string($row['xml'])) != FALSE) {
$z = $sxe->xpath('/record/description');
if ($z && is_array($z)) {
foreach ($z[0] as $ki => $vi) {
@@ -250,8 +253,9 @@ class task_period_upgradetov32 extends task_abstract
$value = (string) $vi;
if (trim($value) === '')
if (trim($value) === '') {
continue;
}
if ($databox_field->is_multi()) {
$new_value = caption_field::get_multi_values($value, $databox_field->get_separator());

View File

@@ -50,10 +50,11 @@ class task_period_workflow01 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)) != NULL) {
// le champ existait dans le xml, on supprime son ancienne valeur (tout le contenu)
while (($n = $ns->firstChild))
while (($n = $ns->firstChild)) {
$ns->removeChild($n);
}
} else {
// le champ n'existait pas dans le xml, on le cree
$dom->documentElement->appendChild($dom->createTextNode("\t"));
@@ -78,15 +79,17 @@ class task_period_workflow01 extends task_databoxAbstract
public function xml2graphic($xml, $form)
{
if (($sxml = simplexml_load_string($xml))) { // in fact XML IS always valid here...
if (($sxml = simplexml_load_string($xml)) != FALSE) { // in fact XML IS always valid here...
// ... but we could check for safe values
if ((int) ($sxml->period) < 1)
if ((int) ($sxml->period) < 1) {
$sxml->period = 1;
elseif ((int) ($sxml->period) > 1440) // 1 jour
} elseif ((int) ($sxml->period) > 1440) { // 1 jour
$sxml->period = 1440;
}
if ((string) ($sxml->delay) == '')
if ((string) ($sxml->delay) == '') {
$sxml->delay = 0;
}
?>
<script type="text/javascript">
var i;
@@ -119,8 +122,7 @@ class task_period_workflow01 extends task_databoxAbstract
<?php
return("");
}
else { // ... so we NEVER come here
} else { // ... so we NEVER come here
// bad xml
return("BAD XML");
}
@@ -365,9 +367,10 @@ class task_period_workflow01 extends task_databoxAbstract
// in minutes
$this->period = (int) $sx_task_settings->period * 60;
if ($this->period <= 0 || $this->period >= 24 * 60)
if ($this->period <= 0 || $this->period >= 24 * 60) {
$this->period = 60;
}
}
protected function retrieveSbasContent(databox $databox)
{
@@ -401,10 +404,11 @@ class task_period_workflow01 extends task_databoxAbstract
throw new Exception('Error in settings for status destination');
}
$sql_s .= ($sql_s ? ', ' : '');
if ((int) $x[1] === 0)
if ((int) $x[1] === 0) {
$sql_s .= 'status = status &~(1 << :stat_dst)';
else
} else {
$sql_s .= 'status = status |(1 << :stat_dst)';
}
$sql_parms[':stat_dst'] = (int) $x[0];
}
@@ -462,8 +466,9 @@ class task_period_workflow01 extends task_databoxAbstract
try {
$databox = databox::get_instance($sbas_id);
foreach ($databox->get_meta_structure() as $meta) {
if ($meta->get_type() !== 'date')
if ($meta->get_type() !== 'date') {
continue;
}
$retjs['date_fields'][] = $meta->get_name();
}
@@ -481,7 +486,7 @@ class task_period_workflow01 extends task_databoxAbstract
}
$base_ids = $user->ACL()->get_granted_base(array(), array($sbas_id));
foreach ($base_ids as $base_id => $collection) {
foreach ($base_ids as $collection) {
$retjs['collections'][] = array('id' => (string) ($collection->get_coll_id()), 'name' => $collection->get_name());
}
} catch (Exception $e) {

View File

@@ -59,10 +59,11 @@ 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)) != NULL) {
// le champ existait dans le xml, on supprime son ancienne valeur (tout le contenu)
while (($n = $ns->firstChild))
while (($n = $ns->firstChild)) {
$ns->removeChild($n);
}
} else {
// le champ n'existait pas dans le xml, on le cree
$dom->documentElement->appendChild($dom->createTextNode("\t"));
@@ -87,26 +88,31 @@ class task_period_writemeta extends task_databoxAbstract
public function xml2graphic($xml, $form)
{
if (($sxml = simplexml_load_string($xml))) { // in fact XML IS always valid here...
if (($sxml = simplexml_load_string($xml)) != FALSE) { // in fact XML IS always valid here...
// ... but we could check for safe values (ex. 0 < period < 3600)
if ((int) ($sxml->period) < 10)
if ((int) ($sxml->period) < 10) {
$sxml->period = 10;
elseif ((int) ($sxml->period) > 300)
} elseif ((int) ($sxml->period) > 300) {
$sxml->period = 300;
}
if ((string) ($sxml->maxrecs) == '')
if ((string) ($sxml->maxrecs) == '') {
$sxml->maxrecs = 100;
if ((int) ($sxml->maxrecs) < 10)
}
if ((int) ($sxml->maxrecs) < 10) {
$sxml->maxrecs = 10;
elseif ((int) ($sxml->maxrecs) > 500)
} elseif ((int) ($sxml->maxrecs) > 500) {
$sxml->maxrecs = 500;
}
if ((string) ($sxml->maxmegs) == '')
if ((string) ($sxml->maxmegs) == '') {
$sxml->maxmegs = 6;
if ((int) ($sxml->maxmegs) < 3)
}
if ((int) ($sxml->maxmegs) < 3) {
$sxml->maxmegs = 3;
elseif ((int) ($sxml->maxmegs) > 32)
} elseif ((int) ($sxml->maxmegs) > 32) {
$sxml->maxmegs = 32;
}
?>
<script type="text/javascript">
<?php echo $form ?>.period.value = "<?php echo p4string::MakeString($sxml->period, "js", '"') ?>";
@@ -116,8 +122,7 @@ class task_period_writemeta extends task_databoxAbstract
</script>
<?php
return("");
}
else { // ... so we NEVER come here
} else { // ... so we NEVER come here
// bad xml
return("BAD XML");
}
@@ -217,10 +222,11 @@ class task_period_writemeta extends task_databoxAbstract
foreach ($subdefgroups as $type => $subdefs) {
foreach ($subdefs as $sub) {
$name = $sub->get_name();
if ($sub->meta_writeable())
if ($sub->meta_writeable()) {
$metasubdefs[$name . '_' . $type] = true;
}
}
}
$this->metasubdefs = $metasubdefs;

View File

@@ -29,10 +29,11 @@ switch ($parm['action']) {
$output = module_admin::getTree($parm['position']);
break;
case 'APACHE':
if ($parm['test'] == 'success')
if ($parm['test'] == 'success') {
$output = '1';
else
} else {
$output = '0';
}
break;
case 'SCHEDULERKEY':
$output = $registry->get('GV_ServerName') . 'admin/runscheduler.php?key=' . urlencode(phrasea::scheduler_key( ! ! $parm['renew']));
@@ -114,8 +115,9 @@ switch ($parm['action']) {
$pid = (int) ($task->getPID());
$task->setState($parm["status"]);
$signal = (int) ($parm['signal']);
if ($signal > 0 && $pid)
if ($signal > 0 && $pid) {
posix_kill($pid, $signal);
}
} catch (Exception $e) {
}
@@ -167,8 +169,9 @@ switch ($parm['action']) {
* @todo checker, cette methode n'est pas implementee partout
*/
$root->setAttribute("crashed", $task->getCrashCounter());
if ($task->saveChanges($conn, $parm["task_id"], $row))
if ($task->saveChanges($conn, $parm["task_id"], $row)) {
$root->setAttribute("saved", "1");
}
} catch (Exception $e) {
}
@@ -206,10 +209,11 @@ switch ($parm['action']) {
$stmt->closeCursor();
$ret['db_processlist'] = array();
foreach ($rows as $row) {
if ($row['Info'] != $sql)
if ($row['Info'] != $sql) {
$ret['db_processlist'][] = $row;
}
}
}
$output = p4string::jsonencode($ret);
break;
@@ -252,8 +256,9 @@ switch ($parm['action']) {
$ret['xml_indexed'] = $datas['xml_indexed'];
$ret['thesaurus_indexed'] = $datas['thesaurus_indexed'];
if (file_exists($registry->get('GV_RootPath') . 'config/minilogos/logopdf_' . $parm['sbas_id'] . '.jpg'))
if (file_exists($registry->get('GV_RootPath') . 'config/minilogos/logopdf_' . $parm['sbas_id'] . '.jpg')) {
$ret['printLogoURL'] = '/print/' . $parm['sbas_id'];
}
$output = p4string::jsonencode($ret);
break;

View File

@@ -29,35 +29,38 @@ $appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session();
define("DEFAULT_MIMETYPE", "application/octet-stream");
if ($request->comes_from_flash())
if ($request->comes_from_flash()) {
define("UPLOADER", "FLASH");
else
} else {
define("UPLOADER", "HTML");
}
if ( ! isset($_FILES['Filedata'])) {
if (UPLOADER == 'FLASH')
if (UPLOADER == 'FLASH') {
header('HTTP/1.1 500 Internal Server Error');
else
} else {
echo '<script type="text/javascript">parent.classic_uploaded("' . _("Internal Server Error") . '")</script>';
}
exit;
}
if ($_FILES['Filedata']['error'] > 0) {
if (UPLOADER == 'FLASH')
if (UPLOADER == 'FLASH') {
header('HTTP/1.1 500 Internal Server Error');
else
} else {
echo '<script type="text/javascript">parent.classic_uploaded("' . _("Internal Server Error") . '")</script>';
}
exit(0);
}
if ( ! move_uploaded_file($_FILES['Filedata']['tmp_name'], $_FILES['Filedata']['tmp_name'] . '_muf')) {
if (UPLOADER == 'FLASH')
if (UPLOADER == 'FLASH') {
header('HTTP/1.1 500 Internal Server Error');
else
} else {
echo '<script type="text/javascript">parent.classic_uploaded("' . _("Internal Server Error") . '")</script>';
}
exit(0);
}
else {
} else {
$_FILES['Filedata']['tmp_name'].='_muf';
}
@@ -87,12 +90,13 @@ if ($sbas_id !== false && is_array($parm['status'])) {
foreach ($parm['status'] as $k => $v) {
if ((int) $k <= 63 && (int) $k >= 4) {
if ($v == '0')
if ($v == '0') {
$mask_non[63 - (int) $k] = $v;
elseif ($v == '1')
} elseif ($v == '1') {
$mask_oui[63 - (int) $k] = $v;
}
}
}
}
$filename = new system_file($_FILES['Filedata']['tmp_name']);
@@ -104,10 +108,12 @@ try {
try {
$tmp_record = record_adapter::get_record_by_sha($sbas_id, $sha256);
if ( ! $tmp_record)
if ( ! $tmp_record) {
throw new Exception('bad luck');
if (is_array($tmp_record))
}
if (is_array($tmp_record)) {
$tmp_record = array_shift($tmp_record);
}
$tmp_uuid = $tmp_record->get_uuid();
@@ -126,34 +132,35 @@ try {
// file already exists in base
if ( ! lazaretFile::move_uploaded_to_lazaret($filename, $base_id, $_FILES['Filedata']["name"], implode("\n", $error_file), $status_2)) {
// move in lazaret failed
if (UPLOADER == 'FLASH')
if (UPLOADER == 'FLASH') {
header('HTTP/1.1 500 Internal Server Error');
else
} else {
echo '<script type="text/javascript">parent.classic_uploaded("' . _("erreur lors de l'archivage") . '")</script>';
}
else {
} else {
// move in lazaret succeed
if (UPLOADER == 'HTML')
if (UPLOADER == 'HTML') {
echo '<script type="text/javascript">parent.classic_uploaded("' . _('Document ajoute a la quarantaine') . '")</script>';
}
}
if (UPLOADER == 'HTML')
if (UPLOADER == 'HTML') {
echo '<script type="text/javascript">parent.classic_uploaded("' . _("Fichier uploade, en attente") . '")</script>';
}
unset($filename);
unlink($_FILES['Filedata']['tmp_name']);
exit;
}
else {
} else {
// file does not exists in base, we can archive
if (($record_id = p4file::archiveFile($filename, $base_id, true, $_FILES['Filedata']["name"])) === false) {
// archive failed
if (UPLOADER == 'FLASH')
if (UPLOADER == 'FLASH') {
header('HTTP/1.1 500 Internal Server Error');
else
} else {
echo '<script type="text/javascript">parent.classic_uploaded("' . _("erreur lors de l'archivage") . '")</script>';
}
else {
} else {
// archive succeed
if ($chStatus === true && $sbas_id !== false && is_array($parm['status'])) {
try {
@@ -164,10 +171,12 @@ try {
}
}
if (UPLOADER == 'HTML')
if (UPLOADER == 'HTML') {
echo '<script type="text/javascript">parent.classic_uploaded("' . _("Fichier uploade !") . '")</script>';
}
}
}
exit(0);
} catch (Exception $e) {