public function getTaskList() { $task3 = new Task(); $task3->setName('task 3')->setStatus(Task::STATUS_STOPPED)->setJobId('Alchemy\\Phrasea\\TaskManager\\Job\\NullJob'); self::$DI['app']['orm.em']->persist($task3); self::$DI['app']['orm.em']->flush(); return new TaskList(self::$DI['app']['orm.em']->getRepository('Phraseanet:Task'), self::$DI['app']['root.path'], '/path/to/php', '/path/to/php-conf'); }
/** * Creates a EmptyCollection task given a collection * * @param \collection $collection * * @return Task */ public function createEmptyCollectionJob(\collection $collection) { $job = new EmptyCollectionJob($this->translator); $settings = simplexml_load_string($job->getEditor()->getDefaultSettings()); $settings->bas_id = $collection->get_base_id(); $task = new Task(); $task->setName($job->getName())->setJobId($job->getJobId())->setSettings($settings->asXML())->setPeriod($job->getEditor()->getDefaultPeriod()); $this->om->persist($task); $this->om->flush(); $this->notify(NotifierInterface::MESSAGE_CREATE); return $task; }
private function insertTwoTasks(EntityManager $em) { $task1 = new Task(); $task1->setName('task 1')->setJobId('Null'); $task2 = new Task(); $task2->setName('task 2')->setJobId('Null'); $em->persist($task1); $em->persist($task2); }
/** * {@inheritDoc} */ public function setName($name) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setName', array($name)); return parent::setName($name); }
/** * transform tasks 'workflow 01' to 'RecordMover' * will group tasks(01) with same period to a single task(02) * * @param base $appbox * @param Application $app * * @return boolean */ public function apply(base $appbox, Application $app) { $ttasks = []; $conn = $appbox->get_connection(); $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(); } $stmt->closeCursor(); $tdom = []; // key = period $taskstodel = []; foreach ($ttasks as $task) { $active = true; $warning = []; /* * migrating task 'workflow01' */ $x = $task['settings']; if (false !== ($sx = simplexml_load_string($x))) { $period = (int) $sx->period; if (!array_key_exists('_' . $period, $tdom)) { $dom = new DOMDocument('1.0', 'UTF-8'); $dom->formatOutput = true; $dom->preserveWhiteSpace = false; $ts = $dom->appendChild($dom->createElement('tasksettings')); $ts->appendChild($dom->createElement('period'))->appendChild($dom->createTextNode(60 * $period)); $ts->appendChild($dom->createElement('logsql'))->appendChild($dom->createTextNode('1')); $tasks = $ts->appendChild($dom->createElement('tasks')); $tdom['_' . $period] = ['dom' => $dom, 'tasks' => $tasks]; } else { $dom =& $tdom['_' . $period]['dom']; $tasks =& $tdom['_' . $period]['tasks']; } /* * migrating task 'workflow01' */ if ($task['class'] === 'task_period_workflow01') { $t = $tasks->appendChild($dom->createElement('task')); $t->setAttribute('active', '0'); $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; } // 'from' section $from = $t->appendChild($dom->createElement('from')); if ($sx->coll0) { if (($coll0 = trim($sx->coll0)) != '') { if (is_numeric($coll0)) { $n = $from->appendChild($dom->createElement('coll')); $n->setAttribute('compare', '='); $n->setAttribute('id', $coll0); } else { $warning[] = sprintf("Bad (from) coll_id '%s'", $coll0); $active = false; } } } if ($sx->status0 && trim($sx->status0) != '') { $st = explode('_', trim($sx->status0)); if (count($st) == 2) { $bit = (int) $st[0]; if ($bit >= 0 && $bit < 32 && ($st[1] == '0' || $st[1] == '1')) { $from->appendChild($dom->createElement('status'))->setAttribute('mask', $st[1] . str_repeat('x', $bit - 1)); } else { $warning[] = sprintf("Bad (from) status '%s'", trim($sx->status0)); $active = false; } } else { $warning[] = sprintf("Bad (from) status '%s'", trim($sx->status0)); $active = false; } } // 'to' section $to = $t->appendChild($dom->createElement('to')); if ($sx->coll1) { if (($coll1 = trim($sx->coll1)) != '') { if (is_numeric($coll1)) { $n = $to->appendChild($dom->createElement('coll')); $n->setAttribute('id', $coll1); } else { $warning[] = sprintf("Bad (to) coll_id '%s'", $coll1); $active = false; } } } if ($sx->status1 && trim($sx->status1) != '') { $st = explode('_', trim($sx->status1)); if (count($st) == 2) { $bit = (int) $st[0]; if ($bit >= 0 && $bit < 32 && ($st[1] == '0' || $st[1] == '1')) { $to->appendChild($dom->createElement('status'))->setAttribute('mask', $st[1] . str_repeat('x', $bit - 1)); } else { $warning[] = sprintf("Bad (to) status '%s'", trim($sx->status1)); $active = false; } } else { $warning[] = sprintf("Bad (to) status '%s'", trim($sx->status1)); $active = false; } } if ($active && $task['active'] == '1') { $t->setAttribute('active', '1'); } foreach ($warning as $w) { $t->appendChild($dom->createComment($w)); } $taskstodel[] = $task['task_id']; } } if (count($taskstodel) > 0) { $conn->exec('DELETE FROM task2 WHERE task_id IN(' . implode(',', $taskstodel) . ')'); } } /* * save new tasks */ foreach ($tdom as $newtask) { $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['orm.em']->persist($task); } $app['orm.em']->flush(); return true; }
/** * Update a task property * - name * - autostart * * @param \Silex\Application $app Silex application * @param Task $task The task * * @return Response */ public function set_task_property(Application $app, Request $request, $task) { $title = $app['request']->get('title'); $autostart = $app['request']->get('autostart'); if (null === $title && null === $autostart) { return $this->getBadRequest($app, $request); } if ($title) { $task->setName($title); } if ($autostart) { $task->setStatus(Task::STATUS_STARTED); } return Result::create($request, ['task' => $this->list_task($app, $task)])->createResponse(); }
public function setTaskPropertyAction(Request $request, Task $task) { $title = $request->get('title'); $autostart = $request->get('autostart'); if (null === $title && null === $autostart) { return $this->getBadRequestAction($request); } if ($title) { $task->setName($title); } if ($autostart) { $task->setStatus(Task::STATUS_STARTED); } return $this->showTaskAction($request, $task); }
/** * Update a task property * - name * - autostart * * @param \Silex\Application $app Silex application * @param Task $task The task * @return \API_V1_result * @throws \API_V1_exception_badrequest */ public function set_task_property(Application $app, $task) { $result = new API_V1_result($app, $app['request'], $this); $title = $app['request']->get('title'); $autostart = $app['request']->get('autostart'); if (null === $title && null === $autostart) { throw new \API_V1_exception_badrequest(); } if ($title) { $task->setName($title); } if ($autostart) { $task->setStatus(Task::STATUS_STARTED); } $result->set_datas(['task' => $this->list_task($app, $task)]); return $result; }