3
* Spring Signage Ltd - http://www.springsignage.com
4
* Copyright (C) 2016 Spring Signage Ltd
9
namespace Xibo\Factory;
11
use Xibo\Exception\NotFoundException;
12
use Xibo\Service\LogServiceInterface;
13
use Xibo\Service\SanitizerServiceInterface;
14
use Xibo\Storage\StorageServiceInterface;
18
* @package Xibo\Factory
20
class TaskFactory extends BaseFactory
24
* @param StorageServiceInterface $store
25
* @param LogServiceInterface $log
26
* @param SanitizerServiceInterface $sanitizerService
28
public function __construct($store, $log, $sanitizerService)
30
$this->setCommonDependencies($store, $log, $sanitizerService);
37
public function create()
39
return new Task($this->getStore(), $this->getLog());
46
* @throws NotFoundException if the task cannot be resolved from the provided route
48
public function getById($taskId)
50
$tasks = $this->query(null, array('taskId' => $taskId));
52
if (count($tasks) <= 0)
53
throw new NotFoundException();
62
* @throws NotFoundException if the task cannot be resolved from the provided route
64
public function getByName($task)
66
$tasks = $this->query(null, array('name' => $task));
68
if (count($tasks) <= 0)
69
throw new NotFoundException();
76
* @param string $class
78
* @throws NotFoundException if the task cannot be resolved from the provided route
80
public function getByClass($class)
82
$tasks = $this->query(null, array('class' => $class));
84
if (count($tasks) <= 0)
85
throw new NotFoundException();
91
* @param null $sortOrder
92
* @param array $filterBy
95
public function query($sortOrder = null, $filterBy = [])
97
if ($sortOrder == null)
98
$sortOrder = ['name'];
103
SELECT `taskId`, `name`, `status`, `pid`, `configFile`, `class`, `options`, `schedule`,
104
`lastRunDt`, `lastRunStatus`, `lastRunMessage`, `lastRunDuration`, `lastRunExitCode`,
108
if (DBVERSION >= 133)
109
$sql .= ', `lastRunStartDt` ';
116
if ($this->getSanitizer()->getString('name', $filterBy) != null) {
117
$params['name'] = $this->getSanitizer()->getString('name', $filterBy);
118
$sql .= ' AND `name` = :name ';
121
if ($this->getSanitizer()->getString('class', $filterBy) != null) {
122
$params['class'] = $this->getSanitizer()->getString('class', $filterBy);
123
$sql .= ' AND `class` = :class ';
126
if ($this->getSanitizer()->getInt('taskId', $filterBy) !== null) {
127
$params['taskId'] = $this->getSanitizer()->getString('taskId', $filterBy);
128
$sql .= ' AND `taskId` = :taskId ';
132
$sql .= 'ORDER BY ' . implode(',', $sortOrder);
135
foreach ($this->getStore()->select($sql, $params) as $row) {
136
$task = $this->create()->hydrate($row, [
138
'status', 'lastRunStatus', 'nextRunDt', 'lastRunDt', 'lastRunStartDt', 'lastRunExitCode', 'runNow', 'isActive', 'pid'
142
if ($task->options != null)
143
$task->options = json_decode($task->options, true);
b'\\ No newline at end of file'