mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-06 20:48:40 +00:00
Static job path added
This commit is contained in:
parent
e605eb3885
commit
5bcefc9a40
|
|
@ -29,13 +29,76 @@ namespace phpOMS\Utils\TaskSchedule;
|
||||||
abstract class SchedulerAbstract
|
abstract class SchedulerAbstract
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* tasks.
|
* Tasks.
|
||||||
*
|
*
|
||||||
* @var TaskAbstract[]
|
* @var TaskAbstract[]
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected $tasks = [];
|
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
|
* Add task
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -30,40 +30,6 @@ use phpOMS\Validation\Base\DateTime;
|
||||||
*/
|
*/
|
||||||
class TaskScheduler extends SchedulerAbstract
|
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()
|
public function save()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -91,16 +57,7 @@ class TaskScheduler extends SchedulerAbstract
|
||||||
2 => ['pipe', 'w'],
|
2 => ['pipe', 'w'],
|
||||||
];
|
];
|
||||||
|
|
||||||
if (count($_ENV) === 0) {
|
$resource = proc_open($cmd, $desc, $pipes, __DIR__, null);
|
||||||
$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]);
|
$stdout = stream_get_contents($pipes[1]);
|
||||||
$stderr = stream_get_contents($pipes[2]);
|
$stderr = stream_get_contents($pipes[2]);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user