Skip to content

Commit 1764577

Browse files
author
Vítězslav Dvořák
committed
Enhance executor classes with environment handling and user login retrieval
1 parent 84386ab commit 1764577

File tree

6 files changed

+27
-4
lines changed

6 files changed

+27
-4
lines changed

src/MultiFlexi/CommonExecutor.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ abstract class CommonExecutor extends \Ease\Sand
3434
public function __construct(Job &$job)
3535
{
3636
$this->setObjectName();
37+
$this->environment = new ConfigFields('Executor'.\Ease\Functions::baseClassName($this));
3738
$this->setJob($job);
3839
}
3940

4041
public function setJob(Job &$job): void
4142
{
4243
$this->job = &$job;
4344
$this->setObjectName($job->getMyKey().'@'.\Ease\Logger\Message::getCallerName($this));
44-
$this->environment = $job->getEnvironment();
45+
$this->environment->addFields($job->getEnvironment());
4546
}
4647

4748
/**
@@ -73,4 +74,9 @@ public function getPid(): ?int
7374
{
7475
return $this->pid;
7576
}
77+
78+
public function getEnvironment(): ConfigFields
79+
{
80+
return $this->environment;
81+
}
7682
}

src/MultiFlexi/Configuration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ public function getConfigFields(): ConfigFields
7373
{
7474
$cnf = new ConfigFields('');
7575

76-
foreach ((array)$this->getData() as $cfgRaw) {
76+
foreach ((array) $this->getData() as $cfgRaw) {
7777
$cnf->addField(new ConfigField($cfgRaw['name'], $cfgRaw['type'], $cfgRaw['name'], '', '', $cfgRaw['value']));
7878
}
79-
79+
8080
return $cnf;
8181
}
8282

src/MultiFlexi/Executor/Native.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ class Native extends \MultiFlexi\CommonExecutor implements \MultiFlexi\executor
3131
private string $commandline;
3232
private \MultiFlexi\ConfigFields $jobFiles;
3333

34+
public function __construct(\MultiFlexi\Job &$job)
35+
{
36+
parent::__construct($job);
37+
38+
foreach (getenv() as $key => $value) {
39+
$this->environment->addField(new \MultiFlexi\ConfigField($key, 'string', $key, '', '', $value));
40+
}
41+
}
42+
3443
public static function name(): string
3544
{
3645
return _('Native');

src/MultiFlexi/UnixUser.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct($userID = null)
2929
* If the user does not exist in the 'user' table, create a new one.
3030
*/
3131
/** @var string $unixUsername */
32-
$unixUsername = $userID ?? get_current_user();
32+
$unixUsername = $userID ?? $this->getUserLogin();
3333

3434
parent::__construct($unixUsername);
3535

@@ -51,4 +51,9 @@ public function __construct($userID = null)
5151
}
5252
}
5353
}
54+
55+
public function getUserLogin(): string
56+
{
57+
return get_current_user();
58+
}
5459
}

src/MultiFlexi/User.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public function __construct($userID = null)
7474
if ($userID) {
7575
$this->setKeyColumn(is_numeric($userID) ? 'id' : 'login');
7676
$this->loadFromSQL($userID);
77+
$this->setKeyColumn('id');
7778
}
7879
}
7980

src/MultiFlexi/executor.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public function commandline(): string;
4040

4141
public function getPid(): ?int;
4242

43+
public function getEnvironment(): ConfigFields;
44+
4345
/**
4446
* Can this Executor execute given application ?
4547
*

0 commit comments

Comments
 (0)