diff --git a/config/config.sample.yml b/config/config.sample.yml
index 9e290f1969..b6874ea2a3 100644
--- a/config/config.sample.yml
+++ b/config/config.sample.yml
@@ -30,6 +30,7 @@ dev:
opcodecache: array_cache
border-manager: border_manager
search-engine: phrasea
+ task-manager: config_taskmanager
##############
# PRODUCTION #
@@ -48,6 +49,7 @@ prod:
opcodecache: array_cache
border-manager: border_manager
search-engine: phrasea
+ task-manager: config_taskmanager
##############
# TEST #
@@ -66,4 +68,5 @@ test:
opcodecache: array_cache
border-manager: border_manager
search-engine: phrasea
+ task-manager: config_taskmanager
diff --git a/config/services.sample.yml b/config/services.sample.yml
index d28dd167fb..2ae1105aea 100644
--- a/config/services.sample.yml
+++ b/config/services.sample.yml
@@ -205,3 +205,11 @@ SearchEngine:
port: 9306
rt_host: localhost
rt_port: 9308
+TaskManager:
+ config_taskmanager:
+ type: TaskManager\TaskManager
+ options:
+ # set the threshold for sending task logs to syslog or by mail
+ # values : task_abstract::[LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERROR | LOG_CRITICAL | LOG_ALERT]
+ syslog_level: task_abstract::LOG_ERROR
+ maillog_level: task_abstract::LOG_ERROR
diff --git a/lib/Alchemy/Phrasea/Core/Configuration.php b/lib/Alchemy/Phrasea/Core/Configuration.php
index adec865d30..cc13bfaabf 100644
--- a/lib/Alchemy/Phrasea/Core/Configuration.php
+++ b/lib/Alchemy/Phrasea/Core/Configuration.php
@@ -294,6 +294,11 @@ class Configuration
return 'Border\\' . $this->configuration->get('border-manager');
}
+ public function getTaskManager()
+ {
+ return 'TaskManager\\' . $this->configuration->get('task-manager');
+ }
+
/**
* Return the selected service configuration
*
diff --git a/lib/Alchemy/Phrasea/Core/Provider/TaskManagerServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/TaskManagerServiceProvider.php
index 6d1e7ff418..9b79b83038 100644
--- a/lib/Alchemy/Phrasea/Core/Provider/TaskManagerServiceProvider.php
+++ b/lib/Alchemy/Phrasea/Core/Provider/TaskManagerServiceProvider.php
@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\Core\Provider;
+use Alchemy\Phrasea\Core\Service\Builder;
use Silex\Application;
use Silex\ServiceProviderInterface;
@@ -19,9 +20,14 @@ class TaskManagerServiceProvider implements ServiceProviderInterface
public function register(Application $app)
{
- $app['task-manager'] = $app->share(function($app) {
- return new \task_manager($app);
- });
+ $app['task-manager'] = $app->share(function(Application $app) {
+
+ $configuration = $app['phraseanet.configuration']
+ ->getService($app['phraseanet.configuration']->getTaskManager());
+
+ $service = Builder::create($app, $configuration);
+ return $service->getDriver();
+ });
}
public function boot(Application $app)
diff --git a/lib/Alchemy/Phrasea/Core/Service/TaskManager/TaskManager.php b/lib/Alchemy/Phrasea/Core/Service/TaskManager/TaskManager.php
new file mode 100644
index 0000000000..241ef1c276
--- /dev/null
+++ b/lib/Alchemy/Phrasea/Core/Service/TaskManager/TaskManager.php
@@ -0,0 +1,113 @@
+getOptions();
+ $logger = $this->extendsLogger(clone $this->app['monolog'], $options);
+
+ $this->taskManager = new \task_manager($this->app, $logger);
+ }
+
+ private function extendsLogger(\Monolog\Logger $logger, $options)
+ {
+ $options = $this->getOptions();
+ $registry = $this->app['phraseanet.registry'];
+
+ // send log to syslog ?
+ if (null !== ($syslogLevel = constant($options['syslog_level']))) {
+ $handler = new Handler\SyslogHandler(
+ "Phraseanet-Task", // string added to each message
+ "user", // facility (type of program logging)
+ $syslogLevel, // level
+ true // bubble
+ );
+ $logger->pushHandler($handler);
+ }
+
+ // send log by mail ?
+ if (null !== ($maillogLevel = constant($options['maillog_level']))) {
+ if (($adminMail = $registry->get('GV_adminMail')) == '') {
+ throw(new RuntimeException(sprintf(
+ "Admininstrator mail must be set to get log by mail."))
+ );
+ }
+ $senderMail = $registry->get('GV_defaultmailsenderaddr');
+
+ $handler = new Handler\NativeMailerHandler(
+ $adminMail,
+ "Phraseanet-Task",
+ $senderMail,
+ $maillogLevel, // level
+ true
+ );
+ $logger->pushHandler($handler);
+ }
+
+ return $logger;
+ }
+
+ /**
+ * Set and return a new Border Manager instance and set the proper checkers
+ * according to the services configuration
+ *
+ * @return \Alchemy\Phrasea\Border\Manager
+ */
+ public function getDriver()
+ {
+ return $this->taskManager;
+ }
+
+ /**
+ * Return the type of the service
+ * @return string
+ */
+ public function getType()
+ {
+ return 'task-manager';
+ }
+
+ /**
+ * Define the mandatory option for the current services
+ * @return array
+ */
+ public function getMandatoryOptions()
+ {
+ return array();
+ // return array('enabled', 'checkers');
+ }
+
+}
diff --git a/lib/classes/API/V1/adapter.php b/lib/classes/API/V1/adapter.php
index 44c8f83a9d..c6696731bb 100644
--- a/lib/classes/API/V1/adapter.php
+++ b/lib/classes/API/V1/adapter.php
@@ -101,7 +101,7 @@ class API_V1_adapter extends API_V1_Abstract
{
$result = new \API_V1_result($app['request'], $this);
- $taskManager = new \task_manager($app);
+ $taskManager = $app['task-manager'];
$ret = $taskManager->getSchedulerState();
$ret['state'] = $ret['status'];
@@ -127,7 +127,7 @@ class API_V1_adapter extends API_V1_Abstract
{
$result = new \API_V1_result($app['request'], $this);
- $taskManager = new \task_manager($app);
+ $taskManager = $app['task-manager'];
$tasks = $taskManager->getTasks();
$ret = array();
@@ -166,7 +166,7 @@ class API_V1_adapter extends API_V1_Abstract
{
$result = new \API_V1_result($app['request'], $this);
- $taskManager = new task_manager($app);
+ $taskManager = $app['task-manager'];
$ret = array(
'task' => $this->list_task($taskManager->getTask($taskId))
@@ -188,7 +188,7 @@ class API_V1_adapter extends API_V1_Abstract
{
$result = new \API_V1_result($app['request'], $this);
- $taskManager = new \task_manager($app);
+ $taskManager = $app['task-manager'];
$task = $taskManager->getTask($taskId);
if (!in_array($task->getState(), array(\task_abstract::STATE_TOSTART, \task_abstract::STATE_STARTED))) {
@@ -211,7 +211,7 @@ class API_V1_adapter extends API_V1_Abstract
{
$result = new API_V1_result($app['request'], $this);
- $taskManager = new \task_manager($app);
+ $taskManager = $app['task-manager'];
$task = $taskManager->getTask($taskId);
if (!in_array($task->getState(), array(\task_abstract::STATE_TOSTOP, \task_abstract::STATE_STOPPED))) {
@@ -243,7 +243,7 @@ class API_V1_adapter extends API_V1_Abstract
throw new \API_V1_exception_badrequest();
}
- $taskManager = new \task_manager($app);
+ $taskManager = $app['task-manager'];
$task = $taskManager->getTask($taskId);
diff --git a/lib/classes/module/console/schedulerState.php b/lib/classes/module/console/schedulerState.php
index a7e3bea532..e420b93c35 100644
--- a/lib/classes/module/console/schedulerState.php
+++ b/lib/classes/module/console/schedulerState.php
@@ -55,7 +55,7 @@ class module_console_schedulerState extends Command
return self::EXITCODE_SETUP_ERROR;
}
- $task_manager = new task_manager($this->container);
+ $task_manager = $this->container['task-manager'];
$exitCode = 0;
$state = $task_manager->getSchedulerState();
diff --git a/lib/classes/module/console/schedulerStop.php b/lib/classes/module/console/schedulerStop.php
index d64c74f101..7a1027b971 100644
--- a/lib/classes/module/console/schedulerStop.php
+++ b/lib/classes/module/console/schedulerStop.php
@@ -34,7 +34,7 @@ class module_console_schedulerStop extends Command
protected function doExecute(InputInterface $input, OutputInterface $output)
{
try {
- $task_manager = new task_manager($this->container);
+ $task_manager = $this->container['task-manager'];
$task_manager->setSchedulerState(task_manager::STATE_TOSTOP);
return 0;
diff --git a/lib/classes/module/console/taskState.php b/lib/classes/module/console/taskState.php
index 6d9dab9428..274dec4903 100644
--- a/lib/classes/module/console/taskState.php
+++ b/lib/classes/module/console/taskState.php
@@ -70,7 +70,7 @@ class module_console_taskState extends Command
return self::EXITCODE_BAD_ARGUMENT;
}
- $task_manager = new task_manager($this->container);
+ $task_manager = $this->container['task-manager'];
$taskPID = $taskState = NULL;
$exitCode = 0;
diff --git a/lib/classes/module/console/tasklist.php b/lib/classes/module/console/tasklist.php
index fc9aeafa79..19c1c69a3e 100644
--- a/lib/classes/module/console/tasklist.php
+++ b/lib/classes/module/console/tasklist.php
@@ -39,7 +39,7 @@ class module_console_tasklist extends Command
}
try {
- $task_manager = new task_manager($this->container);
+ $task_manager = $this->container['task-manager'];
$tasks = $task_manager->getTasks();
if (count($tasks) === 0) {
diff --git a/lib/classes/module/console/taskrun.php b/lib/classes/module/console/taskrun.php
index 2beb88c590..da673a665c 100644
--- a/lib/classes/module/console/taskrun.php
+++ b/lib/classes/module/console/taskrun.php
@@ -44,11 +44,11 @@ class module_console_taskrun extends Command
, task_abstract::RUNNER_MANUAL
);
$this->addOption(
- 'nolog'
- , NULL
- , 1 | InputOption::VALUE_NONE
- , 'do not log to logfile'
- , NULL
+ 'ttylogLevel'
+ , 't'
+ , InputOption::VALUE_REQUIRED
+ , 'threshold : (DEBUG|INFO|WARNING|ERROR|CRITICAL|ALERT)'
+ , ''
);
$this->setDescription('Run task');
@@ -74,7 +74,8 @@ class module_console_taskrun extends Command
throw new \RuntimeException('Argument must be an Id.');
}
- $task_manager = new task_manager($this->container);
+ $task_manager = $this->container['task-manager'];
+ $logger = $task_manager->getLogger();
if ($input->getOption('runner') === task_abstract::RUNNER_MANUAL) {
$schedStatus = $task_manager->getSchedulerState();
@@ -102,6 +103,44 @@ class module_console_taskrun extends Command
$this->container['monolog']->pushHandler($handler);
$this->task = $task_manager->getTask($task_id, $this->container['monolog']);
+ $lib2v = array(
+ 'DEBUG' => task_abstract::LOG_DEBUG,
+ 'INFO' => task_abstract::LOG_INFO,
+ 'WARNING' => task_abstract::LOG_WARNING,
+ 'ERROR' => task_abstract::LOG_ERROR,
+ 'CRITICAL' => task_abstract::LOG_CRITICAL,
+ 'ALERT' => task_abstract::LOG_ALERT
+ );
+
+ $tmpTask = $task_manager->getTask($task_id, null);
+ $taskname = $tmpTask->getName();
+ unset($tmpTask);
+
+
+ // log to tty ?
+
+ if(($ttylogLevel = strtoupper($input->getOption('ttylogLevel'))) != '') {
+ if (!array_key_exists($ttylogLevel, $lib2v)) {
+ throw(new RuntimeException(sprintf(
+ "Bad value '%s' for option loglevel\nuse DEBUG|INFO|WARNING|ERROR|CRITICAL|ALERT", $ttylogLevel))
+ );
+ }
+ $handler = new Handler\StreamHandler(
+ "php://stdout",
+ $lib2v[$ttylogLevel],
+ true
+ );
+ $logger->pushHandler($handler);
+ }
+
+ $logfile = __DIR__ . '/../../../../logs/task_' . $task_id . '.log';
+ $handler = new Handler\RotatingFileHandler($logfile, 10); //, $lib2v[$loglevelOption], true);
+ $logger->pushHandler($handler);
+
+
+ $this->task = $task_manager->getTask($task_id, $logger);
+
+
register_tick_function(array($this, 'tick_handler'), true);
declare(ticks = 1);
diff --git a/lib/classes/patch/370a8.php b/lib/classes/patch/370a8.php
index b1845748af..c84d428d78 100644
--- a/lib/classes/patch/370a8.php
+++ b/lib/classes/patch/370a8.php
@@ -62,7 +62,7 @@ class patch_370a8 implements patchInterface
*/
public function apply(base $appbox, Application $app)
{
- $task_manager = new task_manager($app);
+ $taskManager = $app['task-manager'];
$ttasks = array();
$conn = $appbox->get_connection();
diff --git a/lib/classes/sso.php b/lib/classes/sso.php
index 7c2564ae29..e59cd5bed1 100644
--- a/lib/classes/sso.php
+++ b/lib/classes/sso.php
@@ -2,5 +2,8 @@
class sso
{
-
+ public function get_login()
+ {
+ return "";
+ }
}
diff --git a/lib/classes/task/Scheduler.php b/lib/classes/task/Scheduler.php
index ea7663768a..17f5dae995 100644
--- a/lib/classes/task/Scheduler.php
+++ b/lib/classes/task/Scheduler.php
@@ -126,7 +126,7 @@ class task_Scheduler
$sql = "UPDATE sitepreff SET schedstatus='started'";
$conn->exec($sql);
- $task_manager = new task_manager($this->dependencyContainer);
+ $task_manager = $this->dependencyContainer['task-manager'];
// set every 'auto-start' task to start
foreach ($task_manager->getTasks() as $task) {
diff --git a/lib/classes/task/abstract.php b/lib/classes/task/abstract.php
index ddde9b3296..cf07f883e4 100644
--- a/lib/classes/task/abstract.php
+++ b/lib/classes/task/abstract.php
@@ -22,6 +22,27 @@ abstract class task_abstract
const SIGNAL_SCHEDULER_DIED = 'SIGNAL_SCHEDULER_DIED';
const ERR_ALREADY_RUNNING = 114; // aka EALREADY (Operation already in progress)
+ // default min/max values for the 'restart task every n records' setting on tasks
+ const MINRECS = 10;
+ const MAXRECS = 100;
+ // default min/max values for the 'overflow memory (Mo)' setting on tasks
+ const MINMEGS = 20;
+ const MAXMEGS = 256;
+ // default min/max values for the 'period (seconds)' setting on tasks
+ const MINPERIOD = 10;
+ const MAXPERIOD = 3600;
+ // default min/max values for the 'flush every n records' setting on tasks
+ const MINFLUSH = 1;
+ const MAXFLUSH = 100;
+
+ const LOG_DEBUG = Logger::DEBUG;
+ const LOG_INFO = Logger::INFO;
+ const LOG_WARNING = Logger::WARNING;
+ const LOG_ERROR = Logger::ERROR;
+ const LOG_CRITICAL = Logger::CRITICAL;
+ const LOG_ALERT = Logger::ALERT;
+
+
/**
*
* @var Logger
@@ -677,7 +698,7 @@ abstract class task_abstract
$current_memory = memory_get_usage();
if ($current_memory >> 20 >= $this->maxmegs) {
- $this->log(sprintf("Max memory (%s M) reached (actual is %.02f M)", $this->maxmegs, ($current_memory >> 10) / 1024));
+ $this->log(sprintf("Max memory (%s M) reached (actual is %.02f M)", $this->maxmegs, ($current_memory >> 10) / 1024), self::LOG_ERROR);
$this->running = FALSE;
$ret = self::STATE_MAXMEGSREACHED;
}
@@ -707,7 +728,7 @@ abstract class task_abstract
$current_memory = memory_get_usage();
if ($current_memory >> 20 >= $this->maxmegs) {
- $this->log(sprintf("Max memory (%s M) reached (current is %.02f M)", $this->maxmegs, ($current_memory >> 10) / 1024));
+ $this->log(sprintf("Max memory (%s M) reached (current is %.02f M)", $this->maxmegs, ($current_memory >> 10) / 1024), self::LOG_ERROR);
$this->running = FALSE;
$ret = self::STATE_MAXMEGSREACHED;
}
@@ -739,21 +760,23 @@ abstract class task_abstract
protected function loadSettings(SimpleXMLElement $sx_task_settings)
{
$this->period = (integer) $sx_task_settings->period;
- if ($this->period <= 0 || $this->period >= 60 * 60) {
- $this->period = 60;
+ if ($this->period < self::MINPERIOD || $this->period > self::MAXPERIOD) {
+ $this->period = self::MINPERIOD;
}
$this->maxrecs = (integer) $sx_task_settings->maxrecs;
- if ($sx_task_settings->maxrecs < 10 || $sx_task_settings->maxrecs > 1000) {
- $this->maxrecs = 100;
+ if ($sx_task_settings->maxrecs < self::MINRECS || $sx_task_settings->maxrecs > self::MAXRECS) {
+ $this->maxrecs = self::MINRECS;
}
+
$this->maxmegs = (integer) $sx_task_settings->maxmegs;
- if ($sx_task_settings->maxmegs < 16 || $sx_task_settings->maxmegs > 512) {
- $this->maxmegs = 24;
+ if ($sx_task_settings->maxmegs < self::MINMEGS || $sx_task_settings->maxmegs > self::MAXMEGS) {
+ $this->maxmegs = self::MINMEGS;
}
+
$this->record_buffer_size = (integer) $sx_task_settings->flush;
- if ($sx_task_settings->flush < 1 || $sx_task_settings->flush > 100) {
- $this->record_buffer_size = 10;
+ if ($sx_task_settings->flush < self::MINFLUSH || $sx_task_settings->flush > self::MAXFLUSH) {
+ $this->record_buffer_size = self::MINFLUSH;
}
}
@@ -783,10 +806,11 @@ abstract class task_abstract
$this->logger->addDebug(memory_get_usage() . " -- " . memory_get_usage(true));
}
- public function log($message)
+ public function log($message, $level=self::LOG_INFO)
{
+ // nb : self::log_levels ARE standard log levels, ok with monolog
if ($this->logger) {
- $this->logger->addInfo($message);
+ $this->logger->addRecord($level, $message);
}
return $this;
diff --git a/lib/classes/task/databoxAbstract.php b/lib/classes/task/databoxAbstract.php
index d274e39c99..139b5ea593 100644
--- a/lib/classes/task/databoxAbstract.php
+++ b/lib/classes/task/databoxAbstract.php
@@ -34,9 +34,9 @@ abstract class task_databoxAbstract extends task_abstract
try {
$conn = connection::getPDOConnection($this->dependencyContainer);
} catch (PDOException $e) {
- $this->log($e->getMessage());
+ $this->log($e->getMessage(), self::LOG_ERROR );
if ($this->getRunner() == self::RUNNER_SCHEDULER) {
- $this->log(("Warning : abox connection lost, restarting in 10 min."));
+ $this->log(("appbox connection lost, restarting in 10 min."), self::LOG_ERROR);
// DON'T do sleep(600) because it prevents ticks !
for ($t = 60 * 10; $this->running && $t; $t -- ) {
@@ -47,6 +47,7 @@ abstract class task_databoxAbstract extends task_abstract
// will enforce the scheduler to restart the task
} else {
// runner = manual : can't restart so simply quit
+ $this->log(("appbox connection lost, quit."), self::LOG_ERROR);
}
$this->running = FALSE;
@@ -81,20 +82,29 @@ abstract class task_databoxAbstract extends task_abstract
}
$this->sbas_id = (int) $row['sbas_id'];
- $this->log('This task works now on ' . phrasea::sbas_names($this->sbas_id, $this->dependencyContainer));
+ $this->log(sprintf('This task works now on sbasid=%s ', $this->sbas_id), self::LOG_INFO);
try {
// get the records to process
$databox = $this->dependencyContainer['phraseanet.appbox']->get_databox((int) $row['sbas_id']);
} catch (Exception $e) {
- $this->log(sprintf('Warning : can\' connect to sbas(%s)', $row['sbas_id']));
+ $this->log(sprintf(
+ 'can\'t connect to sbas(%s) because "%s"'
+ , $row['sbas_id']
+ , $e->getMessage())
+ , self::LOG_WARNING
+ );
continue;
}
try {
$this->loadSettings(simplexml_load_string($row['settings']));
} catch (Exception $e) {
- $this->log($e->getMessage());
+ $this->log(sprintf(
+ 'can\'t get get settings of task because "%s"'
+ , $e->getMessage())
+ , self::LOG_WARNING
+ );
continue;
}
@@ -139,7 +149,7 @@ abstract class task_databoxAbstract extends task_abstract
if ($task_must_delete) {
$this->setState(self::STATE_TODELETE);
- $this->log('task will self delete');
+ $this->log('task will self delete', self::LOG_INFO);
}
return;
@@ -160,7 +170,7 @@ abstract class task_databoxAbstract extends task_abstract
// process the records
$ret = $this->processLoop($databox, $rs);
} catch (Exception $e) {
- $this->log('Error : ' . $e->getMessage());
+ $this->log($e->getMessage(), self::LOG_ERROR);
}
return $ret;
diff --git a/lib/classes/task/manager.php b/lib/classes/task/manager.php
index ff98cb75e3..48940f0cac 100644
--- a/lib/classes/task/manager.php
+++ b/lib/classes/task/manager.php
@@ -26,15 +26,22 @@ class task_manager
const STATE_TOSTOP = 'tostop';
protected $app;
+ protected $logger;
protected $tasks;
- public function __construct(Application $app)
+ public function __construct(Application $app, Logger $logger)
{
$this->app = $app;
+ $this->logger = $logger;
return $this;
}
+ public function getLogger()
+ {
+ return $this->logger;
+ }
+
/**
* status of scheduler and tasks
* used do refresh the taskmanager page
@@ -67,16 +74,12 @@ class task_manager
return $ret;
}
- public function getTasks($refresh = false, Logger $logger = null)
+ public function getTasks($refresh = false)
{
if ($this->tasks && !$refresh) {
return $this->tasks;
}
- if (!$logger) {
- $logger = $this->app['monolog'];
- }
-
$sql = "SELECT task2.* FROM task2 ORDER BY task_id ASC";
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute();
@@ -93,7 +96,7 @@ class task_manager
continue;
}
try {
- $tasks[$row['task_id']] = new $classname($row['task_id'], $this->app, $logger);
+ $tasks[$row['task_id']] = new $classname($row['task_id'], $this->app, $this->logger);
} catch (Exception $e) {
}
@@ -109,13 +112,9 @@ class task_manager
* @param int $task_id
* @return task_abstract
*/
- public function getTask($task_id, Logger $logger = null)
+ public function getTask($task_id)
{
- if (!$logger) {
- $logger = $this->app['monolog'];
- }
-
- $tasks = $this->getTasks(false, $logger);
+ $tasks = $this->getTasks(false);
if (!isset($tasks[$task_id])) {
throw new Exception_NotFound('Unknown task_id ' . $task_id);
diff --git a/lib/classes/task/period/RecordMover.php b/lib/classes/task/period/RecordMover.php
index 3a658c79d6..91650342f3 100644
--- a/lib/classes/task/period/RecordMover.php
+++ b/lib/classes/task/period/RecordMover.php
@@ -45,7 +45,8 @@ class task_period_RecordMover extends task_appboxAbstract
$request = http_request::getInstance();
$parm2 = $request->get_parms(
- "period", "logsql"
+ 'period'
+ , 'logsql'
);
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
@@ -53,10 +54,9 @@ class task_period_RecordMover extends task_appboxAbstract
if ($dom->loadXML($oldxml)) {
$xmlchanged = false;
- // foreach($parm2 as $pname=>$pvalue)
foreach (array(
- "str:period",
- "boo:logsql"
+ 'str:period'
+ , 'boo:logsql'
) as $pname) {
$ptype = substr($pname, 0, 3);
$pname = substr($pname, 4);
@@ -67,13 +67,12 @@ class task_period_RecordMover extends task_appboxAbstract
$ns->removeChild($n);
} else {
// field did not exists, create it
- $dom->documentElement->appendChild($dom->createTextNode("\t"));
$ns = $dom->documentElement->appendChild($dom->createElement($pname));
- $dom->documentElement->appendChild($dom->createTextNode("\n"));
}
// set the value
switch ($ptype) {
case "str":
+ case "pop":
$ns->appendChild($dom->createTextNode($pvalue));
break;
case "boo":
@@ -87,113 +86,6 @@ class task_period_RecordMover extends task_appboxAbstract
return $dom->saveXML();
}
- /**
- * must fill the gui (using js) from xml
- *
- * @param string $xml
- * @param form-object $form
- * @return string "" or error message
- */
- public function xml2graphic($xml, $form)
- {
- if (false !== $sxml = simplexml_load_string($xml)) {
- if ((int) ($sxml->period) < 10)
- $sxml->period = 10;
- elseif ((int) ($sxml->period) > 1440) // 1 jour
- $sxml->period = 1440;
-
- if ((string) ($sxml->delay) == '')
- $sxml->delay = 0;
- ?>
-
-
+ return json;
+ };
+ })( jQuery );
+
+ var limits = {
+ 'period':{'min':, 'max':},
+ 'delay':{min:0}
+ } ;
+ $(".formElem").change(function(){
+ fieldname = $(this).attr("name");
+ switch((this.nodeName+$(this).attr("type")).toLowerCase())
+ {
+ case "inputtext":
+ if (typeof(limits[fieldname])!='undefined') {
+ var v = 0|this.value;
+ if(v < limits[fieldname].min)
+ v = limits[fieldname].min;
+ else if(v > limits[fieldname].max)
+ v = limits[fieldname].max;
+ this.value = v;
+ }
+ break;
+ }
+ setDirty();
+ });
+ }
+ );
+
+
-
@@ -427,26 +335,26 @@ class task_period_RecordMover extends task_appboxAbstract
foreach ($this->sxTaskSettings->tasks->task as $sxtask) {
- if ( ! $this->running) {
+ if (!$this->running) {
break;
}
$task = $this->calcSQL($sxtask);
- if ( ! $task['active']) {
+ if (!$task['active']) {
continue;
}
if ($logsql) {
$this->log(sprintf("playing task '%s' on base '%s'"
, $task['name']
- , $task['basename'] ? $task['basename'] : ''));
+ , $task['basename'] ? $task['basename'] : ''), self::LOG_INFO);
}
try {
$connbas = connection::getPDOConnection($this->dependencyContainer, $task['sbas_id']);
} catch (Exception $e) {
- $this->log(sprintf("can't connect sbas %s", $task['sbas_id']));
+ $this->log(sprintf("can't connect sbas %s", $task['sbas_id']), self::LOG_ERROR);
continue;
}
@@ -762,7 +670,7 @@ class task_period_RecordMover extends task_appboxAbstract
// criteria
foreach ($sxtask->from->text as $x) {
- $ijoin ++;
+ $ijoin++;
$comp = strtoupper($x['compare']);
if (in_array($comp, array('<', '>', '<=', '>=', '=', '!='))) {
$s = 'p' . $ijoin . '.name=\'' . $x['field'] . '\' AND p' . $ijoin . '.value' . $comp;
@@ -777,7 +685,7 @@ class task_period_RecordMover extends task_appboxAbstract
// criteria
foreach ($sxtask->from->date as $x) {
- $ijoin ++;
+ $ijoin++;
$s = 'p' . $ijoin . '.name=\'' . $x['field'] . '\' AND NOW()';
$s .= strtoupper($x['direction']) == 'BEFORE' ? '<' : '>=';
$delta = (int) ($x['delta']);
diff --git a/lib/classes/task/period/archive.php b/lib/classes/task/period/archive.php
index 509734280b..be08251444 100644
--- a/lib/classes/task/period/archive.php
+++ b/lib/classes/task/period/archive.php
@@ -24,6 +24,9 @@ use Symfony\Component\Filesystem\Exception\IOException;
*/
class task_period_archive extends task_abstract
{
+ const MINCOLD = 5;
+ const MAXCOLD = 300;
+
/**
* command line args specifics
*
@@ -80,13 +83,13 @@ class task_period_archive extends task_abstract
$request = http_request::getInstance();
$parm2 = $request->get_parms(
- "base_id"
- , "hotfolder"
- , "period"
- , "move_archived"
- , "move_error"
- , "copy_spe"
- , "delfolder"
+ 'base_id'
+ , 'hotfolder'
+ , 'period'
+ , 'move_archived'
+ , 'move_error'
+ , 'copy_spe'
+ , 'delfolder'
, 'cold'
);
$dom = new DOMDocument();
@@ -94,8 +97,16 @@ class task_period_archive extends task_abstract
$dom->preserveWhiteSpace = false;
if ($dom->loadXML($oldxml)) {
$xmlchanged = false;
- // foreach($parm2 as $pname=>$pvalue)
- foreach (array("str:base_id", "str:hotfolder", "str:period", "boo:move_archived", "boo:move_error", "boo:delfolder", 'boo:copy_spe', 'str:cold') as $pname) {
+ foreach (array(
+ 'str:base_id'
+ , 'str:hotfolder'
+ , 'str:period'
+ , 'boo:move_archived'
+ , 'boo:move_error'
+ , 'boo:delfolder'
+ , 'boo:copy_spe'
+ , 'str:cold'
+ ) as $pname) {
$ptype = substr($pname, 0, 3);
$pname = substr($pname, 4);
$pvalue = $parm2[$pname];
@@ -111,6 +122,7 @@ class task_period_archive extends task_abstract
// on fixe sa valeur
switch ($ptype) {
case "str":
+ case "pop":
$ns->appendChild($dom->createTextNode($pvalue));
break;
case "boo":
@@ -136,55 +148,54 @@ class task_period_archive extends task_abstract
{
if(xml)
{
- xml = $.parseXML(xml);
- xml = $(xml);
-
- var isyes = function(v) {
- v = v.toUpperCase().trim();
- return v=='O' || v=='Y' || v=='OUI' || v=='YES' || v=='1';
- }
+ xml2 = $.parseXML(xml);
+ xml2 = $(xml2);
with(document.forms['graphicForm'])
{
var i;
- var opts = base_id.options;
- var basefound = 0;
- for (i=1; basefound==0 && i 0;
+ move_error.checked = Number(xml2.find("move_error").text()) > 0;
+ delfolder.checked = Number(xml2.find("delfolder").text()) > 0;
+ copy_spe.checked = Number(xml2.find("copy_spe").text()) > 0;
}
}
}
+
+
$(document).ready(function(){
- $("#graphicForm *").change(function(){
- var limits = {
- 'period': {min:10, max:3600, allowempty:false} ,
- 'cold': {min:5, max:300, allowempty:false}
- } ;
- var name = $(this).attr("name");
- if(name && limits[name])
+ var limits = {
+ 'period':{'min':, 'max':},
+ 'cold':{'min':, 'max':}
+ } ;
+ $(".formElem").change(function(){
+ fieldname = $(this).attr("name");
+ switch((this.nodeName+$(this).attr("type")).toLowerCase())
{
- var v = $(this).val();
- if(v != "" || !limits[name].allowempty)
- {
- v = 0|v;
- if(v < limits[name].min)
- $(this).val(limits[name].min);
- else if(v > limits[name].max)
- $(this).val(limits[name].max);
- }
+ case "inputtext":
+ if (typeof(limits[fieldname])!='undefined') {
+ var v = 0|this.value;
+ if(v < limits[fieldname].min)
+ v = limits[fieldname].min;
+ else if(v > limits[fieldname].max)
+ v = limits[fieldname].max;
+ this.value = v;
+ }
+ break;
}
+ setDirty();
});
});
@@ -200,45 +211,38 @@ class task_period_archive extends task_abstract
{
ob_start();
?>
-
sxTaskSettings->base_id);
$this->sbas_id = \phrasea::sbasFromBas($this->dependencyContainer, $base_id);
- if ( ! $this->sbas_id) {
+ if (!$this->sbas_id) {
$this->log('base_id unknown');
return 'tostop';
@@ -288,20 +292,20 @@ class task_period_archive extends task_abstract
// mask(s) of accepted files
$this->tmask = array();
$this->tmaskgrp = array();
- $this->period = 60;
+// $this->period = 60;
$this->cold = 30;
if (false !== $this->sxBasePrefs = @simplexml_load_string($collection->get_prefs())) {
$this->sxBasePrefs["id"] = $base_id;
- $this->period = (int) ($this->sxTaskSettings->period);
- if ($this->period <= 0 || $this->period >= 3600) {
- $this->period = 60;
- }
+// $this->period = (int) ($this->sxTaskSettings->period);
+// if ($this->period <= 0 || $this->period >= 3600) {
+// $this->period = 60;
+// }
$this->cold = (int) ($this->sxTaskSettings->cold);
- if ($this->cold <= 0 || $this->cold >= 300) {
- $this->cold = 30;
+ if ($this->cold < self::MINCOLD || $this->cold > self::MAXCOLD) {
+ $this->cold = self::MINCOLD;
}
// check the data-repository exists
@@ -369,7 +373,7 @@ class task_period_archive extends task_abstract
}
$path_in = (string) ($this->sxTaskSettings->hotfolder);
- if ( ! @is_dir($path_in)) {
+ if (!@is_dir($path_in)) {
if ($this->getRunner() == self::RUNNER_SCHEDULER) {
$this->log(sprintf(('Warning : missing hotfolder \'%s\', restarting in 10 min.'), $path_in));
@@ -456,7 +460,7 @@ class task_period_archive extends task_abstract
case 'NORECSTODO':
$duration = time() - $duration;
if ($duration < ($period + $cold)) {
- for ($i = 0; $i < (($period + $cold) - $duration) && $this->running; $i ++ ) {
+ for ($i = 0; $i < (($period + $cold) - $duration) && $this->running; $i++) {
$s = $this->getState();
if ($s == self::STATE_TOSTOP) {
$this->setState(self::STATE_STOPPED);
@@ -482,7 +486,7 @@ class task_period_archive extends task_abstract
}
break;
}
- $loop ++;
+ $loop++;
}
}
}
@@ -724,7 +728,7 @@ class task_period_archive extends task_abstract
$time0 = time();
}
- if (($iloop ++ % 100) == 0) {
+ if (($iloop++ % 100) == 0) {
usleep(1000);
}
@@ -753,7 +757,7 @@ class task_period_archive extends task_abstract
foreach (array("size", "ctime", "mtime") as $k) {
$n->setAttribute($k, $stat[$k]);
}
- $nnew ++;
+ $nnew++;
}
$n->setAttribute('cid', $server_coll_id);
@@ -822,7 +826,7 @@ class task_period_archive extends task_abstract
continue;
}
- if (($iloop ++ % 100) == 0) {
+ if (($iloop++ % 100) == 0) {
usleep(500);
}
@@ -845,7 +849,7 @@ class task_period_archive extends task_abstract
} else {
$n = $node->appendChild($dom->createElement('file'));
$n->setAttribute('name', $file);
- $nnew ++;
+ $nnew++;
}
$this->setBranchHot($dom, $n);
} elseif ($dnl && $dnl->length == 1) {
@@ -901,7 +905,7 @@ class task_period_archive extends task_abstract
$xpath = new DOMXPath($dom);
for ($n = $node->firstChild; $this->running && $n; $n = $n->nextSibling) {
- if (($iloop ++ % 100) == 0) {
+ if (($iloop++ % 100) == 0) {
usleep(1000);
}
@@ -949,7 +953,7 @@ class task_period_archive extends task_abstract
}
}
- if ( ! $err) {
+ if (!$err) {
// the group is ok, flag it ...
$n->setAttribute('grp', 'tocreate');
@@ -995,7 +999,7 @@ class task_period_archive extends task_abstract
}
} else {
// this is a file
- if ( ! $n->getAttribute('match')) {
+ if (!$n->getAttribute('match')) {
// because match can be set before
if ($name == '.phrasea.xml') {
// special file(s) always ok
@@ -1009,7 +1013,7 @@ class task_period_archive extends task_abstract
// scan again for unmatched files
for ($n = $node->firstChild; $this->running && $n; $n = $n->nextSibling) {
- if ( ! $n->getAttribute('isdir') == '1' && ! $n->getAttribute('match')) {
+ 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) {
$nn->setAttribute('error', '1');
@@ -1048,7 +1052,7 @@ class task_period_archive extends task_abstract
$nodesToDel = array();
for ($n = $node->firstChild; $this->running && $n; $n = $n->nextSibling) {
- if (($iloop ++ % 20) == 0) {
+ if (($iloop++ % 20) == 0) {
usleep(1000);
}
@@ -1101,7 +1105,7 @@ class task_period_archive extends task_abstract
$this->log($e->getMessage());
}
- $this->movedFiles ++;
+ $this->movedFiles++;
}
}
}
@@ -1140,7 +1144,7 @@ class task_period_archive extends task_abstract
$nodesToDel = array();
for ($n = $node->firstChild; $this->running && $n; $n = $n->nextSibling) {
- if (($iloop ++ % 20) == 0) {
+ if (($iloop++ % 20) == 0) {
usleep(1000);
}
@@ -1217,7 +1221,7 @@ class task_period_archive extends task_abstract
$ret = 0;
for ($n = $node->firstChild; $n; $n = $n->nextSibling) {
- if (($iloop ++ % 20) == 0) {
+ if (($iloop++ % 20) == 0) {
usleep(1000);
}
@@ -1283,7 +1287,7 @@ 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);
}
@@ -1299,7 +1303,7 @@ class task_period_archive extends task_abstract
, $path_error . '/' . $name
, $depth + 1);
- if ( ! $n->firstChild) {
+ if (!$n->firstChild) {
$nodesToDel[] = $n;
}
/**
@@ -1324,7 +1328,7 @@ class task_period_archive extends task_abstract
$this->log($e->getMessage());
}
- if ( ! $n->getAttribute('keep')) { // do not count copy of special files as a real event
+ if (!$n->getAttribute('keep')) { // do not count copy of special files as a real event
$nodesToDel[] = $n;
$ret = true;
}
@@ -1345,13 +1349,13 @@ class task_period_archive extends task_abstract
$this->log($e->getMessage());
}
- if ( ! $n->getAttribute('keep')) { // do not count copy of special files as a real event
+ if (!$n->getAttribute('keep')) { // do not count copy of special files as a real event
$nodesToDel[] = $n;
$ret = true;
}
}
- if ( ! $n->getAttribute('keep')) {
+ if (!$n->getAttribute('keep')) {
$this->log(sprintf(('delete \'%s\''), $subpath . '/' . $name));
try {
@@ -1427,7 +1431,7 @@ class task_period_archive extends task_abstract
$this->log(sprintf(('created story \'%s\''), $subpath . '/' . $grpFolder));
// if the .grp does not have a representative doc, let's use a generic file
- if ( ! ($rep = $node->getAttribute('grp_representation'))) {
+ if (!($rep = $node->getAttribute('grp_representation'))) {
try {
$this->dependencyContainer['filesystem']->copy(p4string::addEndSlash($this->dependencyContainer['phraseanet.registry']->get('GV_RootPath')) . 'www/skins/icons/substitution/regroup_doc.png', $genericdoc = ($path . '/group.jpg'), true);
@@ -1466,7 +1470,7 @@ class task_period_archive extends task_abstract
$rid = $story->get_record_id();
$this->log(sprintf('story %s created', $rid));
- $this->archivedFiles ++;
+ $this->archivedFiles++;
if ($genericdoc) {
try {
@@ -1526,7 +1530,7 @@ class task_period_archive extends task_abstract
$nodesToDel[] = $captionFileNode;
- $this->movedFiles ++;
+ $this->movedFiles++;
}
if ($representationFileNode) {
$representationFileNode->setAttribute('archived', '1');
@@ -1554,7 +1558,7 @@ class task_period_archive extends task_abstract
}
$nodesToDel[] = $representationFileNode;
- $this->movedFiles ++;
+ $this->movedFiles++;
}
$node->setAttribute('grp', 'tocomplete');
} catch (Exception $e) {
@@ -1602,10 +1606,10 @@ class task_period_archive extends task_abstract
}
}
- if ( ! $stat0) {
+ if (!$stat0) {
$stat0 = '0';
}
- if ( ! $stat1) {
+ if (!$stat1) {
$stat1 = '0';
}
@@ -1664,10 +1668,10 @@ class task_period_archive extends task_abstract
}
}
- if ( ! $stat0) {
+ if (!$stat0) {
$stat0 = '0';
}
- if ( ! $stat1) {
+ if (!$stat1) {
$stat1 = '0';
}
@@ -1781,7 +1785,7 @@ class task_period_archive extends task_abstract
$subpath = substr($path, strlen($rootpath));
- if ( ! $match) {
+ if (!$match) {
// the file does not match on any mask
$this->log(sprintf(("File '%s' does not match any mask"), $subpath . '/' . $file));
$node->setAttribute('error', '1');
@@ -1848,10 +1852,10 @@ class task_period_archive extends task_abstract
if ($this->sxTaskSettings->status) {
$stat1 = (string) ($this->sxTaskSettings->status);
}
- if ( ! $stat0) {
+ if (!$stat0) {
$stat0 = '0';
}
- if ( ! $stat1) {
+ if (!$stat1) {
$stat1 = '0';
}
@@ -1871,7 +1875,7 @@ class task_period_archive extends task_abstract
$captionFileNode->setAttribute('archived', '1');
}
- $this->archivedFiles ++;
+ $this->archivedFiles++;
} catch (\Exception $e) {
$this->log(("Error : can't insert record : " . $e->getMessage()));
@@ -1907,7 +1911,7 @@ class task_period_archive extends task_abstract
$this->log($e->getMessage());
}
}
- if ( ! $node->getAttribute('keep')) // do not count copy of special files as a real event
+ if (!$node->getAttribute('keep')) // do not count copy of special files as a real event
$ret = true;
}
@@ -1936,12 +1940,12 @@ class task_period_archive extends task_abstract
}
}
// do not count copy of special files as a real event
- if ( ! $node->getAttribute('keep')) {
+ if (!$node->getAttribute('keep')) {
$ret = true;
}
}
- if ( ! $node->getAttribute('keep')) {
+ if (!$node->getAttribute('keep')) {
$file = $node->getAttribute('name');
try {
@@ -1952,10 +1956,10 @@ class task_period_archive extends task_abstract
$nodesToDel[] = $node;
- $this->movedFiles ++;
+ $this->movedFiles++;
}
- if ($captionFileNode && ! $captionFileNode->getAttribute('keep')) {
+ if ($captionFileNode && !$captionFileNode->getAttribute('keep')) {
$file = $captionFileNode->getAttribute('name');
try {
@@ -1967,7 +1971,7 @@ class task_period_archive extends task_abstract
$nodesToDel[] = $captionFileNode;
- $this->movedFiles ++;
+ $this->movedFiles++;
}
return;
@@ -1993,7 +1997,7 @@ class task_period_archive extends task_abstract
$node->setAttribute($a, $v);
}
- if (($iloop ++ % 100) == 0) {
+ if (($iloop++ % 100) == 0) {
usleep(1000);
}
@@ -2067,6 +2071,121 @@ class task_period_archive extends task_abstract
return $ret;
}
+ /**
+ * Map a bag of metadatas indexed by **FieldNames** to an array ready for
+ * \record_adapter metadatas submission
+ *
+ * @param \databox_descriptionStructure $metadatasStructure The databox structure related
+ * @param MetadataBag $metadatas The metadata bag
+ * @return array
+ */
+ protected function bagToArray(\databox_descriptionStructure $metadatasStructure, MetadataBag $metadatas)
+ {
+ $metas = array();
+ $unicode = new \unicode();
+
+ foreach ($metadatasStructure as $databox_field) {
+ if ($metadatas->containsKey($databox_field->get_tag()->getTagname())) {
+
+ if ($databox_field->is_multi()) {
+
+ $values = $metadatas->get($databox_field->get_tag()->getTagname())->getValue()->asArray();
+
+ $tmp = array();
+
+ foreach ($values as $value) {
+ foreach (\caption_field::get_multi_values($value, $databox_field->get_separator()) as $v) {
+ $tmp[] = $v;
+ }
+ }
+
+ $values = array_unique($tmp);
+
+ foreach ($values as $value) {
+
+ $value = $unicode->substituteCtrlCharacters($value, ' ');
+ $value = $unicode->toUTF8($value);
+ if ($databox_field->get_type() == 'date') {
+ $value = $unicode->parseDate($value);
+ }
+
+ $metas[] = array(
+ 'meta_struct_id' => $databox_field->get_id(),
+ 'value' => $value,
+ 'meta_id' => null
+ );
+ }
+ } else {
+ $value = $metadatas->get($databox_field->get_tag()->getTagname())->getValue()->asString();
+
+ $value = $unicode->substituteCtrlCharacters($value, ' ');
+ $value = $unicode->toUTF8($value);
+ if ($databox_field->get_type() == 'date') {
+ $value = $unicode->parseDate($value);
+ }
+
+ $metas[] = array(
+ 'meta_struct_id' => $databox_field->get_id(),
+ 'value' => $metadatas->get($databox_field->get_tag()->getTagname())->getValue()->asString(),
+ 'meta_id' => null
+ );
+ }
+ }
+ }
+
+ unset($unicode);
+
+ return $metas;
+ }
+
+ /**
+ * Merge two bags of metadatas indexed by **FieldNames**
+ * Return a bag indexed by **FieldNames**
+ *
+ * @param \databox_descriptionStructure $metadatasStructure The databox structure related
+ * @param MetadataBag $bag1 The first metadata bag
+ * @param MetadataBag $bag2 The second metadata bag
+ * @return \PHPExiftool\Driver\Metadata\MetadataBag
+ */
+ protected function mergeForDatabox(\databox_descriptionStructure $metadatasStructure, MetadataBag $bag1, MetadataBag $bag2)
+ {
+ $metadatasBag = new MetadataBag();
+
+ foreach ($metadatasStructure as $databox_field) {
+
+ $value = array();
+
+ $tag = $databox_field->get_tag();
+
+ foreach (array($bag1, $bag2) as $bag) {
+
+ if (!$bag->containsKey($databox_field->get_name())) {
+ continue;
+ }
+
+ if ($databox_field->is_multi()) {
+ $value = array_unique(array_merge($value, $bag->get($databox_field->get_name())->getValue()->asArray()));
+ } else {
+ $value = $bag->get($databox_field->get_name())->getValue()->asString();
+ }
+ }
+
+ if (!$value) {
+ continue;
+ }
+
+ if ($databox_field->is_multi()) {
+ $value = new \PHPExiftool\Driver\Value\Multi($value);
+ } else {
+ $value = new \PHPExiftool\Driver\Value\Mono($value);
+ }
+
+ $metadatasBag->set($databox_field->get_name(), new PHPExiftool\Driver\Metadata\Metadata($tag, $value));
+ }
+
+ return $metadatasBag;
+ }
+
protected function readXMLForDatabox(\databox_descriptionStructure $metadatasStructure, $pathfile)
{
if (false === $this->dependencyContainer['filesystem']->exists($pathfile)) {
@@ -2083,15 +2202,15 @@ class task_period_archive extends task_abstract
$field = trim($field);
$meta = $metadatasStructure->get_element_by_name(trim($tagname));
- if ( ! $meta) {
+ if (!$meta) {
continue;
}
if ($meta->is_multi()) {
$fields = caption_field::get_multi_values($field, $meta->get_separator());
- if ( ! $metadataBag->containsKey($meta->get_name())) {
- $values = $fields;
+ if (!$metadataBag->containsKey($meta->get_name())) {
+ $values = new \PHPExiftool\Driver\Value\Multi($fields);
} else {
$values = array_merge($metadataBag->get($meta->get_name())->getValue(), $fields);
}
diff --git a/lib/classes/task/period/cindexer.php b/lib/classes/task/period/cindexer.php
index 763aa6caef..82e4b24301 100644
--- a/lib/classes/task/period/cindexer.php
+++ b/lib/classes/task/period/cindexer.php
@@ -160,39 +160,6 @@ class task_period_cindexer extends task_abstract
return($dom->saveXML());
}
- /**
- *
- * @param string $xml
- * @param string $form
- * @return string
- */
- public function xml2graphic($xml, $form)
- {
- if (false !== $sxml = simplexml_load_string($xml)) {
- ?>
-
- get_parms(
- "proxy"
- , "proxyport"
- , "period"
+ 'proxy'
+ , 'proxyport'
+ , 'period'
+ , 'syslog'
);
$dom = new DOMDocument();
+ $dom->preserveWhiteSpace = false;
+ $dom->formatOutput = true;
if ((@$dom->loadXML($oldxml)) != FALSE) {
$xmlchanged = false;
- foreach (array("str:proxy", "str:proxyport", "str:period") as $pname) {
+ foreach (array(
+ 'str:proxy'
+ , 'str:proxyport'
+ , 'str:period'
+ , 'pop:syslog'
+ ) as $pname) {
$ptype = substr($pname, 0, 3);
$pname = substr($pname, 4);
$pvalue = $parm2[$pname];
@@ -64,13 +72,12 @@ class task_period_ftp extends task_appboxAbstract
}
} else {
// le champ n'existait pas dans le xml, on le cree
- $dom->documentElement->appendChild($dom->createTextNode("\t"));
$ns = $dom->documentElement->appendChild($dom->createElement($pname));
- $dom->documentElement->appendChild($dom->createTextNode("\n"));
}
// on fixe sa valeur
switch ($ptype) {
case "str":
+ case "pop":
$ns->appendChild($dom->createTextNode($pvalue));
break;
case "boo":
@@ -84,6 +91,7 @@ class task_period_ftp extends task_appboxAbstract
return($dom->saveXML());
}
+
/**
*
* @return void
@@ -109,28 +117,29 @@ class task_period_ftp extends task_appboxAbstract
}
$(document).ready(function(){
- $("#graphicForm *").change(function(){
- var limits = {
- 'period': {min:10, max:3600, allowempty:false}
- } ;
- var name = $(this).attr("name");
- if(name && limits[name])
+ var limits = {
+ 'period' :{'min':, 'max':}
+ } ;
+ $(".formElem").change(function(){
+ fieldname = $(this).attr("name");
+ switch((this.nodeName+$(this).attr("type")).toLowerCase())
{
- var v = $(this).val();
- if(v != "" || !limits[name].allowempty)
- {
- v = 0|v;
- if(v < limits[name].min)
- $(this).val(limits[name].min);
- else if(v > limits[name].max)
- $(this).val(limits[name].max);
- }
+ case "inputtext":
+ if (typeof(limits[fieldname])!='undefined') {
+ var v = 0|this.value;
+ if(v < limits[fieldname].min)
+ v = limits[fieldname].min;
+ else if(v > limits[fieldname].max)
+ v = limits[fieldname].max;
+ this.value = v;
+ }
+ break;
}
+ setDirty();
});
});
-
+
-
+
-
:
-
+
get_parms("xml", "name", "active", "proxy", "proxyport", "period", "debug");
+ $parm = $request->get_parms(
+ 'xml'
+ , 'name'
+ , 'active'
+ , 'proxy'
+ , 'proxyport'
+ , 'period'
+ , 'debug'
+ );
if ($parm["xml"] === null) {
// pas de xml 'raw' : on accepte les champs 'graphic view'
$domTaskSettings = new DOMDocument();
if ((@$domTaskSettings->loadXML($taskrow["settings"])) != FALSE) {
$xmlchanged = false;
- foreach (array("proxy", "proxyport", "period") as $f) {
+ foreach (array(
+ 'proxy'
+ , 'proxyport'
+ , 'period'
+ ) as $f) {
if ($parm[$f] !== NULL) {
if (($ns = $domTaskSettings->getElementsByTagName($f)->item(0)) != NULL) {
// le champ existait dans le xml, on supprime son ancienne valeur (tout le contenu)
@@ -180,9 +199,7 @@ class task_period_ftp extends task_appboxAbstract
}
} else {
// le champ n'existait pas dans le xml, on le cree
- $domTaskSettings->documentElement->appendChild($domTaskSettings->createTextNode("\t"));
$ns = $domTaskSettings->documentElement->appendChild($domTaskSettings->createElement($f));
- $domTaskSettings->documentElement->appendChild($domTaskSettings->createTextNode("\n"));
}
// on fixe sa valeur
$ns->appendChild($domTaskSettings->createTextNode($parm[$f]));
@@ -337,6 +354,17 @@ class task_period_ftp extends task_appboxAbstract
$this->logger->addDebug($line);
+ if (($ses_id = phrasea_create_session($usr_id)) == null) {
+ $this->logger->addDebug("Unable to create session");
+ return;
+ }
+
+ if (!($ph_session = phrasea_open_session($ses_id, $usr_id))) {
+ $this->logger->addDebug("Unable to open session");
+ phrasea_close_session($ses_id);
+ return;
+ }
+
try {
$ssl = ($ftp_export['ssl'] == '1');
$ftp_client = $this->dependencyContainer['phraseanet.ftp.client']($ftp_server, 21, 300, $ssl, $this->proxy, $this->proxyport);
@@ -379,7 +407,7 @@ 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"]);
}
@@ -419,12 +447,12 @@ class task_period_ftp extends task_appboxAbstract
} else {
$sd = $record->get_subdefs();
- if ( ! $sd || ! isset($sd[$subdef])) {
+ if (!$sd || !isset($sd[$subdef])) {
continue;
}
$localfile = $sd[$subdef]->get_pathfile();
- if ( ! file_exists($localfile)) {
+ if (!file_exists($localfile)) {
throw new Exception('Le fichier local n\'existe pas');
}
}
diff --git a/lib/classes/task/period/ftpPull.php b/lib/classes/task/period/ftpPull.php
index ab6e6fecad..a9f0d6be64 100644
--- a/lib/classes/task/period/ftpPull.php
+++ b/lib/classes/task/period/ftpPull.php
@@ -41,14 +41,36 @@ class task_period_ftpPull extends task_appboxAbstract
$request = http_request::getInstance();
$parm2 = $request->get_parms(
- "proxy", "proxyport", "host", "port", "user"
- , "password", "ssl", "ftppath", "localpath"
- , "passive", "period"
+ 'proxy'
+ , 'proxyport'
+ , 'host'
+ , 'port'
+ , 'user'
+ , 'password'
+ , 'ssl'
+ , 'ftppath'
+ , 'localpath'
+ , 'passive'
+ , 'period'
);
$dom = new DOMDocument();
+ $dom->preserveWhiteSpace = false;
+ $dom->formatOutput = true;
if (@$dom->loadXML($oldxml)) {
$xmlchanged = false;
- foreach (array("str:proxy", "str:proxyport", "str:period", "boo:passive", "boo:ssl", "str:password", "str:user", "str:ftppath", "str:localpath", "str:port", "str:host") as $pname) {
+ foreach (array(
+ 'str:proxy'
+ , 'str:proxyport'
+ , 'str:period'
+ , 'boo:passive'
+ , 'boo:ssl'
+ , 'str:password'
+ , 'str:user'
+ , 'str:ftppath'
+ , 'str:localpath'
+ , 'str:port'
+ , 'str:host'
+ ) as $pname) {
$ptype = substr($pname, 0, 3);
$pname = substr($pname, 4);
$pvalue = $parm2[$pname];
@@ -59,13 +81,12 @@ class task_period_ftpPull extends task_appboxAbstract
}
} else {
// le champ n'existait pas dans le xml, on le cree
- $dom->documentElement->appendChild($dom->createTextNode("\t"));
$ns = $dom->documentElement->appendChild($dom->createElement($pname));
- $dom->documentElement->appendChild($dom->createTextNode("\n"));
}
// on fixe sa valeur
switch ($ptype) {
case "str":
+ case "pop":
$ns->appendChild($dom->createTextNode($pvalue));
break;
case "boo":
@@ -79,51 +100,60 @@ class task_period_ftpPull extends task_appboxAbstract
return($dom->saveXML());
}
- public function xml2graphic($xml, $form)
- {
- if (false !== $sxml = simplexml_load_string($xml)) {
- ?>
-
-
-
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
get_parms(
- "xml", "name", "active", "proxy", "proxyport", "period"
- , "localpath", "ftppath", "port", "host", "user"
- , "password", "passive", "ssl", "debug"
+ 'xml'
+ , 'name'
+ , 'active'
+ , 'proxy'
+ , 'proxyport'
+ , 'period'
+ , 'localpath'
+ , 'ftppath'
+ , 'port'
+ , 'host'
+ , 'user'
+ , 'password'
+ , 'passive'
+ , 'ssl'
+ , 'debug'
);
if ($parm["xml"] === null) {
@@ -192,7 +233,19 @@ class task_period_ftpPull extends task_appboxAbstract
$domdoc = new DOMDocument();
if (($domTaskSettings = $domdoc->loadXML($taskrow["settings"])) != FALSE) {
$xmlchanged = false;
- foreach (array("proxy", "proxyport", "period", "host", "port", "user", "password", "ssl", "passive", "localpath", "ftppath") as $f) {
+ foreach (array(
+ 'proxy'
+ , 'proxyport'
+ , 'period'
+ , 'localpath'
+ , 'ftppath'
+ , 'host'
+ , 'port'
+ , 'user'
+ , 'password'
+ , 'passive'
+ , 'ssl'
+ ) as $f) {
if ($parm[$f] !== NULL) {
if (($ns = $domTaskSettings->getElementsByTagName($f)->item(0)) != NULL) {
// le champ existait dans le xml, on supprime son ancienne valeur (tout le contenu)
@@ -201,9 +254,7 @@ class task_period_ftpPull extends task_appboxAbstract
}
} else {
// le champ n'existait pas dans le xml, on le cree
- $domTaskSettings->documentElement->appendChild($domTaskSettings->createTextNode("\t"));
$ns = $domTaskSettings->documentElement->appendChild($domTaskSettings->createElement($f));
- $domTaskSettings->documentElement->appendChild($domTaskSettings->createTextNode("\n"));
}
// on fixe sa valeur
$ns->appendChild($domTaskSettings->createTextNode($parm[$f]));
@@ -219,7 +270,6 @@ class task_period_ftpPull extends task_appboxAbstract
// si on doit changer le xml, on verifie qu'il est valide
$domdoc = new DOMDocument();
if ($parm["xml"] && ! $domdoc->loadXML($parm["xml"])) {
-
return(false);
}
@@ -264,8 +314,8 @@ class task_period_ftpPull extends task_appboxAbstract
$this->port = (string) ($sx_task_settings->port);
$this->user = (string) ($sx_task_settings->user);
$this->password = (string) ($sx_task_settings->password);
- $this->ssl = ! ! ((string) ($sx_task_settings->ssl));
- $this->passive = ! ! ((string) ($sx_task_settings->passive));
+ $this->ssl = !!((string) ($sx_task_settings->ssl));
+ $this->passive = !!((string) ($sx_task_settings->passive));
$this->ftppath = (string) ($sx_task_settings->ftppath);
$this->localpath = (string) ($sx_task_settings->localpath);
@@ -276,23 +326,23 @@ class task_period_ftpPull extends task_appboxAbstract
{
foreach (array('localpath', 'host', 'port', 'user', 'password', 'ftppath') as $f) {
if (trim((string) ($this->{$f})) === '') {
- $this->log('setting \'' . $f . '\' must be set');
+ $this->log(sprintf('setting \'%s\' must be set', $f), self::LOG_ERROR);
$this->running = FALSE;
}
}
$this->dependencyContainer['filesystem']->mkdir($this->localpath, 0750);
- if ( ! is_dir($this->localpath)) {
- $this->log('\'' . $this->localpath . '\' does not exists');
+ if (!is_dir($this->localpath)) {
+ $this->log(sprintf('\'%s\' does not exists', $this->localpath), self::LOG_ERROR);
$this->running = FALSE;
}
- if ( ! is_writeable($this->localpath)) {
- $this->log('\'' . $this->localpath . '\' is not writeable');
+ if (!is_writeable($this->localpath)) {
+ $this->log(sprintf('\'%s\' is not writeable', $this->localpath), self::LOG_ERROR);
$this->running = FALSE;
}
- if ( ! $this->running) {
+ if (!$this->running) {
$this->set_status(self::STATE_STOPPED);
return array();
@@ -311,7 +361,7 @@ class task_period_ftpPull extends task_appboxAbstract
$this->logger->addDebug("attente de 25sec pour avoir les fichiers froids...");
$this->sleep(25);
- if ( ! $this->running) {
+ if (!$this->running) {
if (isset($ftp) && $ftp instanceof ftpclient) {
$ftp->close();
}
@@ -322,10 +372,10 @@ class task_period_ftpPull extends task_appboxAbstract
$list_2 = $ftp->list_directory(true);
foreach ($list_1 as $filepath => $timestamp) {
- $done ++;
+ $done++;
$this->setProgress($done, $todo);
- if ( ! isset($list_2[$filepath])) {
+ if (!isset($list_2[$filepath])) {
$this->logger->addDebug("le fichier $filepath a disparu...\n");
continue;
}
@@ -358,7 +408,7 @@ class task_period_ftpPull extends task_appboxAbstract
if (isset($ftp) && $ftp instanceof ftpclient) {
$ftp->close();
}
- $this->log('Exception catch : ' . $e->getMessage());
+ $this->log($e->getMessage(), self::LOG_ERROR);
return array();
}
diff --git a/lib/classes/task/period/outofdate.php b/lib/classes/task/period/outofdate.php
deleted file mode 100644
index 43bfb6aaa5..0000000000
--- a/lib/classes/task/period/outofdate.php
+++ /dev/null
@@ -1,777 +0,0 @@
-get_parms(
- "sbas_id"
- , "period"
- , 'field1'
- , 'fieldDs1'
- , 'fieldDv1'
- , 'field2'
- , 'fieldDs2'
- , 'fieldDv2'
- , 'status0'
- , 'coll0'
- , 'status1'
- , 'coll1'
- , 'status2'
- , 'coll2'
- );
- $dom = new DOMDocument();
- $dom->preserveWhiteSpace = false;
- $dom->formatOutput = true;
- if ($dom->loadXML($oldxml)) {
- $xmlchanged = false;
- // foreach($parm2 as $pname=>$pvalue)
- foreach (array(
- "str:sbas_id",
- "str:period",
- 'str:field1',
- 'str:fieldDs1',
- 'str:fieldDv1',
- 'str:field2',
- 'str:fieldDs2',
- 'str:fieldDv2',
- 'str:status0',
- 'str:coll0',
- 'str:status1',
- 'str:coll1',
- 'str:status2',
- 'str:coll2'
- ) as $pname) {
- $ptype = substr($pname, 0, 3);
- $pname = substr($pname, 4);
- $pvalue = $parm2[$pname];
- 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)) {
- $ns->removeChild($n);
- }
- } else {
- // le champ n'existait pas dans le xml, on le cree
- $dom->documentElement->appendChild($dom->createTextNode("\t"));
- $ns = $dom->documentElement->appendChild($dom->createElement($pname));
- $dom->documentElement->appendChild($dom->createTextNode("\n"));
- }
- // on fixe sa valeur
- switch ($ptype) {
- case "str":
- $ns->appendChild($dom->createTextNode($pvalue));
- break;
- case "boo":
- $ns->appendChild($dom->createTextNode($pvalue ? '1' : '0'));
- break;
- }
- $xmlchanged = true;
- }
- }
-
- return($dom->saveXML());
- }
-
- // ====================================================================
- // xml2graphic : must fill the graphic form (using js) from xml
- // ====================================================================
- public function xml2graphic($xml, $form)
- {
- if (false !== $sxml = simplexml_load_string($xml)) {
- if ((int) ($sxml->period) < 10) {
- $sxml->period = 10;
- } elseif ((int) ($sxml->period) > 1440) { // 1 jour
- $sxml->period = 1440;
- }
-
- if ((string) ($sxml->delay) == '') {
- $sxml->delay = 0;
- }
- ?>
-
-
-
-
-
- dependencyContainer['phraseanet.user']->ACL()->get_granted_sbas(array('bas_manage'));
- ?>
-
-
-
- cmd
-
- array("set"=>false, "values"=>array(), "usage"=>" : usage du truc")
- );
-
- // ======================================================================================================
- // ===== help() : text displayed if --help (optional)
- // ======================================================================================================
- public function help()
- {
- return(_("task::outofdate:deplacement de docs suivant valeurs de champs 'date'"));
- }
- // ======================================================================================================
- // ===== run() : le code d'execution de la tache proprement dite
- // ======================================================================================================
-
- 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()
- {
- $ret = '';
- $conn = connection::getPDOConnection($this->dependencyContainer);
-
- $this->sxTaskSettings = simplexml_load_string($this->settings);
-
- $this->sbas_id = (int) ($this->sxTaskSettings->sbas_id);
-
- $this->connbas = connection::getPDOConnection($this->dependencyContainer, $this->sbas_id);
-
- $this->running = true;
- $this->tmask = array();
- $this->tmaskgrp = array();
- $this->period = 60;
-
-
- // ici la tache tourne tant qu'elle est active
- $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 ++ ) {
- sleep(1);
- }
- $this->running = false;
-
- return(self::STATUS_TORESTART);
- }
-
- try {
- $connbas = connection::getPDOConnection($this->dependencyContainer, $this->sbas_id);
- 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 ++ ) {
- sleep(1);
- }
- $this->running = false;
-
- return(self::STATUS_TORESTART);
- }
-
- $this->setLastExecTime();
-
- $sql = "SELECT * FROM task2 WHERE task_id = :task_id";
- $stmt = $conn->prepare($sql);
- $stmt->execute(array(':task_id' => $this->getID()));
- $row = $stmt->fetch(PDO::FETCH_ASSOC);
- $stmt->closeCursor();
-
- if ($row) {
- if ($row['status'] == 'tostop') {
- $ret = self::STATUS_STOPPED;
- $this->running = false;
- } else {
- if (false !== $this->sxTaskSettings = simplexml_load_string($row['settings'])) {
- $period = (int) ($this->sxTaskSettings->period);
- if ($period <= 0 || $period >= 24 * 60) {
- $period = 60;
- }
- } else {
- $period = 60;
- }
- $this->connbas = connection::getPDOConnection($this->dependencyContainer, $this->sbas_id);
-
- $duration = time();
-
- $r = $this->doRecords();
-
- switch ($r) {
- case 'WAIT':
- $this->setState(self::STATE_STOPPED);
- $this->running = false;
- break;
- case 'BAD':
- $this->setState(self::STATE_STOPPED);
- $this->running = false;
- break;
- case 'NORECSTODO':
- $duration = time() - $duration;
- if ($duration < $period) {
- sleep($period - $duration);
- $conn = connection::getPDOConnection($this->dependencyContainer);
- }
- break;
- case 'MAXRECSDONE':
- case 'MAXMEMORY':
- case 'MAXLOOP':
- 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::STATE_STARTED) {
- $this->setState(self::STATE_STOPPED);
- $this->running = false;
- }
- break;
- }
- }
- } else {
- $this->setState(self::STATE_STOPPED);
- $this->running = false;
- }
- $loop ++;
- }
- }
-
- public function doRecords()
- {
- $ndone = 0;
- $ret = 'NORECSTODO';
-
- $tsql = $this->calcSQL($this->sxTaskSettings);
-
- $nchanged = 0;
- foreach ($tsql as $xsql) {
- try {
- $stmt = $this->connbas->prepare($xsql['sql']);
- if ($stmt->execute($xsql['params'])) {
- $n = $stmt->rowCount();
- $stmt->closeCursor();
-
- $nchanged += $n;
- if ($n > 0) {
- $this->log(sprintf("SQL='%s' ; parms=%s - %s changes", $xsql['sql'], var_export($xsql['params']), $n));
- }
- } else {
- $this->log(sprintf("ERROR SQL='%s' ; parms=%s", $xsql['sql'], var_export($xsql['params'], true)));
- }
- } catch (ErrorException $e) {
- $this->log(sprintf("ERROR SQL='%s' ; parms=%s", $xsql['sql'], var_export($xsql['params'], true)));
- }
- }
-
- $ret = ($nchanged > 0 ? $nchanged : 'NORECSTODO');
-
- return($ret);
- }
-
- private function calcSQL($sxTaskSettings)
- {
- $ret = array();
-
- $this->sxTaskSettings = $sxTaskSettings;
-
- $date1 = $date2 = NULL;
- $field1 = $field2 = '';
-
- // test : DATE 1
- if (($field1 = trim($this->sxTaskSettings->field1)) != '') {
- $date1 = time();
- if (($delta = (int) ($this->sxTaskSettings->fieldDv1)) > 0) {
- if ($this->sxTaskSettings->fieldDs1 == '-') {
- $date1 += 86400 * $delta;
- } 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 == '-') {
- $date2 += 86400 * $delta;
- } 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] = '';
- $x = 'status' . $i;
- @list($tostat, $statval) = explode('_', (string) ($this->sxTaskSettings->{$x}));
- if ($tostat >= 4 && $tostat < 32) {
- if ($statval == '0') {
- $sqlset[$i] = 'status=status & ~(1<<' . $tostat . ')';
- $sqlwhere[$i] .= '(status & (1<<' . $tostat . ') = 0)';
- } elseif ($statval == '1') {
- $sqlset[$i] = 'status=status|(1<<' . $tostat . ')';
- $sqlwhere[$i] .= '(status & (1<<' . $tostat . ') != 0)';
- }
- }
- $x = 'coll' . $i;
- if (($tocoll = (string) ($this->sxTaskSettings->{$x})) != '') {
- $sqlset[$i] .= ( $sqlset[$i] ? ', ' : '') . ('coll_id = :coll_id_set' . $i);
- $sqlwhere[$i] .= ( $sqlwhere[$i] ? ' AND ' : '') . '(coll_id = :coll_id_where' . $i . ')';
- $tmp_params[':coll_id_set' . $i] = $tocoll;
- $tmp_params[':coll_id_where' . $i] = $tocoll;
- }
- }
-
- if ($date1 && $sqlset[0]) {
- $params = array();
- $params[':name1'] = $field1;
- $params[':date1'] = $date1;
- $params[':coll_id_set0'] = $tmp_params[':coll_id_set0'];
-
- $w = 'p1.name = :name1 AND :date1 <= p1.value';
- if ($sqlwhere[1] && $sqlwhere[2]) {
- $w .= ' AND ((' . $sqlwhere[1] . ') OR (' . $sqlwhere[2] . '))';
- $params[':coll_id_where1'] = $tmp_params[':coll_id_where1'];
- $params[':coll_id_where2'] = $tmp_params[':coll_id_where2'];
- } else {
- if ($sqlwhere[1]) {
- $w .= ' AND ' . $sqlwhere[1];
- $params[':coll_id_where1'] = $tmp_params[':coll_id_where1'];
- } elseif ($sqlwhere[2]) {
- $w .= ' AND ' . $sqlwhere[2];
- $params[':coll_id_where2'] = $tmp_params[':coll_id_where2'];
- }
- }
-
- $sql = "UPDATE prop AS p1 INNER JOIN record USING(record_id)"
- . " SET " . $sqlset[0]
- . " WHERE " . $w;
-
- $ret[] = array('sql' => $sql, 'params' => $params);
- }
-
- if ($date1 && $date2) {
- $params = array();
- $params[':name1'] = $field1;
- $params[':name2'] = $field2;
- $params[':date1'] = $date1;
- $params[':date2'] = $date2;
- $params[':coll_id_set1'] = $tmp_params[':coll_id_set1'];
-
- $w = 'p1.name = :name1 AND p2.name = :name2 AND :date1 > p1.value AND :date2 <= p2.value';
- if ($sqlwhere[0] && $sqlwhere[2]) {
- $w .= ' AND ((' . $sqlwhere[0] . ') OR (' . $sqlwhere[2] . '))';
- $params[':coll_id_where0'] = $tmp_params[':coll_id_where0'];
- $params[':coll_id_where2'] = $tmp_params[':coll_id_where2'];
- } else {
- if ($sqlwhere[0]) {
- $w .= ' AND ' . $sqlwhere[0];
- $params[':coll_id_where0'] = $tmp_params[':coll_id_where0'];
- } elseif ($sqlwhere[2]) {
- $w .= ' AND ' . $sqlwhere[2];
- $params[':coll_id_where2'] = $tmp_params[':coll_id_where2'];
- }
- }
-
- $sql = "UPDATE (prop AS p1 INNER JOIN prop AS p2 USING(record_id))"
- . " INNER JOIN record USING(record_id)"
- . " SET " . $sqlset[1]
- . " WHERE " . $w;
-
- $ret[] = array('sql' => $sql, 'params' => $params);
- }
-
- if ($date2 && $sqlset[2]) {
- $params = array();
- $params[':name2'] = $field2;
- $params[':date2'] = $date2;
- $params[':coll_id_set2'] = $tmp_params[':coll_id_set2'];
-
- $w = 'p2.name = :name2 AND :date2 > p2.value';
- if ($sqlwhere[0] && $sqlwhere[1]) {
- $w .= ' AND ((' . $sqlwhere[0] . ') OR (' . $sqlwhere[1] . '))';
- $params[':coll_id_where0'] = $tmp_params[':coll_id_where0'];
- $params[':coll_id_where1'] = $tmp_params[':coll_id_where1'];
- } else {
- if ($sqlwhere[0]) {
- $w .= ' AND ' . $sqlwhere[0];
- $params[':coll_id_where0'] = $tmp_params[':coll_id_where0'];
- } elseif ($sqlwhere[1]) {
- $w .= ' AND ' . $sqlwhere[1];
- $params[':coll_id_where1'] = $tmp_params[':coll_id_where1'];
- }
- }
-
- $sql = "UPDATE prop AS p2 INNER JOIN record USING(record_id)"
- . " SET " . $sqlset[2]
- . " WHERE " . $w;
-
- $ret[] = array('sql' => $sql, 'params' => $params);
- }
-
- return($ret);
- }
-
- public function facility()
- {
- $ret = NULL;
-
- $request = http_request::getInstance();
- $parm2 = $request->get_parms(
- 'ACT', 'bid'
- );
-
- phrasea::headers(200, true, 'application/json', 'UTF-8', false);
- $ret = NULL;
- switch ($parm2['ACT']) {
- case 'CALCSQL':
- $xml = $this->graphic2xml('');
- $sxml = simplexml_load_string($xml);
- $ret = $this->calcSQL($sxml);
- break;
- case 'GETBASE':
- $ret = array('date_fields' => array(), 'status_bits' => array(), 'collections' => array());
-
- if ($parm2['bid'] != '') {
- $sbas_id = (int) $parm2['bid'];
- try {
- $databox = $this->dependencyContainer['phraseanet.appbox']->get_databox($sbas_id);
- $meta_struct = $databox->get_meta_structure();
-
- foreach ($meta_struct as $meta) {
- if (mb_strtolower($meta->get_type()) == 'date') {
- $ret['date_fields'][] = $meta->get_name();
- }
- }
-
- $status = $databox->get_statusbits();
- foreach ($status as $n => $stat) {
- $labelon = $stat['labelon'] ? $stat['labelon'] : ($n . '-ON');
- $labeloff = $stat['labeloff'] ? $stat['labeloff'] : ($n . '-OFF');
- $ret['status_bits'][] = array('n' => $n, 'value' => 0, 'label' => $labeloff);
- $ret['status_bits'][] = array('n' => $n, 'value' => 1, 'label' => $labelon);
- }
-
- foreach ($databox->get_collections() as $collection) {
- $ret['collections'][] = array('id' => $collection->get_coll_id(), 'name' => $collection->get_name());
- }
- } catch (Exception $e) {
-
- }
- }
- break;
- }
- print(json_encode($ret));
- }
-}
diff --git a/lib/classes/task/period/subdef.php b/lib/classes/task/period/subdef.php
index d413570a2b..fda42be4fc 100644
--- a/lib/classes/task/period/subdef.php
+++ b/lib/classes/task/period/subdef.php
@@ -13,8 +13,17 @@
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
+
+use Monolog\Logger;
+
class task_period_subdef extends task_databoxAbstract
{
+ const MINMEGS = 20;
+ const MAXMEGS = 64;
+
+ const MINFLUSH = 10;
+ const MAXFLUSH = 100;
+
/**
* Record buffer for writing meta datas after building subdefs
*
@@ -51,6 +60,107 @@ class task_period_subdef extends task_databoxAbstract
return(_('task::subdef:creation des sous definitions'));
}
+ /**
+ * must return the xml (text) version of the form
+ *
+ * @param string $oldxml
+ * @return string
+ */
+ public function graphic2xml($oldxml)
+ {
+ $request = http_request::getInstance();
+
+ $parm2 = $request->get_parms(
+ 'period'
+ , 'flush'
+ , 'maxrecs'
+ , 'maxmegs'
+ );
+ $dom = new DOMDocument();
+ $dom->preserveWhiteSpace = false;
+ $dom->formatOutput = true;
+ if (@$dom->loadXML($oldxml)) {
+ $xmlchanged = false;
+
+ foreach (array(
+ 'str:period'
+ , 'str:flush'
+ , 'str:maxrecs'
+ , 'str:maxmegs'
+ ) as $pname) {
+ $ptype = substr($pname, 0, 3);
+ $pname = substr($pname, 4);
+ $pvalue = $parm2[$pname];
+ if (($ns = $dom->getElementsByTagName($pname)->item(0)) != NULL) {
+ while (($n = $ns->firstChild)) {
+ $ns->removeChild($n);
+ }
+ } else {
+ $ns = $dom->documentElement->appendChild($dom->createElement($pname));
+ }
+ switch ($ptype) {
+ case "str":
+ case "pop":
+ $ns->appendChild($dom->createTextNode($pvalue));
+ break;
+ case "boo":
+ $ns->appendChild($dom->createTextNode($pvalue ? '1' : '0'));
+ break;
+ }
+ $xmlchanged = true;
+ }
+ }
+
+ return($dom->saveXML());
+ }
+
+ /**
+ * must fill the graphic form (using js) from xml
+ *
+ * @param string $xml
+ * @param string $form
+ * @return string
+ */
+ public function xml2graphic($xml, $form)
+ {
+ if (false !== $sxml = simplexml_load_string($xml)) {
+ if ((int) ($sxml->period) < self::MINPERIOD) {
+ $sxml->period = self::MINPERIOD;
+ } elseif ((int) ($sxml->period) > self::MAXPERIOD) {
+ $sxml->period = self::MAXPERIOD;
+ }
+
+ if ((int) ($sxml->flush) < self::MINFLUSH) {
+ $sxml->flush = self::MINFLUSH;
+ } elseif ((int) ($sxml->flush) > self::MAXFLUSH) {
+ $sxml->flush = self::MAXFLUSH;
+ }
+
+ if ((int) ($sxml->maxrecs) < self::MINRECS) {
+ $sxml->maxrecs = self::MINRECS;
+ } elseif (self::MAXRECS != -1 && (int) ($sxml->maxrecs) > self::MAXRECS) {
+ $sxml->maxrecs = self::MAXRECS;
+ }
+
+ if ((int) ($sxml->maxmegs) < self::MINMEGS) {
+ $sxml->maxmegs = self::MINMEGS;
+ } elseif (self::MAXMEGS != -1 && (int) ($sxml->maxmegs) > self::MAXMEGS) {
+ $sxml->maxmegs = self::MAXMEGS;
+ }
+ ?>
+
+
+ , 'max':},
+ 'flush' :{'min':, 'max':},
+ 'maxrecs':{'min':, 'max':},
+ 'maxmegs':{'min':, 'max':}
+ } ;
+ $(".formElem").change(function(){
+ fieldname = $(this).attr("name");
+ switch((this.nodeName+$(this).attr("type")).toLowerCase())
{
- var v = $(this).val();
- if(v != "" || !limits[name].allowempty)
- {
- v = 0|v;
- if(v < limits[name].min)
- $(this).val(limits[name].min);
- else if(v > limits[name].max)
- $(this).val(limits[name].max);
- }
+ case "inputtext":
+ if (typeof(limits[fieldname])!='undefined') {
+ var v = 0|this.value;
+ if(v < limits[fieldname].min)
+ v = limits[fieldname].min;
+ else if(v > limits[fieldname].max)
+ v = limits[fieldname].max;
+ this.value = v;
+ }
+ break;
}
+ setDirty();
});
});
@@ -109,7 +221,6 @@ class task_period_subdef extends task_databoxAbstract
* return interface 'graphic view'
*
*/
-
public function getInterfaceHTML()
{
ob_start();
@@ -117,20 +228,21 @@ class task_period_subdef extends task_databoxAbstract
0
- ORDER BY record_id DESC LIMIT 0, 20';
-
+ ORDER BY record_id DESC LIMIT 0, '.$this->maxrecs;
$stmt = $connbas->prepare($sql);
$stmt->execute();
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
@@ -155,8 +266,10 @@ class task_period_subdef extends task_databoxAbstract
{
$record_id = $row['record_id'];
$this->log(sprintf(
- "Generate subdefs for : sbas_id %s / record %s "
- , $this->sbas_id, $record_id));
+ "Generate subdefs for : sbasid=%s / databox=%s / recordid=%s "
+ , $databox->get_sbas_id(), $databox->get_dbname() , $record_id)
+ , self::LOG_INFO
+ );
try {
$record = new record_adapter($this->dependencyContainer, $this->sbas_id, $record_id);
@@ -165,8 +278,9 @@ class task_period_subdef extends task_databoxAbstract
} catch (\Exception $e) {
$this->log(
sprintf(
- 'Generate failed for record %d on databox %s (%s)', $record_id, $record->get_databox()->get_viewname(), $e->getMessage()
- )
+ "Generate subdefs failed for : sbasid=%s / databox=%s / recordid=%s : %s"
+ , $databox->get_sbas_id(), $databox->get_dbname() , $record_id, $e->getMessage())
+ , self::LOG_WARNING
);
}
@@ -202,7 +316,7 @@ class task_period_subdef extends task_databoxAbstract
$this->log(sprintf(
'setting %d record(s) to subdef meta writing'
, count($this->recs_to_write)
- ));
+ ), self::LOG_INFO);
try {
$connbas = connection::getPDOConnection($this->dependencyContainer, $this->sbas_id);
@@ -214,7 +328,7 @@ class task_period_subdef extends task_databoxAbstract
$stmt->execute();
$stmt->closeCursor();
} catch (Exception $e) {
- $this->log($e->getMessage());
+ $this->log($e->getMessage(), self::LOG_CRITICAL);
}
}
$this->recs_to_write = array();
diff --git a/lib/classes/task/period/workflow01.php b/lib/classes/task/period/workflow01.php
deleted file mode 100644
index 0d98f56ff8..0000000000
--- a/lib/classes/task/period/workflow01.php
+++ /dev/null
@@ -1,472 +0,0 @@
-get_parms(
- "sbas_id"
- , "period"
- , 'status0'
- , 'coll0'
- , 'status1'
- , 'coll1'
- );
- $dom = new DOMDocument();
- $dom->preserveWhiteSpace = false;
- $dom->formatOutput = true;
- if ($dom->loadXML($oldxml)) {
- $xmlchanged = false;
- // foreach($parm2 as $pname=>$pvalue)
- foreach (array(
- "str:sbas_id",
- "str:period",
- 'str:status0',
- 'str:coll0',
- 'str:status1',
- 'str:coll1',
- ) as $pname) {
- $ptype = substr($pname, 0, 3);
- $pname = substr($pname, 4);
- $pvalue = $parm2[$pname];
- 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)) {
- $ns->removeChild($n);
- }
- } else {
- // le champ n'existait pas dans le xml, on le cree
- $dom->documentElement->appendChild($dom->createTextNode("\t"));
- $ns = $dom->documentElement->appendChild($dom->createElement($pname));
- $dom->documentElement->appendChild($dom->createTextNode("\n"));
- }
- // on fixe sa valeur
- switch ($ptype) {
- case "str":
- $ns->appendChild($dom->createTextNode($pvalue));
- break;
- case "boo":
- $ns->appendChild($dom->createTextNode($pvalue ? '1' : '0'));
- break;
- }
- $xmlchanged = true;
- }
- }
-
- return($dom->saveXML());
- }
-
- public function xml2graphic($xml, $form)
- {
- if (false !== $sxml = simplexml_load_string($xml)) {
- if ((int) ($sxml->period) < 1) {
- $sxml->period = 1;
- } elseif ((int) ($sxml->period) > 1440) { // 1 jour
- $sxml->period = 1440;
- }
-
- if ((string) ($sxml->delay) == '') {
- $sxml->delay = 0;
- }
- ?>
-
-
-
-
-
-
-
-
-
-
- cmd
-
- status_origine = (string) $sx_task_settings->status0;
- $this->status_destination = (string) $sx_task_settings->status1;
-
- $this->coll_origine = (int) $sx_task_settings->coll0;
- $this->coll_destination = (int) $sx_task_settings->coll1;
-
- parent::loadSettings($sx_task_settings);
-
- $this->mono_sbas_id = (int) $sx_task_settings->sbas_id;
- // in minutes
- $this->period = (int) $sx_task_settings->period * 60;
-
- if ($this->period <= 0 || $this->period >= 24 * 60) {
- $this->period = 60;
- }
- }
-
- protected function retrieveSbasContent(databox $databox)
- {
- static $firstCall = true;
-
- $connbas = $databox->get_connection();
-
- $sql_s = $sql_w = '';
- $sql_parms = array();
- if ($this->coll_origine != '') {
- $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 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_parms[':coll_dst'] = $this->coll_destination;
- }
- if ($this->status_destination != '') {
- $x = explode('_', $this->status_destination);
- 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)';
- } else {
- $sql_s .= 'status = status |(1 << :stat_dst)';
- }
- $sql_parms[':stat_dst'] = (int) $x[0];
- }
-
- if ($sql_w && $sql_s) {
- $sql = 'UPDATE record SET ' . $sql_s . ' WHERE ' . $sql_w;
- $stmt = $connbas->prepare($sql);
- $stmt->execute($sql_parms);
-
- if ($firstCall || $stmt->rowCount() != 0) {
- $this->log(sprintf(("SQL=%s\n (parms=%s)\n - %s changes"), str_replace(array("\r\n", "\n", "\r", "\t"), " ", $sql)
- , str_replace(array("\r\n", "\n", "\r", "\t"), " ", var_export($sql_parms, true))
- , $stmt->rowCount()));
- $firstCall = false;
- }
- $stmt->closeCursor();
- }
-
- return array();
- }
-
- protected function processOneContent(databox $databox, Array $row)
- {
- return $this;
- }
-
- protected function flushRecordsSbas()
- {
- return $this;
- }
-
- protected function postProcessOneContent(databox $databox, Array $row)
- {
- return $this;
- }
-
- public function facility()
- {
- $request = http_request::getInstance();
-
- $parm = $request->get_parms("bid");
-
- phrasea::headers(200, true, 'text/json', 'UTF-8', false);
-
- $retjs = array('result' => NULL,
- 'date_fields' => array(),
- 'status_bits' => array(),
- 'collections' => array()
- );
-
- $sbas_id = (int) $parm['bid'];
- try {
- $databox = $this->dependencyContainer['phraseanet.appbox']->get_databox($sbas_id);
- foreach ($databox->get_meta_structure() as $meta) {
- if ($meta->get_type() !== 'date') {
- continue;
- }
- $retjs['date_fields'][] = $meta->get_name();
- }
-
- $status = $databox->get_statusbits();
-
- foreach ($status as $n => $s) {
- $retjs['status_bits'][] = array(
- 'n' => $n,
- 'value' => 0,
- 'label' => $s['labeloff'] ? $s['labeloff'] : 'non ' . $s['name']);
- $retjs['status_bits'][] = array(
- 'n' => $n,
- 'value' => 1,
- 'label' => $s['labelon'] ? $s['labelon'] : $s['name']);
- }
-
- $base_ids = $this->dependencyContainer['phraseanet.user']->ACL()->get_granted_base(array(), array($sbas_id));
- foreach ($base_ids as $collection) {
- $retjs['collections'][] = array('id' => (string) ($collection->get_coll_id()), 'name' => $collection->get_name());
- }
- } catch (Exception $e) {
-
- }
-
- return p4string::jsonencode($retjs);
- }
-}
diff --git a/lib/classes/task/period/writemeta.php b/lib/classes/task/period/writemeta.php
index 2c85e7f4a8..6d532270c1 100644
--- a/lib/classes/task/period/writemeta.php
+++ b/lib/classes/task/period/writemeta.php
@@ -44,7 +44,7 @@ class task_period_writemeta extends task_databoxAbstract
$request = http_request::getInstance();
$parm2 = $request->get_parms(
- "period"
+ 'period'
, 'cleardoc'
, 'maxrecs'
, 'maxmegs'
@@ -54,7 +54,12 @@ class task_period_writemeta extends task_databoxAbstract
$dom->formatOutput = true;
if ($dom->loadXML($oldxml)) {
$xmlchanged = false;
- foreach (array("str:period", 'str:maxrecs', 'str:maxmegs', 'boo:cleardoc') as $pname) {
+ foreach (array(
+ 'str:period'
+ , 'str:maxrecs'
+ , 'str:maxmegs'
+ , 'boo:cleardoc'
+ ) as $pname) {
$ptype = substr($pname, 0, 3);
$pname = substr($pname, 4);
$pvalue = $parm2[$pname];
@@ -65,13 +70,12 @@ class task_period_writemeta extends task_databoxAbstract
}
} else {
// le champ n'existait pas dans le xml, on le cree
- $dom->documentElement->appendChild($dom->createTextNode("\t"));
$ns = $dom->documentElement->appendChild($dom->createElement($pname));
- $dom->documentElement->appendChild($dom->createTextNode("\n"));
}
// on fixe sa valeur
switch ($ptype) {
case "str":
+ case "pop":
$ns->appendChild($dom->createTextNode($pvalue));
break;
case "boo":
@@ -88,29 +92,25 @@ class task_period_writemeta extends task_databoxAbstract
public function xml2graphic($xml, $form)
{
if (false !== $sxml = simplexml_load_string($xml)) {
- if ((int) ($sxml->period) < 10) {
- $sxml->period = 10;
- } elseif ((int) ($sxml->period) > 300) {
- $sxml->period = 300;
+
+ if ((int) ($sxml->period) < self::MINPERIOD) {
+ $sxml->period = self::MINPERIOD;
+ } elseif ((int) ($sxml->period) > self::MAXPERIOD) {
+ $sxml->period = self::MAXPERIOD;
}
- if ((string) ($sxml->maxrecs) == '') {
- $sxml->maxrecs = 100;
- }
- if ((int) ($sxml->maxrecs) < 10) {
- $sxml->maxrecs = 10;
- } elseif ((int) ($sxml->maxrecs) > 500) {
- $sxml->maxrecs = 500;
+ if ((int) ($sxml->maxrecs) < self::MINRECS) {
+ $sxml->maxrecs = self::MINRECS;
+ } elseif (self::MAXRECS != -1 && (int) ($sxml->maxrecs) > self::MAXRECS) {
+ $sxml->maxrecs = self::MAXRECS;
}
- if ((string) ($sxml->maxmegs) == '') {
- $sxml->maxmegs = 6;
- }
- if ((int) ($sxml->maxmegs) < 3) {
- $sxml->maxmegs = 3;
- } elseif ((int) ($sxml->maxmegs) > 32) {
- $sxml->maxmegs = 32;
+ if ((int) ($sxml->maxmegs) < self::MINMEGS) {
+ $sxml->maxmegs = self::MINMEGS;
+ } elseif (self::MAXMEGS != -1 && (int) ($sxml->maxmegs) > self::MAXMEGS) {
+ $sxml->maxmegs = self::MAXMEGS;
}
+
?>
:
-
-
+
+
-
+
+
-
+
-
+
Mo
@@ -307,9 +314,9 @@ class task_period_writemeta extends task_databoxAbstract
try {
$writer->write($file, $metadatas);
- $this->log(sprintf('Success writing meta for sbas_id=%1$d - record_id=%2$d (%3$s)', $this->sbas_id, $record_id, $name));
+ $this->log(sprintf('meta written for sbasid=%1$d - recordid=%2$d (%3$s)', $this->sbas_id, $record_id, $name), self::LOG_INFO);
} catch (\PHPExiftool\Exception\Exception $e) {
- $this->log(sprintf('Failure writing meta for sbas_id=%1$d - record_id=%2$d (%3$s)', $this->sbas_id, $record_id, $name));
+ $this->log(sprintf('meta NOT written for sbasid=%1$d - recordid=%2$d (%3$s) because "%s"', $this->sbas_id, $record_id, $name, $e->getMessage()), self::LOG_ERROR);
}
}
diff --git a/templates/web/admin/task.html.twig b/templates/web/admin/task.html.twig
index 6ba5af176e..ed2b2a1431 100644
--- a/templates/web/admin/task.html.twig
+++ b/templates/web/admin/task.html.twig
@@ -67,6 +67,8 @@
+
+