Static job path added

This commit is contained in:
Dennis Eichhorn 2016-11-12 21:41:11 +01:00
parent e605eb3885
commit 5bcefc9a40
2 changed files with 65 additions and 45 deletions

View File

@ -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 <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
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
*

View File

@ -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 <d.eichhorn@oms.com>
*/
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]);