Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
TaskScheduler | n/a |
0 / 0 |
n/a |
0 / 0 |
12 | n/a |
0 / 0 |
|||
create | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
update | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
deleteByName | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
delete | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
getAll | n/a |
0 / 0 |
n/a |
0 / 0 |
2 | |||||
getAllByName | n/a |
0 / 0 |
n/a |
0 / 0 |
5 | |||||
reload | n/a |
0 / 0 |
n/a |
0 / 0 |
1 |
1 | <?php |
2 | /** |
3 | * Jingga |
4 | * |
5 | * PHP Version 8.1 |
6 | * |
7 | * @package phpOMS\Utils\TaskSchedule |
8 | * @copyright Dennis Eichhorn |
9 | * @license OMS License 2.0 |
10 | * @version 1.0.0 |
11 | * @link https://jingga.app |
12 | */ |
13 | declare(strict_types=1); |
14 | |
15 | namespace phpOMS\Utils\TaskSchedule; |
16 | |
17 | /** |
18 | * Task scheduler class. |
19 | * |
20 | * @package phpOMS\Utils\TaskSchedule |
21 | * @license OMS License 2.0 |
22 | * @link https://jingga.app |
23 | * @since 1.0.0 |
24 | * @codeCoverageIgnore |
25 | */ |
26 | class TaskScheduler extends SchedulerAbstract |
27 | { |
28 | /** |
29 | * {@inheritdoc} |
30 | */ |
31 | public function create(TaskAbstract $task) : void |
32 | { |
33 | $this->run('/Create ' . $task->__toString()); |
34 | } |
35 | |
36 | /** |
37 | * {@inheritdoc} |
38 | */ |
39 | public function update(TaskAbstract $task) : void |
40 | { |
41 | $this->run('/Change ' . $task->__toString()); |
42 | } |
43 | |
44 | /** |
45 | * {@inheritdoc} |
46 | */ |
47 | public function deleteByName(string $name) : void |
48 | { |
49 | $this->run('/Delete /TN ' . $name); |
50 | } |
51 | |
52 | /** |
53 | * {@inheritdoc} |
54 | */ |
55 | public function delete(TaskAbstract $task) : void |
56 | { |
57 | $this->deleteByName($task->getId()); |
58 | } |
59 | |
60 | /** |
61 | * {@inheritdoc} |
62 | */ |
63 | public function getAll() : array |
64 | { |
65 | $lines = \explode("\n", $this->normalize($this->run('/query /v /fo CSV'))); |
66 | unset($lines[0]); |
67 | |
68 | $jobs = []; |
69 | foreach ($lines as $line) { |
70 | $jobs[] = Schedule::createWith(\str_getcsv($line)); |
71 | } |
72 | |
73 | return $jobs; |
74 | } |
75 | |
76 | /** |
77 | * {@inheritdoc} |
78 | */ |
79 | public function getAllByName(string $name, bool $exact = true) : array |
80 | { |
81 | if ($exact) { |
82 | $lines = \explode("\n", $this->normalize($this->run('/query /v /fo CSV /tn ' . \escapeshellarg($name)))); |
83 | unset($lines[0]); |
84 | |
85 | $jobs = []; |
86 | foreach ($lines as $line) { |
87 | $jobs[] = Schedule::createWith(\str_getcsv($line)); |
88 | } |
89 | } else { |
90 | $lines = \explode("\n", $this->normalize($this->run('/query /v /fo CSV'))); |
91 | unset($lines[0]); |
92 | |
93 | $jobs = []; |
94 | foreach ($lines as $line) { |
95 | $line = \str_getcsv($line); |
96 | |
97 | if (\stripos($line[1] ?? '', $name) !== false) { |
98 | $jobs[] = Schedule::createWith($line); |
99 | } |
100 | } |
101 | } |
102 | |
103 | return $jobs; |
104 | } |
105 | |
106 | /** |
107 | * {@inheritdoc} |
108 | */ |
109 | public function reload() : void |
110 | { |
111 | } |
112 | } |