diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Collection.php b/lib/Alchemy/Phrasea/Controller/Admin/Collection.php
index 8204e58506..0aacf8f851 100644
--- a/lib/Alchemy/Phrasea/Controller/Admin/Collection.php
+++ b/lib/Alchemy/Phrasea/Controller/Admin/Collection.php
@@ -496,7 +496,7 @@ class Collection implements ControllerProviderInterface
$msg = _('Collection empty successful');
} else {
$settings = '' . $collection->get_base_id() . '';
- \task_abstract::create($app, 'task_period_emptyColl', $settings);
+ \task_period_emptyColl::create($app, $settings);
$msg = _('A task has been creted, please run it to complete empty collection');
}
diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Databox.php b/lib/Alchemy/Phrasea/Controller/Admin/Databox.php
index 05dd45112c..480bafbdb9 100644
--- a/lib/Alchemy/Phrasea/Controller/Admin/Databox.php
+++ b/lib/Alchemy/Phrasea/Controller/Admin/Databox.php
@@ -882,7 +882,7 @@ class Databox implements ControllerProviderInterface
$msg = _('Base empty successful');
} else {
$settings = "" . $collection->get_base_id() . "";
- \task_abstract::create($app, 'task_period_emptyColl', $settings);
+ \task_period_emptyColl::create($app, $settings);
$msg = _('A task has been creted, please run it to complete empty collection');
}
}
diff --git a/lib/Alchemy/Phrasea/Controller/Admin/TaskManager.php b/lib/Alchemy/Phrasea/Controller/Admin/TaskManager.php
index 9aa33edacb..6de02ae451 100644
--- a/lib/Alchemy/Phrasea/Controller/Admin/TaskManager.php
+++ b/lib/Alchemy/Phrasea/Controller/Admin/TaskManager.php
@@ -49,7 +49,11 @@ class TaskManager implements ControllerProviderInterface
})->bind('admin_tasks_list');
$controllers->post('/tasks/create/', function(Application $app, Request $request) {
- $task = \task_abstract::create($app, $request->request->get('tcl'));
+ if (!class_exists($className = $request->request->get('tcl'))) {
+ $app->abort(400, sprintf('Unknown task %s', $className));
+ }
+
+ $task = $className::create($app);
$tid = $task->getId();
return $app->redirectPath('admin_tasks_task_show', array('id' => $tid));
diff --git a/lib/Alchemy/Phrasea/Setup/Installer.php b/lib/Alchemy/Phrasea/Setup/Installer.php
index 24d8a01cf1..a9bf83c95a 100644
--- a/lib/Alchemy/Phrasea/Setup/Installer.php
+++ b/lib/Alchemy/Phrasea/Setup/Installer.php
@@ -94,30 +94,13 @@ class Installer
);
foreach (array('cindexer', 'subdef', 'writemeta') as $task) {
- $class_name = sprintf('task_period_%s', $task);
- if ($task === 'cindexer' && is_executable($this->phraseaIndexer)) {
- $credentials = $databox->get_appbox()->get_connection()->get_credentials();
+ $className = sprintf('task_period_%s', $task);
- $host = $credentials['hostname'];
- $port = $credentials['port'];
- $user_ab = $credentials['user'];
- $password = $credentials['password'];
- $dbname = $credentials['dbname'];
-
- $settings = "\n\n"
- . str_replace('/phraseanet_indexer', '', $this->phraseaIndexer)
- . "" . $host . ""
- . $port . ""
- . $dbname . ""
- . $user_ab . ""
- . $password . "25200"
- . "10"
- . "0utf8";
- } else {
- $settings = null;
+ if (!class_exists($className)) {
+ throw new \InvalidArgumentException('Unknown task class "' . $className.'"');
}
- \task_abstract::create($this->app, $class_name, $settings);
+ $className::create($this->app);
}
}
diff --git a/lib/classes/task/abstract.php b/lib/classes/task/abstract.php
index b17fa3aa3f..3a6d93894d 100644
--- a/lib/classes/task/abstract.php
+++ b/lib/classes/task/abstract.php
@@ -1,6 +1,7 @@
loadXML($settings)) {
- throw new Exception('settings invalide');
+ throw new Exception('Invalid settings');
} elseif (! $settings) {
- $settings = "\n\n";
+ $settings = static::getDefaultSettings($dependencyContainer['phraseanet.configuration']);
}
$params = array(
':active' => 1
, ':name' => ''
- , ':class' => $class_name
+ , ':class' => get_called_class()
, ':settings' => $settings
);
+
$stmt = $dependencyContainer['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
$tid = $dependencyContainer['phraseanet.appbox']->get_connection()->lastInsertId();
- $task = new $class_name($tid, $dependencyContainer, $dependencyContainer['task-manager.logger']);
+ $task = new static($tid, $dependencyContainer, $dependencyContainer['task-manager.logger']);
$task->setTitle($task->getName());
return $task;
@@ -917,4 +915,13 @@ abstract class task_abstract
return $this;
}
+
+ /**
+ *
+ * @param array $params
+ */
+ public static function getDefaultSettings(Configuration $config, array $params = array())
+ {
+ return "\n\n";
+ }
}
diff --git a/lib/classes/task/period/RecordMover.php b/lib/classes/task/period/RecordMover.php
index ad450b395c..798995d191 100644
--- a/lib/classes/task/period/RecordMover.php
+++ b/lib/classes/task/period/RecordMover.php
@@ -8,14 +8,10 @@
* file that was distributed with this source code.
*/
-/**
- *
- * @license http://opensource.org/licenses/gpl-3.0 GPLv3
- * @link www.phraseanet.com
- */
+use Alchemy\Phrasea\Core\Configuration\Configuration;
+
class task_period_RecordMover extends task_appboxAbstract
{
-
/**
*
* @return string
@@ -788,25 +784,97 @@ class task_period_RecordMover extends task_appboxAbstract
switch ($parm2['ACT']) {
case 'CALCTEST':
$sxml = simplexml_load_string($parm2['xml']);
- foreach ($sxml->tasks->task as $sxtask) {
- $ret['tasks'][] = $this->calcSQL($sxtask, false);
+ if (isset($sxml->tasks->task)) {
+ foreach ($sxml->tasks->task as $sxtask) {
+ $ret['tasks'][] = $this->calcSQL($sxtask, false);
+ }
}
break;
case 'PLAYTEST':
$sxml = simplexml_load_string($parm2['xml']);
- foreach ($sxml->tasks->task as $sxtask) {
- $ret['tasks'][] = $this->calcSQL($sxtask, true);
+ if (isset($sxml->tasks->task)) {
+ foreach ($sxml->tasks->task as $sxtask) {
+ $ret['tasks'][] = $this->calcSQL($sxtask, true);
+ }
}
break;
case 'CALCSQL':
$xml = $this->graphic2xml('');
$sxml = simplexml_load_string($xml);
- foreach ($sxml->tasks->task as $sxtask) {
- $ret['tasks'][] = $this->calcSQL($sxtask, false);
+ if (isset($sxml->tasks->task)) {
+ foreach ($sxml->tasks->task as $sxtask) {
+ $ret['tasks'][] = $this->calcSQL($sxtask, false);
+ }
}
break;
}
return json_encode($ret);
}
+
+ /**
+ * @param array $params
+ */
+ public static function getDefaultSettings(Configuration $config, array $params = array())
+ {
+ $period = isset($params['period']) ? $params['period'] : self::MINPERIOD;
+
+ return "
+
+ ". min(max($period, self::MINPERIOD), self::MAXPERIOD) ."
+ 0
+
+ ";
+ }
}
diff --git a/lib/classes/task/period/apibridge.php b/lib/classes/task/period/apibridge.php
index c724adf180..f299b0728e 100644
--- a/lib/classes/task/period/apibridge.php
+++ b/lib/classes/task/period/apibridge.php
@@ -9,11 +9,6 @@
* file that was distributed with this source code.
*/
-/**
- *
- * @license http://opensource.org/licenses/gpl-3.0 GPLv3
- * @link www.phraseanet.com
- */
class task_period_apibridge extends task_appboxAbstract
{
diff --git a/lib/classes/task/period/archive.php b/lib/classes/task/period/archive.php
index 00c7ec0954..a10fa8621c 100644
--- a/lib/classes/task/period/archive.php
+++ b/lib/classes/task/period/archive.php
@@ -9,6 +9,7 @@
*/
use Alchemy\Phrasea\Border\File;
+use Alchemy\Phrasea\Core\Configuration\Configuration;
use Alchemy\Phrasea\Metadata\Tag as PhraseaTag;
use Alchemy\Phrasea\Border\Attribute as BorderAttribute;
use Alchemy\Phrasea\Border\MetadataBag;
@@ -17,11 +18,6 @@ use PHPExiftool\Driver\Metadata\MetadataBag as ExiftoolMetadataBag;
use PHPExiftool\Driver\Metadata\Metadata;
use Symfony\Component\Filesystem\Exception\IOException;
-/**
- *
- * @license http://opensource.org/licenses/gpl-3.0 GPLv3
- * @link www.phraseanet.com
- */
class task_period_archive extends task_abstract
{
const MINCOLD = 5;
@@ -2206,4 +2202,24 @@ class CListFolder
{
return array_shift($this->list);
}
+
+ /**
+ * @param array $params
+ */
+ public static function getDefaultSettings(Configuration $config, array $params = array())
+ {
+ $period = isset($params['period']) ? $params['period'] : self::MINPERIOD;
+
+ return sprintf("
+
+
+
+ %s
+ 0
+ 0
+ 0
+ 0
+
+ ", min(max($period, self::MINPERIOD), self::MAXPERIOD));
+ }
}
diff --git a/lib/classes/task/period/cindexer.php b/lib/classes/task/period/cindexer.php
index 1f21f26781..8e0563f10f 100644
--- a/lib/classes/task/period/cindexer.php
+++ b/lib/classes/task/period/cindexer.php
@@ -8,13 +8,9 @@
* file that was distributed with this source code.
*/
+use Alchemy\Phrasea\Core\Configuration\Configuration;
use Symfony\Component\Process\ExecutableFinder;
-/**
- *
- * @license http://opensource.org/licenses/gpl-3.0 GPLv3
- * @link www.phraseanet.com
- */
class task_period_cindexer extends task_abstract
{
// how to execute indexer (choose in 'run2' method)
@@ -656,4 +652,23 @@ class task_period_cindexer extends task_abstract
pcntl_exec($cmd, $args);
sleep(2);
}
+
+ /**
+ * @param array $params
+ */
+ public static function getDefaultSettings(Configuration $config, array $params = array())
+ {
+ $binaries = $config['binaries'];
+ $database = $config['main']['database'];
+
+ return "\n\n"
+ . (array_key_exists('phraseanet_indexer', $binaries) ? str_replace('/phraseanet_indexer', '', $binaries['phraseanet_indexer']) : '')
+ . "" . $database['host'] . ""
+ . $database['port'] . ""
+ . $database['dbname'] . ""
+ . $database['user'] . ""
+ . $database['password'] . "25200"
+ . "10"
+ . "0utf8";
+ }
}
diff --git a/lib/classes/task/period/emptyColl.php b/lib/classes/task/period/emptyColl.php
index aeba0ec73e..9b91c8f0df 100644
--- a/lib/classes/task/period/emptyColl.php
+++ b/lib/classes/task/period/emptyColl.php
@@ -9,11 +9,6 @@
* file that was distributed with this source code.
*/
-/**
- *
- * @license http://opensource.org/licenses/gpl-3.0 GPLv3
- * @link www.phraseanet.com
- */
class task_period_emptyColl extends task_appboxAbstract
{
protected $base_id;
@@ -35,6 +30,15 @@ class task_period_emptyColl extends task_appboxAbstract
return("Vide une collection");
}
+ /**
+ *
+ * @param array $params
+ */
+ public static function getDefaultSettings(Configuration $config, array $params = array())
+ {
+ return "\n\n";
+ }
+
protected function loadSettings(SimpleXMLElement $sx_task_settings)
{
$this->base_id = (int) $sx_task_settings->base_id;
diff --git a/lib/classes/task/period/ftp.php b/lib/classes/task/period/ftp.php
index 3ca3bd5635..f2577790e6 100644
--- a/lib/classes/task/period/ftp.php
+++ b/lib/classes/task/period/ftp.php
@@ -8,10 +8,12 @@
* file that was distributed with this source code.
*/
+use Alchemy\Phrasea\Core\Configuration\Configuration;
use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Notification\Mail\MailSuccessFTPSender;
use Alchemy\Phrasea\Notification\Receiver;
+
class task_period_ftp extends task_appboxAbstract
{
protected $proxy;
@@ -704,4 +706,21 @@ class task_period_ftp extends task_appboxAbstract
return $this;
}
+
+
+ /**
+ * @param array $params
+ */
+ public static function getDefaultSettings(Configuration $config, array $params = array())
+ {
+ $period = isset($params['period']) ? $params['period'] : self::MINPERIOD;
+
+ return sprintf("
+
+
+
+ %s
+
+ ", min(max($period, self::MINPERIOD), self::MAXPERIOD));
+ }
}
diff --git a/lib/classes/task/period/ftpPull.php b/lib/classes/task/period/ftpPull.php
index a6f24b1042..c9211b79ce 100644
--- a/lib/classes/task/period/ftpPull.php
+++ b/lib/classes/task/period/ftpPull.php
@@ -8,11 +8,8 @@
* file that was distributed with this source code.
*/
-/**
- *
- * @license http://opensource.org/licenses/gpl-3.0 GPLv3
- * @link www.phraseanet.com
- */
+use Alchemy\Phrasea\Core\Configuration\Configuration;
+
class task_period_ftpPull extends task_appboxAbstract
{
protected $proxy;
@@ -453,4 +450,27 @@ class task_period_ftpPull extends task_appboxAbstract
{
}
+
+ /**
+ * @param array $params
+ */
+ public static function getDefaultSettings(Configuration $config, array $params = array())
+ {
+ $period = isset($params['period']) ? $params['period'] : self::MINPERIOD;
+
+ return sprintf("
+
+
+
+ %s
+ 0
+ 0
+
+
+
+
+ 21
+
+ ", min(max($period, self::MINPERIOD), self::MAXPERIOD));
+ }
}
diff --git a/lib/classes/task/period/subdef.php b/lib/classes/task/period/subdef.php
index 68a5531f42..484f107d6d 100644
--- a/lib/classes/task/period/subdef.php
+++ b/lib/classes/task/period/subdef.php
@@ -8,6 +8,8 @@
* file that was distributed with this source code.
*/
+use Alchemy\Phrasea\Core\Configuration\Configuration;
+
class task_period_subdef extends task_databoxAbstract
{
const MINMEGS = 20;
@@ -328,4 +330,28 @@ class task_period_subdef extends task_databoxAbstract
return $this;
}
+
+ /**
+ * @param array $params
+ */
+ public static function getDefaultSettings(Configuration $config, array $params = array())
+ {
+ $period = isset($params['period']) ? $params['period'] : self::MINPERIOD;
+ $flush = isset($params['flush']) ? $params['flush'] : self::MINFLUSH;
+ $maxrecs = isset($params['maxrecs']) ? $params['maxrecs'] : self::MINRECS;
+ $maxmegs = isset($params['maxmegs']) ? $params['maxmegs'] : self::MINMEGS;
+
+ return sprintf('
+
+ %s
+ %s
+ %s
+ %s
+ ',
+ min(max($period, self::MINPERIOD), self::MAXPERIOD),
+ min(max($flush, self::MINFLUSH), self::MAXFLUSH),
+ min(max($maxrecs, self::MINRECS), self::MAXRECS),
+ min(max($maxmegs, self::MINMEGS), self::MAXMEGS)
+ );
+ }
}
diff --git a/lib/classes/task/period/test.php b/lib/classes/task/period/test.php
index 31ed459de4..6960457afc 100644
--- a/lib/classes/task/period/test.php
+++ b/lib/classes/task/period/test.php
@@ -9,11 +9,6 @@
* file that was distributed with this source code.
*/
-/**
- *
- * @license http://opensource.org/licenses/gpl-3.0 GPLv3
- * @link www.phraseanet.com
- */
class task_period_test extends task_appboxAbstract
{
diff --git a/lib/classes/task/period/writemeta.php b/lib/classes/task/period/writemeta.php
index f58855a85a..3a0149aaf6 100644
--- a/lib/classes/task/period/writemeta.php
+++ b/lib/classes/task/period/writemeta.php
@@ -8,16 +8,12 @@
* file that was distributed with this source code.
*/
+use Alchemy\Phrasea\Core\Configuration\Configuration;
use PHPExiftool\Driver\Metadata;
use PHPExiftool\Driver\Value;
use PHPExiftool\Driver\Tag;
use PHPExiftool\Writer;
-/**
- *
- * @license http://opensource.org/licenses/gpl-3.0 GPLv3
- * @link www.phraseanet.com
- */
class task_period_writemeta extends task_databoxAbstract
{
protected $clear_doc;
@@ -340,4 +336,26 @@ class task_period_writemeta extends task_databoxAbstract
return $this;
}
+
+ /**
+ * @param array $params
+ */
+ public static function getDefaultSettings(Configuration $config, array $params = array())
+ {
+ $period = isset($params['period']) ? $params['period'] : self::MINPERIOD;
+ $maxrecs = isset($params['maxrecs']) ? $params['maxrecs'] : self::MINRECS;
+ $maxmegs = isset($params['maxmegs']) ? $params['maxmegs'] : self::MINMEGS;
+
+ return sprintf('
+
+ %s
+ %s
+ %s
+ 0
+ ',
+ min(max($period, self::MINPERIOD), self::MAXPERIOD),
+ min(max($maxrecs, self::MINRECS), self::MAXRECS),
+ min(max($maxmegs, self::MINMEGS), self::MAXMEGS)
+ );
+ }
}
diff --git a/tests/classes/task/period/task_period_archiveTest.php b/tests/classes/task/period/task_period_archiveTest.php
index 03bc118c4d..260de7ab2e 100644
--- a/tests/classes/task/period/task_period_archiveTest.php
+++ b/tests/classes/task/period/task_period_archiveTest.php
@@ -16,7 +16,7 @@ class task_period_archiveTest extends \PhraseanetPHPUnitAbstract
$app = new Application('test');
- $task = \task_period_archive::create($app, 'task_period_archive');
+ $task = \task_period_archive::create($app);
$logger = new \Monolog\Logger('test');
$logger->pushHandler(new \Monolog\Handler\NullHandler());
diff --git a/tests/classes/task/task_abstractTest.php b/tests/classes/task/task_abstractTest.php
index 50c3904475..937d31fca4 100644
--- a/tests/classes/task/task_abstractTest.php
+++ b/tests/classes/task/task_abstractTest.php
@@ -15,7 +15,7 @@ class task_abstractTest extends PhraseanetPHPUnitAbstract
parent::setUpBeforeClass();
$app = new Application('test');
- self::$task = task_abstract::create($app, 'task_period_test');
+ self::$task = task_period_test::create($app);
self::$tid = self::$task->getID();
}