mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-12 10:18:39 +00:00
88 lines
2.0 KiB
PHP
88 lines
2.0 KiB
PHP
<?php
|
|
/**
|
|
* Orange Management
|
|
*
|
|
* PHP Version 7.2
|
|
*
|
|
* @package TBD
|
|
* @copyright Dennis Eichhorn
|
|
* @license OMS License 1.0
|
|
* @version 1.0.0
|
|
* @link http://website.orange-management.de
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
namespace phpOMS\Utils\TaskSchedule;
|
|
|
|
/**
|
|
* Task scheduler class.
|
|
*
|
|
* @package Framework
|
|
* @license OMS License 1.0
|
|
* @link http://website.orange-management.de
|
|
* @since 1.0.0
|
|
* @codeCoverageIgnore
|
|
*/
|
|
class TaskScheduler extends SchedulerAbstract
|
|
{
|
|
/**
|
|
* Normalize run result for easier parsing
|
|
*
|
|
* @param string $raw Raw command output
|
|
*
|
|
* @return string Normalized string for parsing
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
private function normalize(string $raw) : string
|
|
{
|
|
return \str_replace("\r\n", "\n", $raw);
|
|
}
|
|
|
|
/**
|
|
* {@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;
|
|
}
|
|
}
|