run('/Create ' . $task->__toString()); } /** * {@inheritdoc} */ public function update(TaskAbstract $task) : void { $this->run('/Change ' . $task->__toString()); } /** * {@inheritdoc} */ public function deleteByName(string $name) : void { $this->run('/Delete /TN ' . $name); } /** * {@inheritdoc} */ public function delete(TaskAbstract $task) : void { $this->deleteByName($task->getId()); } /** * {@inheritdoc} */ public function getAll() : array { $lines = \explode("\n", $this->normalize($this->run('/query /v /fo CSV'))); unset($lines[0]); $jobs = []; foreach ($lines as $line) { $jobs[] = Schedule::createWith(\str_getcsv($line)); } return $jobs; } /** * {@inheritdoc} */ public function getAllByName(string $name, bool $exact = true) : array { if ($exact) { $lines = \explode("\n", $this->normalize($this->run('/query /v /fo CSV /tn ' . \escapeshellarg($name)))); unset($lines[0]); $jobs = []; foreach ($lines as $line) { $jobs[] = Schedule::createWith(\str_getcsv($line)); } } else { $lines = \explode("\n", $this->normalize($this->run('/query /v /fo CSV'))); unset($lines[0]); $jobs = []; foreach ($lines as $key => $line) { $line = \str_getcsv($line); if (\stripos($line[1], $name) !== false) { $jobs[] = Schedule::createWith($line); } } } return $jobs; } }