From d1f6921b20c3abf8ec9d03559bfe63848161ca44 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Mon, 7 Nov 2016 17:38:11 +0100 Subject: [PATCH] Comment fixes --- DataStorage/Database/DataMapperAbstract.php | 2 + Stdlib/Graph/Tree.php | 2 - Utils/TaskSchedule/SchedulerAbstract.php | 2 +- Utils/TaskSchedule/TaskScheduler.php | 71 ++++++++++++++++++++- 4 files changed, 72 insertions(+), 5 deletions(-) diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index 22993efd8..dba3be76e 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -1330,6 +1330,8 @@ class DataMapperAbstract implements DataMapperInterface /** * Get model based on request object * + * @todo: change to graphql + * * @param RequestAbstract $request Request object * * @return mixed diff --git a/Stdlib/Graph/Tree.php b/Stdlib/Graph/Tree.php index 8ffa06b7b..4d1a29e36 100644 --- a/Stdlib/Graph/Tree.php +++ b/Stdlib/Graph/Tree.php @@ -15,8 +15,6 @@ */ namespace phpOMS\Datatypes; -use phpOMS\Validation\Base\IbanEnum; - /** * Tree class. * diff --git a/Utils/TaskSchedule/SchedulerAbstract.php b/Utils/TaskSchedule/SchedulerAbstract.php index a49553ff8..d64854ae1 100644 --- a/Utils/TaskSchedule/SchedulerAbstract.php +++ b/Utils/TaskSchedule/SchedulerAbstract.php @@ -95,7 +95,7 @@ abstract class SchedulerAbstract * @since 1.0.0 * @author Dennis Eichhorn */ - public function list() : array + public function getAll() : array { return $this->tasks; } diff --git a/Utils/TaskSchedule/TaskScheduler.php b/Utils/TaskSchedule/TaskScheduler.php index 95ec74115..81f847587 100644 --- a/Utils/TaskSchedule/TaskScheduler.php +++ b/Utils/TaskSchedule/TaskScheduler.php @@ -29,6 +29,16 @@ namespace phpOMS\Utils\TaskSchedule; class TaskScheduler extends SchedulerAbstract { + const BIN = ''; + + /** + * Env variables. + * + * @var array + * @since 1.0.0 + */ + private $envOptions = []; + public function save() { @@ -41,12 +51,69 @@ class TaskScheduler extends SchedulerAbstract * * @return array * + * @throws \Exception + * * @since 1.0.0 * @author Dennis Eichhorn */ public function run(string $cmd) : array { - // TODO: Implement run() method. - return []; + $cmd = 'cd ' . escapeshellarg(dirname(self::BIN)) . ' && ' . basename(self::BIN) . ' -C ' . escapeshellarg(__DIR__) . ' ' . $cmd; + + $pipes = []; + $desc = [ + 1 => ['pipe', 'w'], + 2 => ['pipe', 'w'], + ]; + + if (count($_ENV) === 0) { + $env = null; + foreach ($this->envOptions as $key => $value) { + putenv(sprintf("%s=%s", $key, $value)); + } + } else { + $env = array_merge($_ENV, $this->envOptions); + } + + $resource = proc_open($cmd, $desc, $pipes, __DIR__, $env); + $stdout = stream_get_contents($pipes[1]); + $stderr = stream_get_contents($pipes[2]); + + foreach ($pipes as $pipe) { + fclose($pipe); + } + + $status = trim(proc_close($resource)); + + if ($status == -1) { + throw new \Exception($stderr); + } + + return trim($stdout); + } + + public function getAll() : array + { + return str_getcsv($this->run('/query /v /fo CSV')); + } + + public function get(string $id) + { + + } + + public function getByName(string $name) : Schedule + { + + } + + public function getAllByName(string $name) : array + { + return str_getcsv($this->run('/query /v /fo CSV /tn ' . escapeshellarg($name))); + } + + public function create(Schedule $task) + { + } }