mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-10 11:33:17 +00:00
syslog + maillog in task / task-manager as service
fix task interfaces / cleanup fix tests using task manager
This commit is contained in:
@@ -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
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
*
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Alchemy\Phrasea\Core\Provider;
|
||||
|
||||
use Alchemy\Phrasea\Core\Service\Builder;
|
||||
use Silex\Application;
|
||||
use Silex\ServiceProviderInterface;
|
||||
|
||||
@@ -19,8 +20,13 @@ 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();
|
||||
});
|
||||
}
|
||||
|
||||
|
113
lib/Alchemy/Phrasea/Core/Service/TaskManager/TaskManager.php
Normal file
113
lib/Alchemy/Phrasea/Core/Service/TaskManager/TaskManager.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2012 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\Core\Service\TaskManager;
|
||||
|
||||
use Monolog\Handler;
|
||||
use Alchemy\Phrasea\Core;
|
||||
use Alchemy\Phrasea\Core\Service;
|
||||
use Alchemy\Phrasea\Core\Service\ServiceAbstract;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||
|
||||
/**
|
||||
* Define a Border Manager service which handles checks on files that comes in
|
||||
* Phraseanet
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class TaskManager extends ServiceAbstract
|
||||
{
|
||||
/** `
|
||||
* `@var \task_manager
|
||||
*/
|
||||
protected $taskManager;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function init()
|
||||
{
|
||||
$options = $this->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');
|
||||
}
|
||||
|
||||
}
|
@@ -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);
|
||||
|
||||
|
@@ -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();
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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) {
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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();
|
||||
|
@@ -2,5 +2,8 @@
|
||||
|
||||
class sso
|
||||
{
|
||||
|
||||
public function get_login()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
@@ -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) {
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
<?php echo $form ?>.period.value = "<?php echo p4string::MakeString($sxml->period, "js", '"') ?>";
|
||||
<?php echo $form ?>.logsql.checked = <?php echo ($sxml->logsql > 0 ? 'true' : 'false'); ?>;
|
||||
|
||||
parent.$("#sqlu").text("");
|
||||
parent.$("#sqls").text("");
|
||||
var data = {};
|
||||
data["ACT"] = "CALCTEST";
|
||||
data["taskid"]=<?php echo $this->getID(); ?>;
|
||||
data["cls"]="RecordMover";
|
||||
data["xml"] = "<?php echo p4string::MakeString($sxml->saveXML(), "js", '"') ?>";
|
||||
parent.$.ajax({ url: "/admin/task-manager/task/<?php echo $this->getID(); ?>/facility/"
|
||||
, data: data
|
||||
, dataType:'json'
|
||||
, type:"POST"
|
||||
, async:true
|
||||
, success:function(data) {
|
||||
t = "";
|
||||
for (i in data.tasks) {
|
||||
t += "<div class=\"title\"> ";
|
||||
if(data.tasks[i].active)
|
||||
t += "<span class=\"active\"> X </span> ";
|
||||
else
|
||||
t += "<span class=\"notactive\"> X </span> ";
|
||||
if(data.tasks[i].name_htmlencoded)
|
||||
t += "<b>" + data.tasks[i].name_htmlencoded + "</b>";
|
||||
else
|
||||
t += "<b><i>sans nom</i></b>";
|
||||
|
||||
if(data.tasks[i].basename_htmlencoded)
|
||||
t += " (action=" + data.tasks[i].action + ' on ' + data.tasks[i].basename_htmlencoded + ')';
|
||||
else
|
||||
t += " (action=" + data.tasks[i].action + ' on <i>Unknown</i>)';
|
||||
t += "</div>";
|
||||
|
||||
if(data.tasks[i].err_htmlencoded) ;
|
||||
t += "<div class=\"err\">" + data.tasks[i].err_htmlencoded + "</div>";
|
||||
|
||||
t += "<div class=\"sql\">";
|
||||
|
||||
if(data.tasks[i].sql && data.tasks[i].sql.test.sql_htmlencoded)
|
||||
t += "<div class=\"sqltest\">" + data.tasks[i].sql.test.sql_htmlencoded + "</div>";
|
||||
t += "--> <span id=\"SQLRET"+i+"\"><i>wait...</i></span><br/>";
|
||||
|
||||
t += "</div>";
|
||||
}
|
||||
parent.$("#sqla").html(t);
|
||||
|
||||
var data = {};
|
||||
data["ACT"] = "PLAYTEST";
|
||||
data["taskid"]=<?php echo $this->getID(); ?>;
|
||||
data["cls"]="RecordMover";
|
||||
data["xml"] = "<?php echo p4string::MakeString($sxml->saveXML(), "js", '"') ?>";
|
||||
parent.$.ajax({ url: "/admin/task-manager/task/<?php echo $this->getID(); ?>/facility/"
|
||||
, data: data
|
||||
, dataType:'json'
|
||||
, type:"POST"
|
||||
, async:true
|
||||
, success:function(data) {
|
||||
for (i in data.tasks) {
|
||||
if (data.tasks[i].sql) {
|
||||
if (data.tasks[i].sql.test.err) {
|
||||
parent.$("#SQLRET"+i).html("err: " + data.tasks[i].sql.test.err);
|
||||
} else {
|
||||
t = '';
|
||||
for(j in data.tasks[i].sql.test.result.rids)
|
||||
t += (t?', ':'') + data.tasks[i].sql.test.result.rids[j];
|
||||
if(data.tasks[i].sql.test.result.rids.length < data.tasks[i].sql.test.result.n)
|
||||
t += ', ...';
|
||||
parent.$("#SQLRET"+i).html("n=" + data.tasks[i].sql.test.result.n + ", rids:(" + t + ")");
|
||||
}
|
||||
} else {
|
||||
parent.$("#SQLRET"+i).html("");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
<?php
|
||||
return "";
|
||||
} else { // ... so we NEVER come here
|
||||
// bad xml
|
||||
return "BAD XML";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PRINT head for the gui
|
||||
*/
|
||||
@@ -259,31 +151,30 @@ class task_period_RecordMover extends task_appboxAbstract
|
||||
{
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
function taskFillGraphic_<?php echo(get_class($this)); ?>(xmltxt)
|
||||
function taskFillGraphic_<?php echo(get_class($this));?>(xml)
|
||||
{
|
||||
if(xmltxt)
|
||||
$("#sqlu").text("");
|
||||
$("#sqls").text("");
|
||||
if(xml)
|
||||
{
|
||||
xml = $.parseXML(xmltxt);
|
||||
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'])
|
||||
{
|
||||
period.value = xml.find("period").text();
|
||||
logsql.checked = isyes(xml.find("logsql").text());
|
||||
period.value = xml2.find("period").text();
|
||||
logsql.checked = Number(xml2.find("logsql").text()) > 0;
|
||||
// maxrecs.value = xml.find("maxrecs").text();
|
||||
// maxmegs.value = xml.find("maxmegs").text();
|
||||
}
|
||||
|
||||
$("#sqlu").text("");
|
||||
$("#sqls").text("");
|
||||
$.ajax({ url: "/admin/task/<?php echo $this->getID() ?>/facility/"
|
||||
, data: {
|
||||
ACT: "CALCTEST",
|
||||
xml: xmltxt
|
||||
}
|
||||
var data = {};
|
||||
data["ACT"] = "CALCTEST";
|
||||
data["taskid"]=<?php echo $this->getID(); ?>;
|
||||
data["cls"]="RecordMover";
|
||||
data["xml"] = xml;
|
||||
$.ajax({ url: "/admin/task-manager/task/<?php echo $this->getID(); ?>/facility/"
|
||||
, data: data
|
||||
, dataType:'json'
|
||||
, type:"POST"
|
||||
, async:true
|
||||
@@ -319,11 +210,13 @@ class task_period_RecordMover extends task_appboxAbstract
|
||||
}
|
||||
$("#sqla").html(t);
|
||||
|
||||
$.ajax({ url: "/admin/task/<?php echo $this->getID() ?>/facility/"
|
||||
, data: {
|
||||
ACT: "PLAYTEST",
|
||||
xml: xmltxt
|
||||
}
|
||||
var data = {};
|
||||
data["ACT"] = "PLAYTEST";
|
||||
data["taskid"]=<?php echo $this->getID(); ?>;
|
||||
data["cls"]="RecordMover";
|
||||
data["xml"] = xml;
|
||||
$.ajax({ url: "/admin/task-manager/task/<?php echo $this->getID(); ?>/facility/"
|
||||
, data: data
|
||||
, dataType:'json'
|
||||
, type:"POST"
|
||||
, async:true
|
||||
@@ -346,33 +239,47 @@ class task_period_RecordMover extends task_appboxAbstract
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
$("#graphicForm *").change(function(){
|
||||
$(document).ready(
|
||||
function(){
|
||||
(function( $ ){
|
||||
$.fn.serializeJSON=function() {
|
||||
var json = {};
|
||||
jQuery.map($(this).serializeArray(), function(n, i){
|
||||
json[n['name']] = n['value'];
|
||||
});
|
||||
|
||||
return json;
|
||||
};
|
||||
})( jQuery );
|
||||
|
||||
var limits = {
|
||||
'period': {min:10, max:3600, allowempty:false}
|
||||
'period':{'min':<?php echo self::MINPERIOD; ?>, 'max':<?php echo self::MAXPERIOD; ?>},
|
||||
'delay':{min:0}
|
||||
} ;
|
||||
var name = $(this).attr("name");
|
||||
if(name && limits[name])
|
||||
$(".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();
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
</script>
|
||||
<?php
|
||||
@@ -387,12 +294,13 @@ class task_period_RecordMover extends task_appboxAbstract
|
||||
{
|
||||
ob_start();
|
||||
?>
|
||||
<form id="graphicForm" name="graphicForm" onsubmit="return(false);" method="post">
|
||||
<form name="graphicForm" onsubmit="return(false);" method="post">
|
||||
<br/>
|
||||
<?php echo _('task::_common_:periodicite de la tache') ?>
|
||||
<input type="text" name="period" style="width:40px;"" value="" />
|
||||
<input class="formElem" type="text" name="period" style="width:40px;" value="" />
|
||||
<?php echo _('task::_common_:secondes (unite temporelle)') ?>
|
||||
|
||||
<input type="checkbox" name="logsql" /> log changes
|
||||
<br/>
|
||||
<input class="formElem" type="checkbox" name="logsql" /> log changes
|
||||
</form>
|
||||
<center>
|
||||
<div class="terminal" id="sqla"></div>
|
||||
@@ -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'] : '<unknown>'));
|
||||
, $task['basename'] ? $task['basename'] : '<unknown>'), 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 <text field="XXX" compare="OP" value="ZZZ" />
|
||||
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 <date direction ="XXX" field="YYY" delta="Z" />
|
||||
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']);
|
||||
|
@@ -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<opts.length; i++) {
|
||||
if(opts[i].value == xml.find("base_id").text())
|
||||
basefound = i;
|
||||
var opts;
|
||||
var found;
|
||||
opts = base_id.options;
|
||||
for (found=0, i=1; found==0 && i<opts.length; i++) {
|
||||
if(opts[i].value == xml2.find("base_id").text())
|
||||
found = i;
|
||||
}
|
||||
opts[found].selected = true;
|
||||
period.value = xml2.find("period").text();
|
||||
hotfolder.value = xml2.find("hotfolder").text();
|
||||
cold.value = xml2.find("cold").text();
|
||||
move_archived.checked = Number(xml2.find("move_archived").text()) > 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
opts[basefound].selected = true;
|
||||
|
||||
hotfolder.value = xml.find("hotfolder").text();
|
||||
period.value = xml.find("period").text();
|
||||
cold.value = xml.find("cold").text();
|
||||
move_archived.checked = isyes(xml.find("move_archived").text());
|
||||
move_error.checked = isyes(xml.find("move_error").text());
|
||||
delfolder.checked = isyes(xml.find("delfolder").text());
|
||||
copy_spe.checked = isyes(xml.find("copy_spe").text());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$(document).ready(function(){
|
||||
$("#graphicForm *").change(function(){
|
||||
var limits = {
|
||||
'period': {min:10, max:3600, allowempty:false} ,
|
||||
'cold': {min:5, max:300, allowempty:false}
|
||||
'period':{'min':<?php echo self::MINPERIOD; ?>, 'max':<?php echo self::MAXPERIOD; ?>},
|
||||
'cold':{'min':<?php echo self::MINCOLD; ?>, 'max':<?php echo self::MAXCOLD; ?>}
|
||||
} ;
|
||||
var name = $(this).attr("name");
|
||||
if(name && limits[name])
|
||||
$(".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();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -200,13 +211,14 @@ class task_period_archive extends task_abstract
|
||||
{
|
||||
ob_start();
|
||||
?>
|
||||
<form id="graphicForm" name="graphicForm" onsubmit="return(false);" method="post">
|
||||
<form name="graphicForm" onsubmit="return(false);" method="post">
|
||||
<br/>
|
||||
<?php echo _('task::archive:archivage sur base/collection/') ?> :
|
||||
|
||||
<select name="base_id">
|
||||
<select class="formElem" name="base_id">
|
||||
<option value="">...</option>
|
||||
<?php
|
||||
foreach ($this->dependencyContainer['phraseanet.appbox']->get_databoxes() as $databox) {
|
||||
foreach($this->dependencyContainer['phraseanet.appbox']->get_databoxes() as $databox) {
|
||||
foreach ($databox->get_collections() as $collection) {
|
||||
print("<option value=\"" . $collection->get_base_id() . "\">" . $databox->get_viewname() . " / " . $collection->get_name() . "</option>");
|
||||
}
|
||||
@@ -216,29 +228,21 @@ class task_period_archive extends task_abstract
|
||||
<br/>
|
||||
<br/>
|
||||
<?php echo _('task::_common_:hotfolder') ?>
|
||||
<input type="text" name="hotfolder" style="width:400px;" onchange="chgxmltxt(this, 'hotfolder');" value=""><br/>
|
||||
<input class="formElem" type="text" name="hotfolder" style="width:400px;" value=""><br/>
|
||||
<br/>
|
||||
<?php echo _('task::_common_:periodicite de la tache') ?> :
|
||||
<input type="text" name="period" style="width:40px;" onchange="chgxmltxt(this, 'period');" value=""> <?php echo _('task::_common_:secondes (unite temporelle)') ?><br/>
|
||||
<input class="formElem" type="text" name="period" style="width:40px;" value=""> <?php echo _('task::_common_:secondes (unite temporelle)') ?><br/>
|
||||
<br/>
|
||||
<?php echo _('task::archive:delai de \'repos\' avant traitement') ?> :
|
||||
<input type="text" name="cold" style="width:40px;" onchange="chgxmltxt(this, 'cold');" value=""> <?php echo _('task::_common_:secondes (unite temporelle)') ?><br/>
|
||||
<?php echo _('task::_common_:hotfolder') ?>
|
||||
<input type="text" name="hotfolder" style="width:400px;" value=""><br/>
|
||||
<input class="formElem" type="text" name="cold" style="width:40px;" value=""> <?php echo _('task::_common_:secondes (unite temporelle)') ?><br/>
|
||||
<br/>
|
||||
<?php echo _('task::_common_:periodicite de la tache') ?> :
|
||||
<input type="text" name="period" style="width:40px;" value=""> <?php echo _('task::_common_:secondes (unite temporelle)') ?><br/>
|
||||
<br/>
|
||||
<?php echo _('task::archive:delai de \'repos\' avant traitement') ?> :
|
||||
<input type="text" name="cold" style="width:40px;" value=""> <?php echo _('task::_common_:secondes (unite temporelle)') ?><br/>
|
||||
<br/>
|
||||
<input type="checkbox" name="move_archived"> <?php echo _('task::archive:deplacer les fichiers archives dans _archived') ?>
|
||||
<input class="formElem" type="checkbox" name="move_archived"> <?php echo _('task::archive:deplacer les fichiers archives dans _archived') ?>
|
||||
|
||||
<input type="checkbox" name="move_error"> <?php echo _('task::archive:deplacer les fichiers non-archives dans _error') ?><br/>
|
||||
<input class="formElem" type="checkbox" name="move_error"> <?php echo _('task::archive:deplacer les fichiers non-archives dans _error') ?><br/>
|
||||
<br/>
|
||||
<input type="checkbox" name="copy_spe"> <?php echo _('task::archive:copier les fichiers \'.phrasea.xml\' et \'.grouping.xml\' dans _archived') ?><br/>
|
||||
<input class="formElem" type="checkbox" name="copy_spe"> <?php echo _('task::archive:copier les fichiers \'.phrasea.xml\' et \'.grouping.xml\' dans _archived') ?><br/>
|
||||
<br/>
|
||||
<input type="checkbox" name="delfolder"> <?php echo _('task::archive:supprimer les repertoires apres archivage') ?><br/>
|
||||
<input class="formElem" type="checkbox" name="delfolder"> <?php echo _('task::archive:supprimer les repertoires apres archivage') ?><br/>
|
||||
</form>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
@@ -267,7 +271,7 @@ class task_period_archive extends task_abstract
|
||||
$base_id = (int) ($this->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);
|
||||
}
|
||||
|
@@ -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)) {
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
<?php echo $form ?>.binpath.value = "<?php echo p4string::MakeString($sxml->binpath, "js", '"') ?>";
|
||||
<?php echo $form ?>.host.value = "<?php echo p4string::MakeString($sxml->host, "js", '"') ?>";
|
||||
<?php echo $form ?>.port.value = "<?php echo p4string::MakeString($sxml->port, "js", '"') ?>";
|
||||
<?php echo $form ?>.base.value = "<?php echo p4string::MakeString($sxml->base, "js", '"') ?>";
|
||||
<?php echo $form ?>.user.value = "<?php echo p4string::MakeString($sxml->user, "js", '"') ?>";
|
||||
<?php echo $form ?>.socket.value = "<?php echo p4string::MakeString($sxml->socket, "js", '"') ?>";
|
||||
<?php echo $form ?>.password.value = "<?php echo p4string::MakeString($sxml->password, "js", '"') ?>";
|
||||
<?php echo $form ?>.clng.value = "<?php echo p4string::MakeString($sxml->clng, "js", '"') ?>";
|
||||
<?php echo $form ?>.use_sbas.checked = <?php echo trim((string) $sxml->use_sbas) != '' ? (p4field::isyes($sxml->use_sbas) ? 'true' : 'false') : 'true' ?>;
|
||||
<?php echo $form ?>.nolog.checked = <?php echo p4field::isyes($sxml->nolog) ? 'true' : 'false' ?>;
|
||||
<?php echo $form ?>.winsvc_run.checked = <?php echo p4field::isyes($sxml->winsvc_run) ? 'true' : 'false' ?>;
|
||||
<?php echo $form ?>.charset.value = "<?php echo trim((string) $sxml->charset) != '' ? p4string::MakeString($sxml->charset, "js", '"') : 'utf8' ?>";
|
||||
<?php echo $form ?>.debugmask.value = "<?php echo trim((string) $sxml->debugmask) != '' ? p4string::MakeString($sxml->debugmask, "js", '"') : '0' ?>";
|
||||
parent.calccmd();
|
||||
</script>
|
||||
<?php
|
||||
return("");
|
||||
} else { // ... so we NEVER come here
|
||||
// bad xml
|
||||
return("BAD XML");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
|
@@ -46,14 +46,22 @@ class task_period_ftp extends task_appboxAbstract
|
||||
$request = http_request::getInstance();
|
||||
|
||||
$parm2 = $request->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}
|
||||
'period' :{'min':<?php echo self::MINPERIOD; ?>, 'max':<?php echo self::MAXPERIOD; ?>}
|
||||
} ;
|
||||
var name = $(this).attr("name");
|
||||
if(name && limits[name])
|
||||
$(".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();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -145,18 +154,16 @@ class task_period_ftp extends task_appboxAbstract
|
||||
<form id="graphicForm" name="graphicForm" onsubmit="return(false);" method="post">
|
||||
<br/>
|
||||
<?php echo _('task::ftp:proxy') ?>
|
||||
<input type="text" name="proxy" style="width:400px;"><br/>
|
||||
<input class="formElem" type="text" name="proxy" style="width:400px;" /><br/>
|
||||
<br/>
|
||||
<?php echo _('task::ftp:proxy port') ?>
|
||||
<input type="text" name="proxyport" style="width:400px;"><br/>
|
||||
<input class="formElem" type="text" name="proxyport" style="width:400px;" /><br/>
|
||||
<br/>
|
||||
|
||||
<?php echo _('task::_common_:periodicite de la tache') ?> :
|
||||
<input type="text" name="period" style="width:40px;">
|
||||
<input class="formElem" type="text" name="period" style="width:40px;" />
|
||||
<?php echo _('task::_common_:secondes (unite temporelle)') ?><br/>
|
||||
</form>
|
||||
<?php
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
@@ -164,14 +171,26 @@ class task_period_ftp extends task_appboxAbstract
|
||||
{
|
||||
$request = http_request::getInstance();
|
||||
|
||||
$parm = $request->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');
|
||||
}
|
||||
}
|
||||
|
@@ -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)) {
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
<?php echo $form ?>.proxy.value = "<?php echo p4string::MakeString($sxml->proxy, "js", '"') ?>";
|
||||
<?php echo $form ?>.proxyport.value = "<?php echo p4string::MakeString($sxml->proxyport, "js", '"') ?>";
|
||||
<?php echo $form ?>.period.value = "<?php echo p4string::MakeString($sxml->period, "js", '"') ?>";
|
||||
|
||||
<?php echo $form ?>.localpath.value = "<?php echo p4string::MakeString($sxml->localpath, "js", '"') ?>";
|
||||
<?php echo $form ?>.ftppath.value = "<?php echo p4string::MakeString($sxml->ftppath, "js", '"') ?>";
|
||||
<?php echo $form ?>.host.value = "<?php echo p4string::MakeString($sxml->host, "js", '"') ?>";
|
||||
<?php echo $form ?>.port.value = "<?php echo p4string::MakeString($sxml->port, "js", '"') ?>";
|
||||
<?php echo $form ?>.user.value = "<?php echo p4string::MakeString($sxml->user, "js", '"') ?>";
|
||||
<?php echo $form ?>.password.value = "<?php echo p4string::MakeString($sxml->password, "js", '"') ?>";
|
||||
<?php echo $form ?>.ssl.checked = <?php echo p4field::isyes($sxml->ssl) ? "true" : 'false' ?>;
|
||||
<?php echo $form ?>.passive.checked = <?php echo p4field::isyes($sxml->passive) ? "true" : 'false' ?>;
|
||||
</script>
|
||||
|
||||
<?php
|
||||
|
||||
return("");
|
||||
} else { // ... so we NEVER come here
|
||||
// bad xml
|
||||
return("BAD XML");
|
||||
}
|
||||
}
|
||||
|
||||
public function printInterfaceJS()
|
||||
{
|
||||
global $parm;
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
function chgxmltxt(textinput, fieldname)
|
||||
|
||||
function taskFillGraphic_<?php echo(get_class($this));?>(xml)
|
||||
{
|
||||
setDirty();
|
||||
}
|
||||
function chgxmlck(checkinput, fieldname)
|
||||
if(xml)
|
||||
{
|
||||
setDirty();
|
||||
}
|
||||
function chgxmlpopup(popupinput, fieldname)
|
||||
xml = $.parseXML(xml);
|
||||
xml = $(xml);
|
||||
|
||||
with(document.forms['graphicForm'])
|
||||
{
|
||||
setDirty();
|
||||
proxy.value = xml.find("proxy").text();
|
||||
proxyport.value = xml.find("proxyport").text();
|
||||
period.value = xml.find("period").text();
|
||||
localpath.value = xml.find("localpath").text();
|
||||
ftppath.value = xml.find("ftppath").text();
|
||||
host.value = xml.find("host").text();
|
||||
port.value = xml.find("port").text();
|
||||
user.value = xml.find("user").text();
|
||||
password.value = xml.find("password").text();
|
||||
ssl.checked = Number(xml.find("ssl").text()) > 0;
|
||||
passive.checked = Number(xml.find("passive").text()) > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
var limits = {
|
||||
'period' :{'min':<?php echo self::MINPERIOD; ?>, 'max':<?php echo self::MAXPERIOD; ?>}
|
||||
} ;
|
||||
$(".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();
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<?php
|
||||
@@ -137,43 +167,42 @@ class task_period_ftpPull extends task_appboxAbstract
|
||||
<form name="graphicForm" onsubmit="return(false);" method="post">
|
||||
<br/>
|
||||
<?php echo('task::ftp:proxy') ?>
|
||||
<input type="text" name="proxy" style="width:400px;" onchange="chgxmltxt(this, 'proxy');"><br/>
|
||||
<input class="formElem" type="text" name="proxy" style="width:400px;" /><br/>
|
||||
<br/>
|
||||
<?php echo('task::ftp:proxy port') ?>
|
||||
<input type="text" name="proxyport" style="width:400px;" onchange="chgxmltxt(this, 'proxyport');"><br/>
|
||||
<input class="formElem" type="text" name="proxyport" style="width:400px;" /><br/>
|
||||
<br/>
|
||||
|
||||
<?php echo('task::ftp:host') ?>
|
||||
<input type="text" name="host" style="width:400px;" onchange="chgxmltxt(this, 'host');"><br/>
|
||||
<input class="formElem" type="text" name="host" style="width:400px;" /><br/>
|
||||
<br/>
|
||||
<?php echo('task::ftp:port') ?>
|
||||
<input type="text" name="port" style="width:400px;" onchange="chgxmltxt(this, 'port');"><br/>
|
||||
<input class="formElem" type="text" name="port" style="width:400px;" /><br/>
|
||||
<br/>
|
||||
<?php echo('task::ftp:user') ?>
|
||||
<input type="text" name="user" style="width:400px;" onchange="chgxmltxt(this, 'user');"><br/>
|
||||
<input class="formElem" type="text" name="user" style="width:400px;" /><br/>
|
||||
<br/>
|
||||
<?php echo('task::ftp:password') ?>
|
||||
<input type="password" name="password" style="width:400px;" onchange="chgxmltxt(this, 'password');"><br/>
|
||||
<input class="formElem" type="password" name="password" style="width:400px;" /><br/>
|
||||
<br/>
|
||||
<?php echo('task::ftp:chemin distant') ?>
|
||||
<input type="text" name="ftppath" style="width:400px;" onchange="chgxmltxt(this, 'ftppath');"><br/>
|
||||
<input class="formElem" type="text" name="ftppath" style="width:400px;" /><br/>
|
||||
<br/>
|
||||
<?php echo('task::ftp:localpath') ?>
|
||||
<input type="text" name="localpath" style="width:400px;" onchange="chgxmltxt(this, 'localpath');"><br/>
|
||||
<input class="formElem" type="text" name="localpath" style="width:400px;" /><br/>
|
||||
<br/>
|
||||
|
||||
<input type="checkbox" name="passive" onchange="chgxmlck(this)">
|
||||
<input class="formElem" type="checkbox" name="passive" />
|
||||
<?php echo _('task::ftp:mode passif') ?>
|
||||
<br/>
|
||||
<input type="checkbox" name="ssl" onchange="chgxmlck(this)">
|
||||
<input class="formElem" type="checkbox" name="ssl" />
|
||||
<?php echo _('task::ftp:utiliser SSL') ?>
|
||||
<br/>
|
||||
<?php echo('task::_common_:periodicite de la tache') ?>
|
||||
<input type="text" name="period" style="width:40px;" onchange="chgxmltxt(this, 'period');">
|
||||
<input class="formElem" type="text" name="period" style="width:40px;" />
|
||||
<?php echo('task::_common_:minutes (unite temporelle)') ?><br/>
|
||||
</form>
|
||||
<?php
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
@@ -182,9 +211,21 @@ class task_period_ftpPull extends task_appboxAbstract
|
||||
$request = http_request::getInstance();
|
||||
|
||||
$parm = $request->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();
|
||||
}
|
||||
|
@@ -1,777 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2012 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class task_period_outofdate extends task_abstract
|
||||
{
|
||||
|
||||
// ====================================================================
|
||||
// getName : must return the name for this kind of task
|
||||
// MANDATORY
|
||||
// ====================================================================
|
||||
public function getName()
|
||||
{
|
||||
return(_('Documents perimes'));
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
// graphic2xml : must return the xml (text) version of the form
|
||||
// ====================================================================
|
||||
public function graphic2xml($oldxml)
|
||||
{
|
||||
// global $parm;
|
||||
$request = http_request::getInstance();
|
||||
|
||||
$parm2 = $request->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;
|
||||
}
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
var i;
|
||||
var opts;
|
||||
var pops = [
|
||||
{'name':"sbas_id", 'val':"<?php echo p4string::MakeString($sxml->sbas_id, "js") ?>"},
|
||||
|
||||
{'name':"field1", 'val':"<?php echo p4string::MakeString($sxml->field1, "js") ?>"},
|
||||
{'name':"field2", 'val':"<?php echo p4string::MakeString($sxml->field2, "js") ?>"},
|
||||
{'name':"fieldDs1", 'val':"<?php echo p4string::MakeString($sxml->fieldDs1, "js") ?>"},
|
||||
{'name':"fieldDs2", 'val':"<?php echo p4string::MakeString($sxml->fieldDs2, "js") ?>"},
|
||||
|
||||
{'name':"status0", 'val':"<?php echo p4string::MakeString($sxml->status0, "js") ?>"},
|
||||
{'name':"coll0", 'val':"<?php echo p4string::MakeString($sxml->coll0, "js") ?>"},
|
||||
|
||||
{'name':"status1", 'val':"<?php echo p4string::MakeString($sxml->status1, "js") ?>"},
|
||||
{'name':"coll1", 'val':"<?php echo p4string::MakeString($sxml->coll1, "js") ?>"},
|
||||
|
||||
{'name':"status2", 'val':"<?php echo p4string::MakeString($sxml->status2, "js") ?>"},
|
||||
{'name':"coll2", 'val':"<?php echo p4string::MakeString($sxml->coll2, "js") ?>"}
|
||||
];
|
||||
for (j in pops) {
|
||||
for (opts=<?php echo $form ?>[pops[j].name].options, i=0; i<opts.length; i++) {
|
||||
if (opts[i].value == pops[j].val) {
|
||||
opts[i].selected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(j==0)
|
||||
parent.chgsbas(<?php echo $form ?>[pops[j].name]);
|
||||
}
|
||||
<?php echo $form ?>.period.value = "<?php echo p4string::MakeString($sxml->period, "js", '"') ?>";
|
||||
<?php echo $form ?>.fieldDv1.value = "<?php echo p4string::MakeString($sxml->fieldDv1, "js", '"') ?>";
|
||||
<?php echo $form ?>.fieldDv2.value = "<?php echo p4string::MakeString($sxml->fieldDv2, "js", '"') ?>";
|
||||
parent.calcSQL();
|
||||
</script>
|
||||
<?php
|
||||
|
||||
return("");
|
||||
} else { // ... so we NEVER come here
|
||||
// bad xml
|
||||
return("BAD XML");
|
||||
}
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
// printInterfaceHEAD() :
|
||||
// ====================================================================
|
||||
public function printInterfaceHEAD()
|
||||
{
|
||||
?>
|
||||
<style>
|
||||
OPTION.jsFilled
|
||||
{
|
||||
padding-left:10px;
|
||||
padding-right:20px;
|
||||
}
|
||||
#OUTOFDATETAB TD
|
||||
{
|
||||
text-align:center;
|
||||
}
|
||||
.sqlcmd
|
||||
{
|
||||
font-family:monospace;
|
||||
font-size:12px;
|
||||
text-align:left; color:#00e000;
|
||||
}
|
||||
.sqlparams
|
||||
{
|
||||
font-family:monospace;
|
||||
font-size:12px;
|
||||
text-align:left; color:#00e0e0;
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
// printInterfaceJS() : generer le code js de l'interface 'graphic view'
|
||||
// ====================================================================
|
||||
public function printInterfaceJS()
|
||||
{
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
|
||||
(function( $ ){
|
||||
$.fn.serializeJSON=function() {
|
||||
var json = {};
|
||||
jQuery.map($(this).serializeArray(), function(n, i){
|
||||
json[n['name']] = n['value'];
|
||||
});
|
||||
|
||||
return json;
|
||||
};
|
||||
})( jQuery );
|
||||
|
||||
|
||||
function chgxmltxt(textinput, fieldname)
|
||||
{
|
||||
var limits = { 'period':{min:1, 'max':1440} , 'delay':{min:0} } ;
|
||||
if (typeof(limits[fieldname])!='undefined') {
|
||||
var v = 0|textinput.value;
|
||||
if(limits[fieldname].min && v < limits[fieldname].min)
|
||||
v = limits[fieldname].min;
|
||||
else if(limits[fieldname].max && v > limits[fieldname].max)
|
||||
v = limits[fieldname].max;
|
||||
textinput.value = v;
|
||||
}
|
||||
setDirty();
|
||||
calcSQL();
|
||||
}
|
||||
|
||||
function chgxmlck(checkinput, fieldname)
|
||||
{
|
||||
setDirty();
|
||||
calcSQL();
|
||||
}
|
||||
|
||||
function chgxmlpopup(popupinput, fieldname)
|
||||
{
|
||||
setDirty();
|
||||
calcSQL();
|
||||
}
|
||||
|
||||
function calcSQL()
|
||||
{
|
||||
var data = $("form[name='graphicForm']").serializeJSON();
|
||||
data["taskid"] = <?php echo $this->getID(); ?>;
|
||||
data["ACT"] = "CALCSQL";
|
||||
data["cls"]="outofdate";
|
||||
$.ajax({ url: "/admin/task-manager/task/<?php echo $this->getID(); ?>/facility/"
|
||||
, data: data
|
||||
, dataType:'json'
|
||||
, type:"POST"
|
||||
, async:false
|
||||
, success:function(data) {
|
||||
var s = "";
|
||||
for (i in data) {
|
||||
s += (s?"<br/>\n":"");
|
||||
s += "<div class=\"sqlcmd\">" + (data[i]["sql"]+'<br/>\n') + "</div>\n";
|
||||
var ptxt = "";
|
||||
for(p in data[i]["params"])
|
||||
ptxt += (ptxt?", ":"") + p + ':' + data[i]["params"][p];
|
||||
s += "<div class=\"sqlparams\">params:{" + ptxt + "}</div>\n";
|
||||
}
|
||||
$("#cmd").html(s);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function chgsbas(sbaspopup)
|
||||
{
|
||||
var data = {taskid:<?php echo $this->getID(); ?>, bid: sbaspopup.value};
|
||||
data["ACT"] = "GETBASE";
|
||||
data["cls"]="outofdate";
|
||||
$.ajax({ url: "/admin/task-manager/task/<?php echo $this->getID(); ?>/facility/"
|
||||
, data: data
|
||||
, dataType:'json'
|
||||
, type:"POST"
|
||||
, async:false
|
||||
, success:function(data) {
|
||||
var html = "<option value=\"\">...</option>";
|
||||
for(i in data.date_fields)
|
||||
html += "\n<option class=\"jsFilled\" value=\"" + data.date_fields[i] + "\">" + data.date_fields[i] + "</option>";
|
||||
for(fld=1; fld<=2; fld++)
|
||||
$("#field"+fld).html(html);
|
||||
|
||||
var html = "<option value=\"\">...</option>";
|
||||
for(i in data.collections)
|
||||
html += "\n<option class=\"jsFilled\" value=\"" + data.collections[i].id + "\">" + data.collections[i].name + "</option>";
|
||||
for(fld=0; fld<=2; fld++)
|
||||
$("#coll"+fld).html(html);
|
||||
|
||||
var html = "<option value=\"\">...</option>";
|
||||
for(i in data.status_bits)
|
||||
html += "\n<option class=\"jsFilled\" value=\"" + data.status_bits[i].n+"_"+data.status_bits[i].value + "\">" + data.status_bits[i].label + "</option>";
|
||||
for(fld=0; fld<=2; fld++)
|
||||
$("#status"+fld).html(html);
|
||||
}
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
// getInterfaceHTML(..) : retourner l'interface 'graphic view' !! EN UTF-8 !!
|
||||
// ====================================================================
|
||||
public function getInterfaceHTML()
|
||||
{
|
||||
ob_start();
|
||||
|
||||
$sbas_list = $this->dependencyContainer['phraseanet.user']->ACL()->get_granted_sbas(array('bas_manage'));
|
||||
?>
|
||||
<form name="graphicForm" onsubmit="return(false);" method="post">
|
||||
<?php echo _('task::outofdate:Base') ?> :
|
||||
|
||||
<select onchange="chgsbas(this);setDirty();" name="sbas_id">
|
||||
<option value="">...</option>
|
||||
<?php
|
||||
foreach ($sbas_list as $databox) {
|
||||
$selected = '';
|
||||
print("\t\t\t\t<option value=\"" . $databox->get_sbas_id() . "\" $selected>" . p4string::MakeString($databox->get_viewname(), "form") . "</option>\n");
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<?php echo _('task::_common_:periodicite de la tache') ?> :
|
||||
<input type="text" name="period" style="width:40px;" onchange="chgxmltxt(this, 'period');" value="">
|
||||
<?php echo _('task::_common_:minutes (unite temporelle)') ?><br/>
|
||||
<br/>
|
||||
|
||||
<table id="OUTOFDATETAB" style="margin-right:10px; ">
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td style="width:20%;">
|
||||
<?php echo _('task::outofdate:before') ?>
|
||||
</td>
|
||||
<td colspan="2" style="width:20%; white-space:nowrap;">
|
||||
<select style="width:100px" name="field1" id="field1" onchange="chgxmlpopup(this, 'field1');"></select>
|
||||
<br/>
|
||||
<select name="fieldDs1" id="fieldDs1" onchange="chgxmlpopup(this, 'fieldDs1');">
|
||||
<option value="+">+</option>
|
||||
<option value="-">-</option>
|
||||
</select>
|
||||
<input name="fieldDv1" id="fieldDv1" onchange="chgxmltxt(this, 'fieldDv1');" type="text" style="width:30px" value="0"></input> <?php echo _('admin::taskoutofdate: days ') ?>
|
||||
</td>
|
||||
<td style="width:20%; padding-left:20px; padding-right:20px;">
|
||||
<?php echo _('task::outofdate:between') ?>
|
||||
</td>
|
||||
<td colspan="2" style="width:20%; white-space:nowrap;">
|
||||
<select style="width:100px" name="field2" id="field2" onchange="chgxmlpopup(this, 'field2');"></select>
|
||||
<br/>
|
||||
<select name="fieldDs2" id="fieldDs2" onchange="chgxmlpopup(this, 'fieldDs2');">
|
||||
<option value="+">+</option>
|
||||
<option value="-">-</option>
|
||||
</select>
|
||||
<input name="fieldDv2" id="fieldDv2" onchange="chgxmltxt(this, 'fieldDv2');" type="text" style="width:30px" value="0"></input> <?php echo _('admin::taskoutofdate: days ') ?>
|
||||
</td>
|
||||
<td style="width:20%;">
|
||||
<?php echo _('task::outofdate:after') ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="white-space:nowrap;">
|
||||
<?php echo _('task::outofdate:coll.') ?> :
|
||||
</td>
|
||||
<td colspan="2" style="border-right:1px solid #000000">
|
||||
<select name="coll0" id="coll0" onchange="chgxmlpopup(this, 'coll0');"></select>
|
||||
</td>
|
||||
<td colspan="3" style="border-right:1px solid #000000">
|
||||
<select name="coll1" id="coll1" onchange="chgxmlpopup(this, 'coll1');"></select>
|
||||
</td>
|
||||
<td colspan="2">
|
||||
<select name="coll2" id="coll2" onchange="chgxmlpopup(this, 'coll2');"></select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="white-space:nowrap;">
|
||||
<?php echo _('task::outofdate:status') ?> :<br/>
|
||||
</td>
|
||||
<td colspan="2" style="border-right:1px solid #000000">
|
||||
<select name="status0" id="status0" onchange="chgxmlpopup(this, 'status0');"></select>
|
||||
</td>
|
||||
<td colspan="3" style="border-right:1px solid #000000">
|
||||
<select name="status1" id="status1" onchange="chgxmlpopup(this, 'status1');"></select>
|
||||
</td>
|
||||
<td colspan="2">
|
||||
<select name="status2" id="status2" onchange="chgxmlpopup(this, 'status2');"></select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
<br/>
|
||||
<center>
|
||||
<div style="margin:10px; padding:5px; border:1px #000000 solid; background-color:#404040" id="cmd">cmd</div>
|
||||
</center>
|
||||
<?php
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
// ====================================================================
|
||||
// $argt : command line args specifics to this task (optional)
|
||||
// ====================================================================
|
||||
public $argt = array(
|
||||
// "--truc" => 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('<?xml version="1.0" encoding="UTF-8"?><tasksettings/>');
|
||||
$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));
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
<?php echo $form ?>.period.value = "<?php echo p4string::MakeString($sxml->period, "js", '"') ?>";
|
||||
<?php echo $form ?>.flush.value = "<?php echo p4string::MakeString($sxml->flush, "js", '"') ?>";
|
||||
<?php echo $form ?>.maxrecs.value = "<?php echo p4string::MakeString($sxml->maxrecs, "js", '"') ?>";
|
||||
<?php echo $form ?>.maxmegs.value = "<?php echo p4string::MakeString($sxml->maxmegs, "js", '"') ?>";
|
||||
</script>
|
||||
|
||||
<?php
|
||||
return("");
|
||||
} else {
|
||||
return("BAD XML");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -79,26 +189,28 @@ class task_period_subdef extends task_databoxAbstract
|
||||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
$("#graphicForm *").change(function(){
|
||||
var limits = {
|
||||
'period': {min:1, max:300, allowempty:false} ,
|
||||
'flush': {min:1, max:100, allowempty:false} ,
|
||||
'maxrecs':{min:10, max:1000, allowempty:true} ,
|
||||
'maxmegs':{min:2, max:100, allowempty:true}
|
||||
'period' :{'min':<?php echo self::MINPERIOD; ?>, 'max':<?php echo self::MAXPERIOD; ?>},
|
||||
'flush' :{'min':<?php echo self::MINFLUSH; ?>, 'max':<?php echo self::MAXFLUSH; ?>},
|
||||
'maxrecs':{'min':<?php echo self::MINRECS; ?>, 'max':<?php echo self::MAXRECS; ?>},
|
||||
'maxmegs':{'min':<?php echo self::MINMEGS; ?>, 'max':<?php echo self::MAXMEGS; ?>}
|
||||
} ;
|
||||
var name = $(this).attr("name");
|
||||
if(name && limits[name])
|
||||
$(".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();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -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
|
||||
<form id="graphicForm" name="graphicForm" onsubmit="return(false);" method="post">
|
||||
<br/>
|
||||
<?php echo _('task::_common_:periodicite de la tache') ?> :
|
||||
<input type="text" name="period" style="width:40px;" value="">
|
||||
<?php echo _('task::_common_:secondes (unite temporelle)') ?><br/>
|
||||
<input class="formElem" type="text" name="period" style="width:40px;" value="">
|
||||
<?php echo _('task::_common_:secondes (unite temporelle)') ?>
|
||||
<br/>
|
||||
<?php echo sprintf(_("task::_common_:passer tous les %s records a l'etape suivante"), '<input type="text" name="flush" style="width:40px;" value="">'); ?>
|
||||
<br/>
|
||||
<?php echo sprintf(_("task::_common_:passer tous les %s records a l'etape suivante"), '<input class="formElem" type="text" name="flush" style="width:40px;" value="">'); ?>
|
||||
<br/>
|
||||
<br/>
|
||||
<?php echo _('task::_common_:relancer la tache tous les') ?>
|
||||
<input type="text" name="maxrecs" style="width:40px;" value="">
|
||||
<input class="formElem" type="text" name="maxrecs" style="width:40px;" value="">
|
||||
<?php echo _('task::_common_:records, ou si la memoire depasse') ?>
|
||||
<input type="text" name="maxmegs" style="width:40px;" value=""> Mo
|
||||
<input class="formElem" type="text" name="maxmegs" style="width:40px;" value="">
|
||||
Mo
|
||||
<br/>
|
||||
</form>
|
||||
<?php
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
@@ -141,8 +253,7 @@ class task_period_subdef extends task_databoxAbstract
|
||||
$sql = 'SELECT coll_id, record_id
|
||||
FROM record
|
||||
WHERE jeton & ' . JETON_MAKE_SUBDEF . ' > 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();
|
||||
|
@@ -1,472 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2012 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class task_period_workflow01 extends task_databoxAbstract
|
||||
{
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return(_('task::workflow01'));
|
||||
}
|
||||
|
||||
public function graphic2xml($oldxml)
|
||||
{
|
||||
$request = http_request::getInstance();
|
||||
|
||||
$parm2 = $request->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;
|
||||
}
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
var i;
|
||||
var opts;
|
||||
var pops = [
|
||||
{'name':"sbas_id", 'val':"<?php echo p4string::MakeString($sxml->sbas_id, "js") ?>"},
|
||||
|
||||
{'name':"status0", 'val':"<?php echo p4string::MakeString($sxml->status0, "js") ?>"},
|
||||
{'name':"coll0", 'val':"<?php echo p4string::MakeString($sxml->coll0, "js") ?>"},
|
||||
|
||||
{'name':"status1", 'val':"<?php echo p4string::MakeString($sxml->status1, "js") ?>"},
|
||||
{'name':"coll1", 'val':"<?php echo p4string::MakeString($sxml->coll1, "js") ?>"}
|
||||
];
|
||||
for (j in pops) {
|
||||
for (opts=<?php echo $form ?>[pops[j].name].options, i=0; i<opts.length; i++) {
|
||||
if (opts[i].value == pops[j].val) {
|
||||
opts[i].selected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(j==0)
|
||||
parent.chgsbas(<?php echo $form ?>[pops[j].name]);
|
||||
}
|
||||
<?php echo $form ?>.period.value = "<?php echo p4string::MakeString($sxml->period, "js", '"') ?>";
|
||||
parent.calccmd();
|
||||
</script>
|
||||
|
||||
<?php
|
||||
|
||||
return("");
|
||||
} else { // ... so we NEVER come here
|
||||
// bad xml
|
||||
return("BAD XML");
|
||||
}
|
||||
}
|
||||
|
||||
public function printInterfaceHEAD()
|
||||
{
|
||||
?>
|
||||
<style>
|
||||
OPTION.jsFilled
|
||||
{
|
||||
padding-left:10px;
|
||||
padding-right:20px;
|
||||
}
|
||||
#OUTOFDATETAB TD
|
||||
{
|
||||
text-align:center;
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function printInterfaceJS()
|
||||
{
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
function calccmd()
|
||||
{
|
||||
var cmd = '';
|
||||
with(document.forms['graphicForm'])
|
||||
{
|
||||
cmd += "";
|
||||
if ((coll0.value||status0.value) && (coll1.value||status1.value)) {
|
||||
cmd += "UPDATE record SET ";
|
||||
u = "";
|
||||
if(coll1.value)
|
||||
u += (u?", ":"") + "coll_id=" + coll1.value;
|
||||
if (status1.value) {
|
||||
x = status1.value.split("_");
|
||||
if(x[1]=="0")
|
||||
u += (u?", ":"") + "status=status&~(1<<" + x[0] + ")";
|
||||
else
|
||||
u += (u?", ":"") + "status=status|(1<<" + x[0] + ")";
|
||||
}
|
||||
cmd += u;
|
||||
w = "";
|
||||
if(coll0.value)
|
||||
w += (w?" AND ":"") + "coll_id=" + coll0.value;
|
||||
if (status0.value) {
|
||||
x = status0.value.split("_");
|
||||
if(x[1]=="0")
|
||||
w += (w?" AND ":"") + "(status>>" + x[0] + ")&1=0";
|
||||
else
|
||||
w += (w?" AND ":"") + "(status>>" + x[0] + ")&1=1";
|
||||
}
|
||||
cmd += " WHERE " + w;
|
||||
}
|
||||
}
|
||||
document.getElementById('cmd').innerHTML = cmd;
|
||||
}
|
||||
|
||||
function chgxmltxt(textinput, fieldname)
|
||||
{
|
||||
var limits = { 'period':{min:1, 'max':1440} , 'delay':{min:0} } ;
|
||||
if (typeof(limits[fieldname])!='undefined') {
|
||||
var v = 0|textinput.value;
|
||||
if(limits[fieldname].min && v < limits[fieldname].min)
|
||||
v = limits[fieldname].min;
|
||||
else if(limits[fieldname].max && v > limits[fieldname].max)
|
||||
v = limits[fieldname].max;
|
||||
textinput.value = v;
|
||||
}
|
||||
setDirty();
|
||||
calccmd();
|
||||
}
|
||||
|
||||
function chgxmlck(checkinput, fieldname)
|
||||
{
|
||||
setDirty();
|
||||
calccmd();
|
||||
}
|
||||
|
||||
function chgxmlpopup(popupinput, fieldname)
|
||||
{
|
||||
setDirty();
|
||||
calccmd();
|
||||
}
|
||||
|
||||
function chgsbas(sbaspopup)
|
||||
{
|
||||
for (fld=0; fld<=1; fld++) {
|
||||
var p = document.getElementById("status"+fld);
|
||||
while( (f=p.firstChild) )
|
||||
p.removeChild(f);
|
||||
var o = p.appendChild(document.createElement('option'));
|
||||
o.setAttribute('value', '');
|
||||
o.appendChild(document.createTextNode("..."));
|
||||
|
||||
var p = document.getElementById("coll"+fld);
|
||||
while( (f=p.firstChild) )
|
||||
p.removeChild(f);
|
||||
var o = p.appendChild(document.createElement('option'));
|
||||
o.setAttribute('value', '');
|
||||
o.appendChild(document.createTextNode("..."));
|
||||
}
|
||||
if (sbaspopup.value > 0) {
|
||||
$.ajax({
|
||||
url:"/admin/task-manager/task/<?php echo $this->getID(); ?>/facility/"
|
||||
, async:false
|
||||
, data:{'cls':'workflow01', 'taskid':<?php echo $this->getID() ?>, 'bid':sbaspopup.value}
|
||||
, success:function(data){
|
||||
for (fld=0; fld<=1; fld++) {
|
||||
var p = document.getElementById("status"+fld);
|
||||
for (i in data.status_bits) {
|
||||
var o = p.appendChild(document.createElement('option'));
|
||||
o.setAttribute('value', data.status_bits[i].n + "_" + data.status_bits[i].value);
|
||||
o.appendChild(document.createTextNode(data.status_bits[i].label));
|
||||
o.setAttribute('class', "jsFilled");
|
||||
}
|
||||
}
|
||||
|
||||
for (fld=0; fld<=1; fld++) {
|
||||
var p = document.getElementById("coll"+fld);
|
||||
for (i in data.collections) {
|
||||
var o = p.appendChild(document.createElement('option'));
|
||||
o.setAttribute('value', ""+data.collections[i].id);
|
||||
o.appendChild(document.createTextNode(data.collections[i].name));
|
||||
o.setAttribute('class', "jsFilled");
|
||||
}
|
||||
}
|
||||
}});
|
||||
}
|
||||
calccmd();
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function getInterfaceHTML()
|
||||
{
|
||||
ob_start();
|
||||
?>
|
||||
<form name="graphicForm" onsubmit="return(false);" method="post">
|
||||
<?php echo _('task::outofdate:Base') ?> :
|
||||
|
||||
<select onchange="chgsbas(this);setDirty();" name="sbas_id">
|
||||
<option value="">...</option>
|
||||
<?php
|
||||
$sbas_ids = $this->dependencyContainer['phraseanet.user']->ACL()->get_granted_sbas(array('bas_manage'));
|
||||
foreach ($sbas_ids as $databox) {
|
||||
print('<option value="' . $databox->get_sbas_id() . '">' . p4string::MakeString($databox->get_viewname(), "form") . '</option>');
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<?php echo _('task::_common_:periodicite de la tache') ?> :
|
||||
<input type="text" name="period" style="width:40px;" onchange="chgxmltxt(this, 'period');" value="">
|
||||
<?php echo _('task::_common_:minutes (unite temporelle)') ?><br/>
|
||||
<br/>
|
||||
|
||||
<table id="OUTOFDATETAB" style="margin-right:10px; ">
|
||||
<tr>
|
||||
<td style="white-space:nowrap;">
|
||||
Collection :
|
||||
</td>
|
||||
<td>
|
||||
<select name="coll0" id="coll0" onchange="chgxmlpopup(this, 'coll0');"></select>
|
||||
</td>
|
||||
<td rowspan="2">
|
||||
====>
|
||||
</td>
|
||||
<td>
|
||||
<select name="coll1" id="coll1" onchange="chgxmlpopup(this, 'coll1');"></select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="white-space:nowrap;">
|
||||
Status :
|
||||
</td>
|
||||
<td>
|
||||
<select name="status0" id="status0" onchange="chgxmlpopup(this, 'status0');"></select>
|
||||
</td>
|
||||
<td>
|
||||
<select name="status1" id="status1" onchange="chgxmlpopup(this, 'status1');"></select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
<br>
|
||||
<center>
|
||||
<div style="margin:10px; padding:5px; border:1px #000000 solid; font-family:monospace; font-size:16px; text-align:left; color:#00e000; background-color:#404040" id="cmd">cmd</div>
|
||||
</center>
|
||||
<?php
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
public function help()
|
||||
{
|
||||
return(_("task::outofdate:deplacement de docs suivant valeurs de champs 'date'"));
|
||||
}
|
||||
protected $status_origine;
|
||||
protected $coll_origine;
|
||||
protected $status_destination;
|
||||
protected $coll_destination;
|
||||
|
||||
protected function loadSettings(SimpleXMLElement $sx_task_settings)
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
<?php echo $form ?>.period.value = "<?php echo p4string::MakeString($sxml->period, "js", '"') ?>";
|
||||
@@ -119,7 +119,6 @@ class task_period_writemeta extends task_databoxAbstract
|
||||
<?php echo $form ?>.maxmegs.value = "<?php echo p4string::MakeString($sxml->maxmegs, "js", '"') ?>";
|
||||
</script>
|
||||
<?php
|
||||
|
||||
return("");
|
||||
} else { // ... so we NEVER come here
|
||||
// bad xml
|
||||
@@ -131,40 +130,47 @@ class task_period_writemeta extends task_databoxAbstract
|
||||
{
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
function chgxmltxt(textinput, fieldname)
|
||||
function taskFillGraphic_<?php echo(get_class($this));?>(xml)
|
||||
{
|
||||
var limits = { 'period':{min:1, 'max':300} , 'maxrecs':{min:10, 'max':1000} , 'maxmegs':{min:2, 'max':100} } ;
|
||||
if(xml)
|
||||
{
|
||||
xml = $.parseXML(xml);
|
||||
xml = $(xml);
|
||||
|
||||
with(document.forms['graphicForm'])
|
||||
{
|
||||
period.value = xml.find("period").text();
|
||||
cleardoc.checked = Number(xml.find("cleardoc").text()) > 0;
|
||||
maxrecs.value = xml.find("maxrecs").text();
|
||||
maxmegs.value = xml.find("maxmegs").text();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
var limits = {
|
||||
'period':{'min':<?php echo self::MINPERIOD; ?>, 'max':<?php echo self::MAXPERIOD; ?>},
|
||||
'maxrecs':{'min':<?php echo self::MINRECS; ?>, 'max':<?php echo self::MAXRECS; ?>},
|
||||
'maxmegs':{'min':<?php echo self::MINMEGS; ?>, 'max':<?php echo self::MAXMEGS; ?>}
|
||||
} ;
|
||||
$(".formElem").change(function(){
|
||||
fieldname = $(this).attr("name");
|
||||
switch((this.nodeName+$(this).attr("type")).toLowerCase())
|
||||
{
|
||||
case "inputtext":
|
||||
if (typeof(limits[fieldname])!='undefined') {
|
||||
var v = 0|textinput.value;
|
||||
var v = 0|this.value;
|
||||
if(v < limits[fieldname].min)
|
||||
v = limits[fieldname].min;
|
||||
else if(v > limits[fieldname].max)
|
||||
v = limits[fieldname].max;
|
||||
textinput.value = v;
|
||||
this.value = v;
|
||||
}
|
||||
break;
|
||||
}
|
||||
setDirty();
|
||||
}
|
||||
function chgxmlck_die(ck)
|
||||
{
|
||||
if (ck.checked) {
|
||||
if(document.forms['graphicForm'].maxrecs.value == "")
|
||||
document.forms['graphicForm'].maxrecs.value = 500;
|
||||
if(document.forms['graphicForm'].maxmegs.value == "")
|
||||
document.forms['graphicForm'].maxmegs.value = 4;
|
||||
document.forms['graphicForm'].maxrecs.disabled = document.forms['graphicForm'].maxmegs.disabled = false;
|
||||
} else {
|
||||
document.forms['graphicForm'].maxrecs.disabled = document.forms['graphicForm'].maxmegs.disabled = true;
|
||||
}
|
||||
setDirty();
|
||||
}
|
||||
function chgxmlck(checkinput, fieldname)
|
||||
{
|
||||
setDirty();
|
||||
}
|
||||
function chgxmlpopup(popupinput, fieldname)
|
||||
{
|
||||
setDirty();
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
@@ -179,17 +185,18 @@ class task_period_writemeta extends task_databoxAbstract
|
||||
<form name="graphicForm" onsubmit="return(false);" method="post">
|
||||
<br/>
|
||||
<?php echo _('task::_common_:periodicite de la tache') ?> :
|
||||
<input type="text" name="period" style="width:40px;" onchange="chgxmltxt(this, 'period');" value="">
|
||||
<?php echo _('task::_common_:secondes (unite temporelle)') ?><br/>
|
||||
<input class="formElem" type="text" name="period" style="width:40px;" value="">
|
||||
<?php echo _('task::_common_:secondes (unite temporelle)') ?>
|
||||
<br/>
|
||||
<input type="checkbox" name="cleardoc" onchange="chgxmlck(this)">
|
||||
<br/>
|
||||
<input class="formElem" type="checkbox" name="cleardoc">
|
||||
<?php echo _('task::writemeta:effacer les metadatas non presentes dans la structure') ?>
|
||||
<br/>
|
||||
<br/>
|
||||
<?php echo _('task::_common_:relancer la tache tous les') ?>
|
||||
<input type="text" name="maxrecs" style="width:40px;" onchange="chgxmltxt(this, 'maxrecs');" value="">
|
||||
<input class="formElem" type="text" name="maxrecs" style="width:40px;" value="">
|
||||
<?php echo _('task::_common_:records, ou si la memoire depasse') ?>
|
||||
<input type="text" name="maxmegs" style="width:40px;" onchange="chgxmltxt(this, 'maxmegs');" value="">
|
||||
<input class="formElem" type="text" name="maxmegs" style="width:40px;" value="">
|
||||
Mo
|
||||
<br/>
|
||||
</form>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -67,6 +67,8 @@
|
||||
|
||||
<button id="taskCancelButton">{% trans 'boutton::annuler' %}</button>
|
||||
<button id="taskSaveButton">{% trans 'boutton::valider' %}</button>
|
||||
<br/>
|
||||
<br/>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
@@ -181,11 +183,22 @@
|
||||
$("#taskSaveButton").click(function()
|
||||
{
|
||||
// click on save button
|
||||
|
||||
var data = $("form[name='graphicForm']").serializeJSON();
|
||||
data["__action"] = "FORM2XML";
|
||||
data["__xml"] = $("#txtareaxml").val();
|
||||
$.ajax({ url: "/admin/task-manager/task/{{task.getID()}}/facility/"
|
||||
, data: data
|
||||
, dataType:'text'
|
||||
, type:"POST"
|
||||
, async:false
|
||||
, success:function(data) {
|
||||
$("#txtareaxml").val(data);
|
||||
$.ajax({ url: "/admin/task-manager/task/{{task.getID()}}/save/"
|
||||
, data: {
|
||||
title:$("#taskTaskname").val(),
|
||||
active:!!$("#taskTaskActive").attr("checked"),
|
||||
xml:$("#txtareaxml").val()
|
||||
xml:data
|
||||
}
|
||||
, dataType:'json'
|
||||
, type:"POST"
|
||||
@@ -197,6 +210,11 @@
|
||||
alert("Erreur XML:\n\n" + jqXHR.responseText);
|
||||
}
|
||||
});
|
||||
}
|
||||
, error:function(jqXHR, textStatus, errorThrown) {
|
||||
alert(jqXHR.responseText);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
@@ -492,7 +492,7 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
$json = $this->getJson(self::$DI['client']->getResponse());
|
||||
$this->assertTrue($json->success);
|
||||
|
||||
$taskManager = new \task_manager(self::$DI['app']);
|
||||
$taskManager = self::$DI['app']['task-manager'];
|
||||
$tasks = $taskManager->getTasks();
|
||||
|
||||
$found = false;
|
||||
|
@@ -635,7 +635,7 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
$json = $this->getJson(self::$DI['client']->getResponse());
|
||||
$this->assertTrue($json->success);
|
||||
|
||||
$taskManager = new \task_manager(self::$DI['app']);
|
||||
$taskManager = self::$DI['app']['task-manager'];
|
||||
$tasks = $taskManager->getTasks();
|
||||
|
||||
$found = false;
|
||||
|
@@ -15,7 +15,7 @@ class TaskManagerTest extends \PhraseanetWebTestCaseAuthenticatedAbstract {
|
||||
}
|
||||
|
||||
public function testRouteTaskManager_tasks() {
|
||||
$task_manager = new \task_manager(self::$DI['app']);
|
||||
$task_manager = self::$DI['app']['task-manager'];
|
||||
|
||||
$crawler = self::$DI['client']->request(
|
||||
'GET', '/admin/task-manager/tasks/', array()
|
||||
@@ -36,7 +36,7 @@ class TaskManagerTest extends \PhraseanetWebTestCaseAuthenticatedAbstract {
|
||||
}
|
||||
|
||||
public function testRouteTaskManager_task_create() {
|
||||
$task_manager = new \task_manager(self::$DI['app']);
|
||||
$task_manager = self::$DI['app']['task-manager'];
|
||||
|
||||
$nTasks0 = count($task_manager->getTasks());
|
||||
|
||||
|
@@ -3,7 +3,7 @@
|
||||
use Alchemy\Phrasea\CLI;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
class module_console_schedulerStateTest extends PHPUnit_Framework_TestCase
|
||||
class module_console_schedulerStateTest extends PhraseanetPHPUnitAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -18,14 +18,15 @@ class module_console_schedulerStateTest extends PHPUnit_Framework_TestCase
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute(array('command' => $command->getName()));
|
||||
|
||||
$task_manager = new task_manager($application);
|
||||
$task_manager = self::$DI['app']['task-manager'];
|
||||
|
||||
$state = $task_manager->getSchedulerState();
|
||||
|
||||
$sentence = sprintf('Scheduler is %s', $state['status']);
|
||||
$this->assertTrue(strpos($commandTester->getDisplay(), $sentence) !== false);
|
||||
|
||||
$commandTester->execute(array('command' => $command->getName(), '--short'=>true));
|
||||
$task_manager = new task_manager($application);
|
||||
|
||||
$state = $task_manager->getSchedulerState();
|
||||
|
||||
$sentence = sprintf('%s(%s)', $state['status'], $state['pid']);
|
||||
|
@@ -27,7 +27,8 @@ class module_console_taskStateTest extends PhraseanetPHPUnitAbstract
|
||||
$this->assertTrue(strpos($commandTester->getDisplay(), $sentence) !== false);
|
||||
|
||||
// test good tasks ids
|
||||
$task_manager = new task_manager($application);
|
||||
$task_manager = self::$DI['app']['task-manager'];
|
||||
|
||||
$tasks = $task_manager->getTasks();
|
||||
$tids = array(); // list known ids of tasks so we can generate a 'unknown id' later
|
||||
foreach ($tasks as $task) {
|
||||
|
@@ -3,7 +3,7 @@
|
||||
use Alchemy\Phrasea\CLI;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
class module_console_tasklistTest extends PHPUnit_Framework_TestCase
|
||||
class module_console_tasklistTest extends PhraseanetPHPUnitAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -18,7 +18,7 @@ class module_console_tasklistTest extends PHPUnit_Framework_TestCase
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute(array('command' => $command->getName()));
|
||||
|
||||
$task_manager = new task_manager($application);
|
||||
$task_manager = self::$DI['app']['task-manager'];
|
||||
$lines = explode("\n", trim($commandTester->getDisplay()));
|
||||
|
||||
if (count($task_manager->getTasks()) > 0) {
|
||||
|
Reference in New Issue
Block a user