Skip to content

Commit

Permalink
Store also Runtemplate updads
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitexus committed Dec 27, 2024
1 parent caf3925 commit dc2536b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/MultiFlexi/Executor/Native.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ public static function description(): string
return _('Run Job on same machine as MultiFlexi itself');
}

public function setJob(\MultiFlexi\Job &$job): void {
public function setJob(\MultiFlexi\Job &$job): void
{
parent::setJob($job);
$this->jobFiles = (new \MultiFlexi\FileStore())->extractFilesForJob($this->job);

$this->environment = array_merge($this->environment, $this->jobFiles);
}

/**
* @return string
*/
Expand All @@ -65,6 +66,7 @@ public function cmdparams()
public function commandline(): string
{
$this->job->setEnvironment($this->environment);

return $this->executable().' '.$this->cmdparams();
}

Expand Down
4 changes: 2 additions & 2 deletions src/MultiFlexi/FileStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ public function loadAndStoreFile(string $field, string $filePath, string $fileNa
/**
* Store a file related to a runtemplate.
*/
public function storeFileForRuntemplate(string $field, string $filePath, string $fileName, int $runtemplateId): bool
public function storeFileForRuntemplate(string $field, string $filePath, string $fileName, RunTemplate $runtemplate): bool
{
return $this->loadAndStoreFile($field, $filePath, $fileName, $runtemplateId, null);
return $this->loadAndStoreFile($field, $filePath, $fileName, $runtemplate->getMyKey(), null);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/MultiFlexi/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,8 @@ public function setPid(int $pid): void
$this->setZabbixValue('pid', $pid);
}

public function setEnvironment(array $environment) {
public function setEnvironment(array $environment): void
{
$this->environment = $environment;
}
}
3 changes: 2 additions & 1 deletion src/MultiFlexi/Ui/RuntemplateConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class RuntemplateConfigForm extends EngineForm

public function __construct(\MultiFlexi\RunTemplate $engine)
{
parent::__construct($engine, null, ['method' => 'post', 'action' => 'runtemplate.php']);
parent::__construct($engine, null, ['method' => 'post', 'action' => 'runtemplate.php', 'enctype' => 'multipart/form-data']);

$defaults = $engine->getAppEnvironment();
$appRequirements = $engine->getApplication()->getRequirements();
$customized = $engine->getRuntemplateEnvironment();
Expand Down
24 changes: 24 additions & 0 deletions src/runtemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,30 @@

$app->checkRequiredFields($dataToSave, true);

/**
* Save all uploaded files into temporary directory and prepare job environment.
*/
if (!empty($_FILES)) {
$fileStore = new \MultiFlexi\FileStore();

foreach ($_FILES as $field => $file) {
if ($file['error'] === 0) {
if (is_uploaded_file($file['tmp_name'])) {
$uploadEnv[$field]['value'] = $file['name'];
$uploadEnv[$field]['upload'] = $file['tmp_name'];
$uploadEnv[$field]['type'] = 'file';
$uploadEnv[$field]['source'] = 'Upload';
}
}
}

if ($uploadEnv) {
foreach ($uploadEnv as $field => $file) {
$fileStore->storeFileForRuntemplate($field, $file['upload'], $file['value'], $runTemplate);
}
}
}

if ($configurator->takeData($dataToSave) && null !== $configurator->saveToSQL()) {
$configurator->addStatusMessage(_('Config fields Saved'), 'success');
} else {
Expand Down

0 comments on commit dc2536b

Please sign in to comment.