mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-14 19:18:41 +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
|
||||
{
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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]);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user