diff --git a/config/configuration.sample.yml b/config/configuration.sample.yml index 46b839f9fe..98c336f961 100644 --- a/config/configuration.sample.yml +++ b/config/configuration.sample.yml @@ -129,6 +129,10 @@ registration-fields: required: true task-manager: status: started + listener: + protocol: tcp + host: 127.0.0.1 + port: 6700 xsendfile: enabled: false type: nginx diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Databoxes.php b/lib/Alchemy/Phrasea/Controller/Admin/Databoxes.php index 0f5902a471..90d12a7f48 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Databoxes.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Databoxes.php @@ -11,6 +11,7 @@ namespace Alchemy\Phrasea\Controller\Admin; +use Alchemy\Phrasea\TaskManager\TaskManagerStatus; use Silex\Application; use Silex\ControllerProviderInterface; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -331,7 +332,8 @@ class Databoxes implements ControllerProviderInterface */ public function databasesUpgrade(Application $app, Request $request) { - if (\phrasea::is_scheduler_started($app)) { + $info = $app['task-manager.live-information']->getManager(); + if (TaskManagerStatus::STATUS_STARTED === $info['actual']) { return $app->redirectPath('admin_databases', array('success' => 0, 'error' => 'scheduler-started')); } diff --git a/lib/Alchemy/Phrasea/Controller/Api/V1.php b/lib/Alchemy/Phrasea/Controller/Api/V1.php index a85b1296a0..19d258cbe1 100644 --- a/lib/Alchemy/Phrasea/Controller/Api/V1.php +++ b/lib/Alchemy/Phrasea/Controller/Api/V1.php @@ -210,21 +210,23 @@ class V1 implements ControllerProviderInterface /** * Get task informations * - * Route : /monitor/task/{task_id}/ + * Route : /monitor/task/{task}/ * * Method : GET * * Parameters : * */ - $controllers->get('/monitor/task/{task_id}/', function(SilexApplication $app, Request $request, $task_id) { - return $app['api']->get_task($app, $task_id)->get_response(); - })->before($mustBeAdmin)->assert('task_id', '\d+'); + $controllers->get('/monitor/task/{task}/', function(SilexApplication $app, Request $request, $task) { + return $app['api']->get_task($app, $task)->get_response(); + }) + ->convert('task', array($app['converter.task'], 'convert')) + ->before($mustBeAdmin)->assert('task', '\d+'); /** * Start task * - * Route : /monitor/task/{task_id}/ + * Route : /monitor/task/{task}/ * * Method : POST * @@ -232,37 +234,43 @@ class V1 implements ControllerProviderInterface * - name (string) change the name of the task * - autostart (boolean) start task when scheduler starts */ - $controllers->post('/monitor/task/{task_id}/', function(SilexApplication $app, Request $request, $task_id) { - return $app['api']->set_task_property($app, $task_id)->get_response(); - })->before($mustBeAdmin)->assert('task_id', '\d+'); + $controllers->post('/monitor/task/{task}/', function(SilexApplication $app, Request $request, $task) { + return $app['api']->set_task_property($app, $task)->get_response(); + }) + ->convert('task', array($app['converter.task'], 'convert')) + ->before($mustBeAdmin)->assert('task', '\d+'); /** * Start task * - * Route : /monitor/task/{task_id}/start/ + * Route : /monitor/task/{task}/start/ * * Method : POST * * Parameters : * */ - $controllers->post('/monitor/task/{task_id}/start/', function(SilexApplication $app, Request $request, $task_id) { - return $app['api']->start_task($app, $task_id)->get_response(); - })->before($mustBeAdmin); + $controllers->post('/monitor/task/{task}/start/', function(SilexApplication $app, Request $request, $task) { + return $app['api']->start_task($app, $task)->get_response(); + }) + ->convert('task', array($app['converter.task'], 'convert')) + ->before($mustBeAdmin); /** * Stop task * - * Route : /monitor/task/{task_id}/stop/ + * Route : /monitor/task/{task}/stop/ * * Method : POST * * Parameters : * */ - $controllers->post('/monitor/task/{task_id}/stop/', function(SilexApplication $app, Request $request, $task_id) { - return $app['api']->stop_task($app, $task_id)->get_response(); - })->before($mustBeAdmin); + $controllers->post('/monitor/task/{task}/stop/', function(SilexApplication $app, Request $request, $task) { + return $app['api']->stop_task($app, $task)->get_response(); + }) + ->convert('task', array($app['converter.task'], 'convert')) + ->before($mustBeAdmin); /** * Get some information about phraseanet diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Tools.php b/lib/Alchemy/Phrasea/Controller/Prod/Tools.php index d65a0d5499..14372aa51a 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Tools.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Tools.php @@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\Controller\Prod; use Alchemy\Phrasea\Controller\RecordsRequest; use Alchemy\Phrasea\Exception\RuntimeException; use DataURI; +use PHPExiftool\Exception\ExceptionInterface as PHPExiftoolException; use Silex\Application; use Silex\ControllerProviderInterface; use Symfony\Component\HttpFoundation\Request; @@ -49,7 +50,7 @@ class Tools implements ControllerProviderInterface $metadatas = $app['exiftool.reader'] ->files($record->get_subdef('document')->get_pathfile()) ->first()->getMetadatas(); - } catch (\PHPExiftool\Exception\Exception $e) { + } catch (PHPExiftoolException $e) { } catch (\Exception_Media_SubdefNotFound $e) { diff --git a/lib/Alchemy/Phrasea/Core/CLIProvider/TaskManagerServiceProvider.php b/lib/Alchemy/Phrasea/Core/CLIProvider/TaskManagerServiceProvider.php index c2a48b4314..975136c558 100644 --- a/lib/Alchemy/Phrasea/Core/CLIProvider/TaskManagerServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/CLIProvider/TaskManagerServiceProvider.php @@ -31,13 +31,18 @@ class TaskManagerServiceProvider implements ServiceProviderInterface }); $app['task-manager'] = $app->share(function(Application $app) { - $options = array( - 'listener_protocol' => 'tcp', - 'listener_host' => '127.0.0.1', - 'listener_port' => 6660, - ); + $options = $app['task-manager.listener.options']; - return TaskManager::create($app['dispatcher'], $app['task-manager.logger'], $app['task-manager.task-list'], $options); + return TaskManager::create( + $app['dispatcher'], + $app['task-manager.logger'], + $app['task-manager.task-list'], + array( + 'listener_protocol' => $options['protocol'], + 'listener_host' => $options['host'], + 'listener_port' => $options['port'], + ) + ); }); $app['task-manager.task-list'] = $app->share(function(Application $app) { diff --git a/lib/Alchemy/Phrasea/Core/Provider/ManipulatorServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/ManipulatorServiceProvider.php index 4526ebaaaf..4e4cbf814b 100644 --- a/lib/Alchemy/Phrasea/Core/Provider/ManipulatorServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/Provider/ManipulatorServiceProvider.php @@ -22,7 +22,7 @@ class ManipulatorServiceProvider implements ServiceProviderInterface public function register(SilexApplication $app) { $app['manipulator.task'] = $app->share(function(SilexApplication $app) { - return new TaskManipulator($app['EM']); + return new TaskManipulator($app['EM'], $app['task-manager.notifier']); }); $app['manipulator.user'] = $app->share(function($app) { diff --git a/lib/Alchemy/Phrasea/Setup/Installer.php b/lib/Alchemy/Phrasea/Setup/Installer.php index 456675ad4e..17a2b29c56 100644 --- a/lib/Alchemy/Phrasea/Setup/Installer.php +++ b/lib/Alchemy/Phrasea/Setup/Installer.php @@ -104,7 +104,7 @@ class Installer $this->app['manipulator.task']->create( $job->getName(), $job->getJobId(), - $job->getEditor()->getDefaultSettings($app['phraseanet.configuration']), + $job->getEditor()->getDefaultSettings($this->app['phraseanet.configuration']), $job->getEditor()->getDefaultPeriod() ); } diff --git a/lib/Alchemy/Phrasea/TaskManager/Job/PhraseanetIndexerJob.php b/lib/Alchemy/Phrasea/TaskManager/Job/PhraseanetIndexerJob.php index 51d39e06d5..92ea811cfc 100644 --- a/lib/Alchemy/Phrasea/TaskManager/Job/PhraseanetIndexerJob.php +++ b/lib/Alchemy/Phrasea/TaskManager/Job/PhraseanetIndexerJob.php @@ -65,7 +65,9 @@ class PhraseanetIndexerJob extends AbstractJob $indexerPath = $this->getPhraseanetIndexerPath($app); $builder = new ProcessBuilder($this->getCommandline($indexerPath, $app, $task)); - $builder->setWorkingDirectory(dirname($indexerPath)); + $builder + ->setWorkingDirectory(dirname($indexerPath)) + ->setTimeout(0); $process = $builder->getProcess(); if (0 < $socketPort) { diff --git a/lib/Alchemy/Phrasea/TaskManager/Job/WriteMetadataJob.php b/lib/Alchemy/Phrasea/TaskManager/Job/WriteMetadataJob.php index 96cdb5a12f..828e494491 100644 --- a/lib/Alchemy/Phrasea/TaskManager/Job/WriteMetadataJob.php +++ b/lib/Alchemy/Phrasea/TaskManager/Job/WriteMetadataJob.php @@ -15,6 +15,7 @@ use Alchemy\Phrasea\TaskManager\Editor\WriteMetadataEditor; use PHPExiftool\Driver\Metadata; use PHPExiftool\Driver\Value; use PHPExiftool\Driver\Tag; +use PHPExiftool\Exception\ExceptionInterface as PHPExiftoolException; use PHPExiftool\Writer; class WriteMetadataJob extends AbstractJob @@ -158,8 +159,8 @@ class WriteMetadataJob extends AbstractJob try { $app['exiftool.writer']->write($file, $metadatas); $this->log('debug', sprintf('meta written for sbasid=%1$d - recordid=%2$d (%3$s)', $databox->get_sbas_id(), $record_id, $name)); - } catch (\PHPExiftool\Exception\Exception $e) { - $this->log('debug', sprintf('meta NOT written for sbasid=%1$d - recordid=%2$d (%3$s) because "%s"', $databox->get_sbas_id(), $record_id, $name, $e->getMessage())); + } catch (PHPExiftoolException $e) { + $this->log('error', sprintf('meta was not written for sbasid=%d - recordid=%d (%s) because "%s"', $databox->get_sbas_id(), $record_id, $name, $e->getMessage())); } } diff --git a/lib/Alchemy/Phrasea/TaskManager/Task.php b/lib/Alchemy/Phrasea/TaskManager/Task.php index aab23731b2..4b68cc6f72 100644 --- a/lib/Alchemy/Phrasea/TaskManager/Task.php +++ b/lib/Alchemy/Phrasea/TaskManager/Task.php @@ -13,7 +13,7 @@ namespace Alchemy\Phrasea\TaskManager; use Entities\Task as TaskEntity; use Alchemy\TaskManager\TaskInterface; -use Symfony\Component\Process\ProcessableInterface; +use Symfony\Component\Process\Process; class Task implements TaskInterface { @@ -22,7 +22,7 @@ class Task implements TaskInterface private $iterations; private $process; - public function __construct(TaskEntity $entity, $name, $iterations, ProcessableInterface $process) + public function __construct(TaskEntity $entity, $name, $iterations, Process $process) { $this->entity = $entity; $this->name = $name; diff --git a/lib/classes/API/V1/adapter.php b/lib/classes/API/V1/adapter.php index b1c176eaf2..ad5e1767aa 100644 --- a/lib/classes/API/V1/adapter.php +++ b/lib/classes/API/V1/adapter.php @@ -23,6 +23,7 @@ use Alchemy\Phrasea\Model\Entities\Feed; use Alchemy\Phrasea\Model\Entities\FeedEntry; use Alchemy\Phrasea\Model\Entities\FeedItem; use Alchemy\Phrasea\Model\Entities\LazaretFile; +use Alchemy\Phrasea\Model\Entities\Task; use Alchemy\Phrasea\Model\Entities\UserQuery; use Alchemy\Phrasea\Model\Entities\ValidationParticipant; use Symfony\Component\HttpFoundation\Request; @@ -115,19 +116,17 @@ class API_V1_adapter extends API_V1_Abstract public function get_scheduler(Application $app) { $result = new \API_V1_result($app, $app['request'], $this); + $date = new \DateTime(); + $data = $app['task-manager.live-information']->getManager(); - $taskManager = $app['task-manager']; - $ret = $taskManager->getSchedulerState(); - - $ret['state'] = $ret['status']; - - unset($ret['qdelay'], $ret['status']); - - if (null !== $ret['updated_on']) { - $ret['updated_on'] = $ret['updated_on']->format(DATE_ATOM); - } - - $result->set_datas(array('scheduler' => $ret)); + $result->set_datas(array('scheduler' => array( + 'configuration' => $data['configuration'], + 'state' => $data['actual'], + 'status' => $data['actual'], + 'pid' => $data['process-id'], + 'process-id' => $data['process-id'], + 'updated_on' => $date->format(DATE_ATOM), + ))); return $result; } @@ -143,12 +142,9 @@ class API_V1_adapter extends API_V1_Abstract { $result = new \API_V1_result($app, $app['request'], $this); - $taskManager = $app['task-manager']; - $tasks = $taskManager->getTasks(); - $ret = array(); - foreach ($tasks as $task) { - $ret[] = $this->list_task($task); + foreach ($app['manipulator.task']->getRepository()->findAll() as $task) { + $ret[] = $this->list_task($app, $task); } $result->set_datas(array('tasks' => $ret)); @@ -156,18 +152,28 @@ class API_V1_adapter extends API_V1_Abstract return $result; } - protected function list_task(\task_abstract $task) + protected function list_task(Application $app, Task $task) { + $data = $app['task-manager.live-information']->getTask($task); + return array( - 'id' => $task->getID(), + 'id' => $task->getId(), + 'title' => $task->getName(), 'name' => $task->getName(), - 'state' => $task->getState(), - 'pid' => $task->getPID(), - 'title' => $task->getTitle(), - 'last_exec_time' => $task->getLastExecTime() ? $task->getLastExecTime()->format(DATE_ATOM) : null, - 'auto_start' => !!$task->isActive(), - 'runner' => $task->getRunner(), - 'crash_counter' => $task->getCrashCounter() + 'state' => $task->getStatus(), + 'status' => $task->getStatus(), + 'actual-status' => $data['actual'], + 'process-id' => $data['process-id'], + 'pid' => $data['process-id'], + 'jobId' => $task->getJobId(), + 'period' => $task->getPeriod(), + 'last_exec_time' => $task->getLastExecution() ? $task->getLastExecution()->format(DATE_ATOM) : null, + 'last_execution' => $task->getLastExecution() ? $task->getLastExecution()->format(DATE_ATOM) : null, + 'updated' => $task->getUpdated() ? $task->getUpdated()->format(DATE_ATOM) : null, + 'created' => $task->getCreated() ? $task->getCreated()->format(DATE_ATOM) : null, + 'auto_start' => $task->getStatus() === Task::STATUS_STARTED, + 'crashed' => $task->getCrashed(), + 'status' => $task->getStatus(), ); } @@ -175,19 +181,13 @@ class API_V1_adapter extends API_V1_Abstract * Get informations about an identified task * * @param \Silex\Application $app The API silex application - * @param integer $taskId + * @param Task $task * @return \API_V1_result */ - public function get_task(Application $app, $taskId) + public function get_task(Application $app, Task $task) { $result = new \API_V1_result($app, $app['request'], $this); - - $taskManager = $app['task-manager']; - - $ret = array( - 'task' => $this->list_task($taskManager->getTask($taskId)) - ); - + $ret = array('task' => $this->list_task($app, $task)); $result->set_datas($ret); return $result; @@ -197,21 +197,15 @@ class API_V1_adapter extends API_V1_Abstract * Start a specified task * * @param \Silex\Application $app The API silex application - * @param integer $taskId The task id + * @param Task $task The task to start * @return \API_V1_result */ - public function start_task(Application $app, $taskId) + public function start_task(Application $app, Task $task) { $result = new \API_V1_result($app, $app['request'], $this); - $taskManager = $app['task-manager']; - - $task = $taskManager->getTask($taskId); - if (!in_array($task->getState(), array(\task_abstract::STATE_TOSTART, \task_abstract::STATE_STARTED))) { - $task->setState(\task_abstract::STATE_TOSTART); - } - - $result->set_datas(array('task' => $this->list_task($task))); + $app['manipulator.task']->start($task); + $result->set_datas(array('task' => $this->list_task($app, $task))); return $result; } @@ -220,20 +214,15 @@ class API_V1_adapter extends API_V1_Abstract * Stop a specified task * * @param \Silex\Application $app The API silex application - * @param integer $taskId The task id + * @param Task $task The task to stop * @return \API_V1_result */ - public function stop_task(Application $app, $taskId) + public function stop_task(Application $app, Task $task) { $result = new API_V1_result($app, $app['request'], $this); - $taskManager = $app['task-manager']; - - $task = $taskManager->getTask($taskId); - if (!in_array($task->getState(), array(\task_abstract::STATE_TOSTOP, \task_abstract::STATE_STOPPED))) { - $task->setState(\task_abstract::STATE_TOSTOP); - } - $result->set_datas(array('task' => $this->list_task($task))); + $app['manipulator.task']->stop($task); + $result->set_datas(array('task' => $this->list_task($app, $task))); return $result; } @@ -244,11 +233,11 @@ class API_V1_adapter extends API_V1_Abstract * - autostart * * @param \Silex\Application $app Silex application - * @param integer $taskId the task id + * @param Task $task The task * @return \API_V1_result * @throws \API_V1_exception_badrequest */ - public function set_task_property(Application $app, $taskId) + public function set_task_property(Application $app, $task) { $result = new API_V1_result($app, $app['request'], $this); @@ -259,19 +248,14 @@ class API_V1_adapter extends API_V1_Abstract throw new \API_V1_exception_badrequest(); } - $taskManager = $app['task-manager']; - - $task = $taskManager->getTask($taskId); - if ($title) { - $task->setTitle($title); + $task->setName($title); } - if ($autostart) { - $task->setActive(!!$autostart); + $task->setStatus(Task::STATUS_STARTED); } - $result->set_datas(array('task' => $this->list_task($task))); + $result->set_datas(array('task' => $this->list_task($app, $task))); return $result; } diff --git a/lib/classes/patch/370a8.php b/lib/classes/patch/370a8.php index 01efe1bcc3..782f18cd69 100644 --- a/lib/classes/patch/370a8.php +++ b/lib/classes/patch/370a8.php @@ -11,6 +11,8 @@ use Alchemy\Phrasea\Application; +use Entities\Task; + /** * * @license http://opensource.org/licenses/gpl-3.0 GPLv3 @@ -66,7 +68,7 @@ class patch_370a8 implements patchInterface { $ttasks = array(); $conn = $appbox->get_connection(); - $sql = 'SELECT task_id, active, name, class, settings FROM task2 WHERE class=\'task_period_workflow01\' OR class=\'task_period_ftv\''; + $sql = 'SELECT task_id, active, name, class, settings FROM task2 WHERE class=\'task_period_workflow01\''; if (($stmt = $conn->prepare($sql)) !== FALSE) { $stmt->execute(); $ttasks = $stmt->fetchAll(); @@ -80,7 +82,7 @@ class patch_370a8 implements patchInterface $warning = array(); /* - * migrating task 'workflow01' or 'task_period_ftv' + * migrating task 'workflow01' */ $x = $task['settings']; if (false !== $sx = simplexml_load_string($x)) { @@ -193,58 +195,6 @@ class patch_370a8 implements patchInterface $taskstodel[] = $task['task_id']; } - - /* - * migrating task 'task_period_ftv' - */ - if ($task['class'] === 'task_period_ftv') { - foreach ($sx->tasks->task as $sxt) { - $active = true; - $warning = array(); - - $t = $dom->importNode(dom_import_simplexml($sxt), true); - $t->setAttribute('active', '0'); -// $t->setAttribute('name', 'imported from \'' . $task->getTitle() . '\''); - $t->setAttribute('name', 'imported from \'' . $task['name'] . '\''); - $t->setAttribute('action', 'update'); - - if ($sx->sbas_id) { - $sbas_id = trim($sx->sbas_id); - if ($sbas_id != '' && is_numeric($sbas_id)) { - $t->setAttribute('sbas_id', $sx->sbas_id); - } else { - $warning[] = sprintf("Bad sbas_id '%s'", $sbas_id); - $active = false; - } - } else { - $warning[] = sprintf("missing sbas_id"); - $active = false; - } - - if ($active && $task['active'] == '1') { - $t->setAttribute('active', '1'); - } - foreach ($warning as $w) { - $t->appendChild($dom->createComment($w)); - } - - $x = new DOMXPath($dom); - $nlfrom = $x->query('from', $t); - if ($nlfrom->length == 1) { - $nlcoll = $x->query('colls', $nlfrom->item(0)); - if ($nlcoll->length > 0) { - $nn = $dom->createElement('coll'); - $nn->setAttribute('compare', '='); - $nn->setAttribute('id', $nlcoll->item(0)->getAttribute('id')); - $nlfrom->item(0)->replaceChild($nn, $nlcoll->item(0)); - } - - $tasks->appendChild($t); - } - } - - $taskstodel[] = $task['task_id']; - } } if (count($taskstodel) > 0) { @@ -256,8 +206,20 @@ class patch_370a8 implements patchInterface * save new tasks */ foreach ($tdom as $newtask) { - $task = task_abstract::create($app, 'task_period_RecordMover', $newtask['dom']->saveXML()); + $settings = $newtask['dom']->saveXML(); + $sxml = simplexml_load_string($settings); + $period = $sxml->period ? (int) $sxml->period : 300; + + $task = new Task(); + $task + ->setName('Record mover') + ->setJobId('RecordMover') + ->setSettings($settings) + ->setPeriod($period) + ->setStatus(Task::STATUS_STARTED); + $app['EM']->persist($task); } + $app['EM']->flush(); return true; } diff --git a/lib/classes/record/adapter.php b/lib/classes/record/adapter.php index bf868b1831..13b09bf591 100644 --- a/lib/classes/record/adapter.php +++ b/lib/classes/record/adapter.php @@ -1607,9 +1607,10 @@ class record_adapter implements record_Interface, cache_cacheableInterface public function generate_subdefs(databox $databox, Application $app, Array $wanted_subdefs = null) { $subdefs = $databox->get_subdef_structure()->getSubdefGroup($this->get_type()); + $logger = isset($app['task-manager.logger']) ? $app['task-manager.logger'] : $app['monolog']; if (!$subdefs) { - $app['task-manager.logger']->addInfo(sprintf('Nothing to do for %s', $this->get_type())); + $logger->addInfo(sprintf('Nothing to do for %s', $this->get_type())); return; } @@ -1626,14 +1627,14 @@ class record_adapter implements record_Interface, cache_cacheableInterface if ($this->has_subdef($subdefname) && $this->get_subdef($subdefname)->is_physically_present()) { $pathdest = $this->get_subdef($subdefname)->get_pathfile(); $this->get_subdef($subdefname)->remove_file(); - $app['task-manager.logger']->addInfo(sprintf('Removed old file for %s', $subdefname)); + $logger->addInfo(sprintf('Removed old file for %s', $subdefname)); $this->clearSubdefCache($subdefname); } $pathdest = $this->generateSubdefPathname($subdef, $app['filesystem'], $pathdest); - $app['task-manager.logger']->addInfo(sprintf('Generating subdef %s to %s', $subdefname, $pathdest)); - $this->generate_subdef($app['media-alchemyst'], $subdef, $pathdest, $app['task-manager.logger']); + $logger->addInfo(sprintf('Generating subdef %s to %s', $subdefname, $pathdest)); + $this->generate_subdef($app['media-alchemyst'], $subdef, $pathdest, $logger); if (file_exists($pathdest)) { $media = $app['mediavorus']->guess($pathdest); diff --git a/lib/conf.d/configuration.yml b/lib/conf.d/configuration.yml index fb11c52e63..00d5c46c82 100644 --- a/lib/conf.d/configuration.yml +++ b/lib/conf.d/configuration.yml @@ -136,4 +136,8 @@ xsendfile: mapping: [] task-manager: status: started + listener: + protocol: tcp + host: 127.0.0.1 + port: 6700 plugins: [] diff --git a/tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php b/tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php index d4a29e12a4..93e4455f76 100644 --- a/tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php +++ b/tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php @@ -6,6 +6,7 @@ use Alchemy\Phrasea\Border\File; use Alchemy\Phrasea\Border\Manager; use Alchemy\Phrasea\Core\PhraseaEvents; use Alchemy\Phrasea\Authentication\Context; +use Entities\Task; use Symfony\Component\HttpKernel\Client; use Symfony\Component\HttpFoundation\Response; @@ -289,7 +290,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract $this->evaluateMeta200($content); $response = $content['response']; - $tasks = self::$DI['app']['task-manager']->getTasks(); + $tasks = self::$DI['app']['manipulator.task']->getRepository()->findAll(); $this->assertEquals(count($tasks), count($response['tasks'])); foreach ($response['tasks'] as $task) { @@ -323,8 +324,11 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract $this->assertArrayHasKey('state', $response['scheduler']); $this->assertArrayHasKey('pid', $response['scheduler']); $this->assertArrayHasKey('updated_on', $response['scheduler']); + $this->assertArrayHasKey('status', $response['scheduler']); + $this->assertArrayHasKey('configuration', $response['scheduler']); + $this->assertArrayHasKey('process-id', $response['scheduler']); - $this->assertEquals(3, count($response['scheduler'])); + $this->assertEquals(6, count($response['scheduler'])); if (null !== $response['scheduler']['updated_on']) { $this->assertDateAtom($response['scheduler']['updated_on']); @@ -341,9 +345,19 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract $this->assertArrayHasKey('id', $task); $this->assertArrayHasKey('name', $task); $this->assertArrayHasKey('state', $task); + $this->assertArrayHasKey('status', $task); + $this->assertArrayHasKey('actual-status', $task); $this->assertArrayHasKey('pid', $task); + $this->assertArrayHasKey('process-id', $task); $this->assertArrayHasKey('title', $task); + $this->assertArrayHasKey('crashed', $task); + $this->assertArrayHasKey('auto_start', $task); $this->assertArrayHasKey('last_exec_time', $task); + $this->assertArrayHasKey('last_execution', $task); + $this->assertArrayHasKey('updated', $task); + $this->assertArrayHasKey('created', $task); + $this->assertArrayHasKey('period', $task); + $this->assertArrayHasKey('jobId', $task); $this->assertInternalType('integer', $task['id']); @@ -352,13 +366,8 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract } $av_states = array( - \task_abstract::STATE_STARTED, - \task_abstract::STATE_STOPPED, - \task_abstract::STATE_OK, - \task_abstract::STATE_TODELETE, - \task_abstract::STATE_TORESTART, - \task_abstract::STATE_TOSTOP, - \task_abstract::STATE_TOSTART, + Task::STATUS_STARTED, + Task::STATUS_STOPPED, ); $this->assertContains($task['state'], $av_states); @@ -377,7 +386,8 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract */ public function testGetMonitorTaskById() { - $tasks = self::$DI['app']['task-manager']->getTasks(); + $this->insertTwoTasks(); + $tasks = self::$DI['app']['manipulator.task']->getRepository()->findAll(); if (null === self::$adminToken) { $this->markTestSkipped('there is no user with admin rights'); @@ -388,8 +398,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract } $this->setToken(self::$adminToken); - reset($tasks); - $idTask = key($tasks); + $idTask = $tasks[0]->getId(); $route = '/api/v1/monitor/task/' . $idTask . '/'; $this->evaluateMethodNotAllowedRoute($route, array('PUT', 'DELETE')); @@ -409,7 +418,8 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract */ public function testPostMonitorTaskById() { - $tasks = self::$DI['app']['task-manager']->getTasks(); + $this->insertTwoTasks(); + $tasks = self::$DI['app']['manipulator.task']->getRepository()->findAll(); if (null === self::$adminToken) { $this->markTestSkipped('there is no user with admin rights'); @@ -420,8 +430,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract } $this->setToken(self::$adminToken); - reset($tasks); - $idTask = key($tasks); + $idTask = $tasks[0]->getId(); $route = '/api/v1/monitor/task/' . $idTask . '/'; $this->evaluateMethodNotAllowedRoute($route, array('PUT', 'DELETE')); @@ -464,15 +473,15 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract $this->markTestSkipped('there is no user with admin rights'); } - $tasks = self::$DI['app']['task-manager']->getTasks(); + $this->insertTwoTasks(); + $tasks = self::$DI['app']['manipulator.task']->getRepository()->findAll(); if (!count($tasks)) { $this->markTestSkipped('no tasks created for the current instance'); } $this->setToken(self::$adminToken); - reset($tasks); - $idTask = key($tasks); + $idTask = $tasks[0]->getId(); $route = '/api/v1/monitor/task/' . $idTask . '/start/'; $this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE')); @@ -485,8 +494,8 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract $this->assertArrayHasKey('task', $content['response']); $this->evaluateGoodTask($content['response']['task']); - $task = self::$DI['app']['task-manager']->getTask($idTask); - $this->assertContains($task->getState(), array(\task_abstract::STATE_TOSTART, \task_abstract::STATE_STARTED)); + $task = self::$DI['app']['manipulator.task']->getRepository()->find($idTask); + $this->assertEquals(Task::STATUS_STARTED, $task->getStatus()); } /** @@ -495,7 +504,8 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract */ public function testPostMonitorStopTask() { - $tasks = self::$DI['app']['task-manager']->getTasks(); + $this->insertTwoTasks(); + $tasks = self::$DI['app']['manipulator.task']->getRepository()->findAll(); if (null === self::$adminToken) { $this->markTestSkipped('there is no user with admin rights'); @@ -506,8 +516,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract } $this->setToken(self::$adminToken); - reset($tasks); - $idTask = key($tasks); + $idTask = $tasks[0]->getId(); $route = '/api/v1/monitor/task/' . $idTask . '/stop/'; $this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE')); @@ -520,8 +529,8 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract $this->assertArrayHasKey('task', $content['response']); $this->evaluateGoodTask($content['response']['task']); - $task = self::$DI['app']['task-manager']->getTask($idTask); - $this->assertContains($task->getState(), array(\task_abstract::STATE_TOSTOP, \task_abstract::STATE_STOPPED)); + $task = self::$DI['app']['manipulator.task']->getRepository()->find($idTask); + $this->assertEquals(Task::STATUS_STOPPED, $task->getStatus()); } /** diff --git a/tests/Alchemy/Tests/Phrasea/Command/Setup/CheckEnvironmentTest.php b/tests/Alchemy/Tests/Phrasea/Command/Setup/CheckEnvironmentTest.php index cb4fcdc8dc..d2dfc1e8f8 100644 --- a/tests/Alchemy/Tests/Phrasea/Command/Setup/CheckEnvironmentTest.php +++ b/tests/Alchemy/Tests/Phrasea/Command/Setup/CheckEnvironmentTest.php @@ -12,6 +12,7 @@ class CheckEnvironmentTest extends \PhraseanetPHPUnitAbstract $output = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); $command = new CheckEnvironment('system:check'); + $command->setContainer(self::$DI['cli']); $this->assertLessThan(2, $command->execute($input, $output)); } } diff --git a/tests/Alchemy/Tests/Phrasea/Core/Provider/ManipulatorServiceProviderTest.php b/tests/Alchemy/Tests/Phrasea/Core/Provider/ManipulatorServiceProviderTest.php index 51d0b7c5c6..dc3e2c37e6 100644 --- a/tests/Alchemy/Tests/Phrasea/Core/Provider/ManipulatorServiceProviderTest.php +++ b/tests/Alchemy/Tests/Phrasea/Core/Provider/ManipulatorServiceProviderTest.php @@ -2,13 +2,11 @@ namespace Alchemy\Tests\Phrasea\Core\Provider; -class ManipulatorServiceProviderTest extends ServiceProviderTestCase +class ManipulatorServiceProvidertest extends ServiceProviderTestCase { public function provideServiceDescription() { return array( - array('Alchemy\Phrasea\Core\Provider\ManipulatorServiceProvider', 'manipulator.user', '\Alchemy\Phrasea\Model\Manipulator\UserManipulator'), - array('Alchemy\Phrasea\Core\Provider\ManipulatorServiceProvider', 'model.user-manager', '\Alchemy\Phrasea\Model\Manager\UserManager'), array( 'Alchemy\Phrasea\Core\Provider\ManipulatorServiceProvider', 'manipulator.task', diff --git a/tests/Alchemy/Tests/Phrasea/TaskManager/TaskTest.php b/tests/Alchemy/Tests/Phrasea/TaskManager/TaskTest.php index ed7643daa5..00f4adb98c 100644 --- a/tests/Alchemy/Tests/Phrasea/TaskManager/TaskTest.php +++ b/tests/Alchemy/Tests/Phrasea/TaskManager/TaskTest.php @@ -9,7 +9,9 @@ class TaskTest extends TaskTestCase { public function testThatCreatedProcessAreDifferents() { - $process = $this->getMock('Symfony\Component\Process\ProcessableInterface'); + $process = $this->getMockBuilder('Symfony\Component\Process\Process') + ->disableOriginalConstructor() + ->getMock(); $taskEntity = $this->getMock('Entities\Task'); $task = new Task($taskEntity, 'task number', 42, $process); @@ -27,7 +29,9 @@ class TaskTest extends TaskTestCase protected function getTask() { - $process = $this->getMock('Symfony\Component\Process\ProcessableInterface'); + $process = $this->getMockBuilder('Symfony\Component\Process\Process') + ->disableOriginalConstructor() + ->getMock(); $taskEntity = $this->getMock('Entities\Task'); return new Task($taskEntity, 'task number', 42, $process); diff --git a/tests/classes/PhraseanetPHPUnitAbstract.php b/tests/classes/PhraseanetPHPUnitAbstract.php index 187903586f..80ccb063f1 100644 --- a/tests/classes/PhraseanetPHPUnitAbstract.php +++ b/tests/classes/PhraseanetPHPUnitAbstract.php @@ -10,6 +10,7 @@ use Alchemy\Phrasea\Model\Entities\FeedEntry; use Alchemy\Phrasea\Model\Entities\FeedItem; use Alchemy\Phrasea\Model\Entities\FeedPublisher; use Alchemy\Phrasea\Model\Entities\FeedToken; +use Alchemy\Phrasea\Model\Entities\Task; use Alchemy\Phrasea\Model\Entities\User; use Silex\WebTestCase; use Symfony\Component\HttpFoundation\Response; @@ -264,6 +265,23 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase $this->assertTrue(false !== stripos($response->getContent(), 'Sorry, the page you are looking for could not be found')); } + public function insertTwoTasks() + { + $task1 = new Task(); + $task1 + ->setName('task 1') + ->setJobId('Null'); + + $task2 = new Task(); + $task2 + ->setName('task 2') + ->setJobId('Null'); + + self::$DI['app']['EM']->persist($task1); + self::$DI['app']['EM']->persist($task2); + self::$DI['app']['EM']->flush(); + } + /** * Insert fixture contained in the specified fixtureLoader * into sqlLite test temporary database