Update unit tests and legacy

This commit is contained in:
Romain Neutron
2013-10-01 17:54:30 +02:00
parent d561436815
commit 58c402ac2b
19 changed files with 188 additions and 184 deletions

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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);