diff --git a/Utils/TaskSchedule/SchedulerAbstract.php b/Utils/TaskSchedule/SchedulerAbstract.php index d64854ae1..bbd7f50a8 100644 --- a/Utils/TaskSchedule/SchedulerAbstract.php +++ b/Utils/TaskSchedule/SchedulerAbstract.php @@ -29,13 +29,76 @@ namespace phpOMS\Utils\TaskSchedule; abstract class SchedulerAbstract { /** - * tasks. + * Tasks. * * @var TaskAbstract[] * @since 1.0.0 */ protected $tasks = []; + /** + * Bin path. + * + * @var string + * @since 1.0.0 + */ + protected static $bin = ''; + + /** + * Get git binary. + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function getBin() : string + { + return self::$bin; + } + + /** + * Set git binary. + * + * @param string $path Git path + * + * @throws PathException + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function setBin(string $path) + { + if (realpath($path) === false) { + throw new PathException($path); + } + + self::$bin = realpath($path); + } + + /** + * Test git. + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function test() : bool + { + $pipes = []; + $resource = proc_open(escapeshellarg(self::$bin), [1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes); + + $stdout = stream_get_contents($pipes[1]); + $stderr = stream_get_contents($pipes[2]); + + foreach ($pipes as $pipe) { + fclose($pipe); + } + + return trim(proc_close($resource)) !== 127; + } + /** * Add task * diff --git a/Utils/TaskSchedule/TaskScheduler.php b/Utils/TaskSchedule/TaskScheduler.php index dc92396e2..e37378a3f 100644 --- a/Utils/TaskSchedule/TaskScheduler.php +++ b/Utils/TaskSchedule/TaskScheduler.php @@ -30,40 +30,6 @@ use phpOMS\Validation\Base\DateTime; */ class TaskScheduler extends SchedulerAbstract { - - protected static $bin = 'c:/WINDOWS/system32/schtasks.exe'; - - /** - * Env variables. - * - * @var array - * @since 1.0.0 - */ - private $envOptions = []; - - /** - * Test git. - * - * @return bool - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - public static function test() : bool - { - $pipes = []; - $resource = proc_open(escapeshellarg(self::$bin), [1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes); - - $stdout = stream_get_contents($pipes[1]); - $stderr = stream_get_contents($pipes[2]); - - foreach ($pipes as $pipe) { - fclose($pipe); - } - - return trim(proc_close($resource)) !== 127; - } - public function save() { @@ -91,16 +57,7 @@ class TaskScheduler extends SchedulerAbstract 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); + $resource = proc_open($cmd, $desc, $pipes, __DIR__, null); $stdout = stream_get_contents($pipes[1]); $stderr = stream_get_contents($pipes[2]);