ENHANCEMENT: better setter for data
This commit is contained in:
parent
36052686e7
commit
045d2389b9
|
@ -3,9 +3,9 @@
|
||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
use App\Repository\JobRepository;
|
use App\Repository\JobRepository;
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use InvalidArgumentException;
|
|
||||||
|
|
||||||
#[ORM\Entity(repositoryClass: JobRepository::class)]
|
#[ORM\Entity(repositoryClass: JobRepository::class)]
|
||||||
class Job
|
class Job
|
||||||
|
@ -116,13 +116,7 @@ class Job
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setData(array $data): Job
|
public function setData(string $name, mixed $value): Job
|
||||||
{
|
|
||||||
$this->data = json_encode($data);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addData(string $name, mixed $value): mixed
|
|
||||||
{
|
{
|
||||||
$data = json_decode($this->data, true);
|
$data = json_decode($this->data, true);
|
||||||
if (!empty($name)) {
|
if (!empty($name)) {
|
||||||
|
@ -151,6 +145,7 @@ class Job
|
||||||
if (!empty($name)) {
|
if (!empty($name)) {
|
||||||
$this->removeDataItem($data, $name);
|
$this->removeDataItem($data, $name);
|
||||||
}
|
}
|
||||||
|
$this->data = json_encode($data);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,7 +243,7 @@ class Job
|
||||||
/**
|
/**
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function getRuns(): Collection|ArrayCollection
|
public function getRuns(): Collection
|
||||||
{
|
{
|
||||||
return $this->runs;
|
return $this->runs;
|
||||||
}
|
}
|
||||||
|
@ -257,7 +252,7 @@ class Job
|
||||||
* @param Collection $runs
|
* @param Collection $runs
|
||||||
* @return Job
|
* @return Job
|
||||||
*/
|
*/
|
||||||
public function setRuns(Collection|ArrayCollection $runs): Job
|
public function setRuns(Collection $runs): Job
|
||||||
{
|
{
|
||||||
$this->runs = $runs;
|
$this->runs = $runs;
|
||||||
return $this;
|
return $this;
|
||||||
|
|
|
@ -66,18 +66,18 @@ class JobRepository extends EntityRepository
|
||||||
|
|
||||||
foreach ($jobs as $key=>&$job) {
|
foreach ($jobs as $key=>&$job) {
|
||||||
$jobData = $job->getData();
|
$jobData = $job->getData();
|
||||||
$job->addData('host-displayname', $jobData['host']);
|
$job->setData('host-displayname', $jobData['host']);
|
||||||
$job->addData('host', $jobData['host']);
|
$job->setData('host', $jobData['host']);
|
||||||
$job->addData('service', $jobData['service'] ?? '');
|
$job->setData('service', $jobData['service'] ?? '');
|
||||||
$job->addData('norun', $job->getLastrun() !== null && $job->getNextrun() > $job->getLastrun());
|
$job->setData('norun', $job->getLastrun() !== null && $job->getNextrun() > $job->getLastrun());
|
||||||
$job->addData('running', $job->getRunning() != 0);
|
$job->setData('running', $job->getRunning() != 0);
|
||||||
$failedruns = $runRepo->getRunsForJob($job->getId(), true, $jobData['fail-days']);
|
$failedruns = $runRepo->getRunsForJob($job->getId(), true, $jobData['fail-days']);
|
||||||
$failed = count($failedruns);
|
$failed = count($failedruns);
|
||||||
$all = count($runRepo->getRunsForJob($job->getId(), false, $jobData['fail-days']));
|
$all = count($runRepo->getRunsForJob($job->getId(), false, $jobData['fail-days']));
|
||||||
$job->addData('lastfail', $failedruns[0] ?? NULL);
|
$job->setData('lastfail', $failedruns[0] ?? NULL);
|
||||||
$job->addData('needschecking', $all > 0 && (($failed / $all) * 100) > $jobData['fail-pct']);
|
$job->setData('needschecking', $all > 0 && (($failed / $all) * 100) > $jobData['fail-pct']);
|
||||||
if(!empty($jobData['containertype']) && $jobData['containertype'] != 'none') {
|
if(!empty($jobData['containertype']) && $jobData['containertype'] != 'none') {
|
||||||
$job->addData('host-displayname', $jobData['service'] . ' on ' . $jobData['host']);
|
$job->setData('host-displayname', $jobData['service'] . ' on ' . $jobData['host']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,8 +209,8 @@ class JobRepository extends EntityRepository
|
||||||
|
|
||||||
if(!empty($job->getData('vars'))) {
|
if(!empty($job->getData('vars'))) {
|
||||||
foreach($job->getData('vars') as $key => $var) {
|
foreach($job->getData('vars') as $key => $var) {
|
||||||
if (!empty($job->getData('basicauth-username'))) $job->addData('basicauth-username', str_replace('{' . $key . '}', $var['value'], $job->getData('basicauth-username')));
|
if (!empty($job->getData('basicauth-username'))) $job->setData('basicauth-username', str_replace('{' . $key . '}', $var['value'], $job->getData('basicauth-username')));
|
||||||
$job->addData('url', str_replace('{' . $key . '}', $var['value'], $job->getData('url')));
|
$job->setData('url', str_replace('{' . $key . '}', $var['value'], $job->getData('url')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@ class JobRepository extends EntityRepository
|
||||||
{
|
{
|
||||||
if(!empty($job->getData('vars'))) {
|
if(!empty($job->getData('vars'))) {
|
||||||
foreach ($job->getData('vars') as $key => $var) {
|
foreach ($job->getData('vars') as $key => $var) {
|
||||||
$job->addData('command', str_replace('{' . $key . '}', $var['value'], $job->getData('command')));
|
$job->setData('command', str_replace('{' . $key . '}', $var['value'], $job->getData('command')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,12 +300,12 @@ class JobRepository extends EntityRepository
|
||||||
if($job->getRunning() == 1) {
|
if($job->getRunning() == 1) {
|
||||||
$this->setTempVar($job->getId(), 'starttime', $starttime);
|
$this->setTempVar($job->getId(), 'starttime', $starttime);
|
||||||
$this->setTempVar($job->getId(), 'manual', $manual);
|
$this->setTempVar($job->getId(), 'manual', $manual);
|
||||||
$job->addData('reboot-command', str_replace('{reboot-delay}', $job['data']['reboot-delay'], $job->getData('reboot-command')));
|
$job->setData('reboot-command', str_replace('{reboot-delay}', $job['data']['reboot-delay'], $job->getData('reboot-command')));
|
||||||
$job->addData('reboot-command', str_replace('{reboot-delay-secs}', $job['data']['reboot-delay-secs'], $job->getData('reboot-command')));
|
$job->setData('reboot-command', str_replace('{reboot-delay-secs}', $job['data']['reboot-delay-secs'], $job->getData('reboot-command')));
|
||||||
|
|
||||||
if (!empty($job->getData('vars'))) {
|
if (!empty($job->getData('vars'))) {
|
||||||
foreach ($job->getData('vars') as $key => $var) {
|
foreach ($job->getData('vars') as $key => $var) {
|
||||||
$job->addData('reboot-command', str_replace('{' . $key . '}', $var['value'], $job->getData('reboot-command')));
|
$job->setData('reboot-command', str_replace('{' . $key . '}', $var['value'], $job->getData('reboot-command')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,7 +342,7 @@ class JobRepository extends EntityRepository
|
||||||
|
|
||||||
if (!empty($job->getData('vars'))) {
|
if (!empty($job->getData('vars'))) {
|
||||||
foreach ($job->getData('vars') as $key => $var) {
|
foreach ($job->getData('vars') as $key => $var) {
|
||||||
$job->addData('getservices-command', str_replace('{' . $key . '}', $var['value'], $job->getData('getservices-command')));
|
$job->setData('getservices-command', str_replace('{' . $key . '}', $var['value'], $job->getData('getservices-command')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -640,7 +640,7 @@ class JobRepository extends EntityRepository
|
||||||
if(!empty($job->getData('vars'))) {
|
if(!empty($job->getData('vars'))) {
|
||||||
foreach ($job->getData('vars') as $key => &$value) {
|
foreach ($job->getData('vars') as $key => &$value) {
|
||||||
if ($value['issecret']) {
|
if ($value['issecret']) {
|
||||||
$job->addData('vars.' . $key . '.value', ($withSecrets) ? Secret::decrypt(base64_decode($value['value'])) : '');
|
$job->setData('vars.' . $key . '.value', ($withSecrets) ? Secret::decrypt(base64_decode($value['value'])) : '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -648,13 +648,13 @@ class JobRepository extends EntityRepository
|
||||||
switch($job->getData('crontype')) {
|
switch($job->getData('crontype')) {
|
||||||
case 'http':
|
case 'http':
|
||||||
if($job->hasData('vars.basicauth-password.value')) {
|
if($job->hasData('vars.basicauth-password.value')) {
|
||||||
$job->addData('basicauth-password', $job->getData('vars.basicauth-password.value'));
|
$job->setData('basicauth-password', $job->getData('vars.basicauth-password.value'));
|
||||||
$job->removeData('vars.basicauth-password');
|
$job->removeData('vars.basicauth-password');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'reboot':
|
case 'reboot':
|
||||||
$job->addData('reboot-delay', $job->getData('vars.reboot-delay.value'));
|
$job->setData('reboot-delay', $job->getData('vars.reboot-delay.value'));
|
||||||
$job->addData('reboot-delay-secs', $job->getData('vars.reboot-delay-secs.value'));
|
$job->setData('reboot-delay-secs', $job->getData('vars.reboot-delay-secs.value'));
|
||||||
|
|
||||||
$job->removeData('vars.reboot-delay');
|
$job->removeData('vars.reboot-delay');
|
||||||
$job->removeData('vars.reboot-delay-secs');
|
$job->removeData('vars.reboot-delay-secs');
|
||||||
|
@ -664,11 +664,11 @@ class JobRepository extends EntityRepository
|
||||||
switch($job->getData('hosttype')) {
|
switch($job->getData('hosttype')) {
|
||||||
case 'ssh':
|
case 'ssh':
|
||||||
if($job->hasData('vars.ssh-privkey.value')) {
|
if($job->hasData('vars.ssh-privkey.value')) {
|
||||||
$job->addData('ssh-privkey', $job->getData('vars.ssh-privkey.value'));
|
$job->setData('ssh-privkey', $job->getData('vars.ssh-privkey.value'));
|
||||||
$job->removeData('vars.ssh-privkey');
|
$job->removeData('vars.ssh-privkey');
|
||||||
}
|
}
|
||||||
if($job->hasData('vars.privkey-password.value')) {
|
if($job->hasData('vars.privkey-password.value')) {
|
||||||
$job->addData('privkey-password', $job->getData('vars.privkey-password.value'));
|
$job->setData('privkey-password', $job->getData('vars.privkey-password.value'));
|
||||||
$job->removeData('vars.privkey-password');
|
$job->removeData('vars.privkey-password');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -256,7 +256,6 @@
|
||||||
</div>
|
</div>
|
||||||
{% set key = 1 %}
|
{% set key = 1 %}
|
||||||
{% if job.data.vars is defined %}
|
{% if job.data.vars is defined %}
|
||||||
Im defined!
|
|
||||||
{% for id,var in job.data.vars %}
|
{% for id,var in job.data.vars %}
|
||||||
<div class="input-group var-group">
|
<div class="input-group var-group">
|
||||||
<div class="input-group-text border-end-0">
|
<div class="input-group-text border-end-0">
|
||||||
|
|
Loading…
Reference in New Issue