BUGFIX: demo mode was always activated

main
Jeroen De Meerleer 1 month ago
parent 417521d497
commit b3e25ac14b
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
  1. 14
      src/Repository/JobRepository.php
  2. 4
      templates/flashes.html.twig

@ -187,7 +187,7 @@ class JobRepository extends EntityRepository
*/
private function runHttpJob(Job &$job): array
{
if(isset($_ENV['DEMO_MODE']) && $_ENV['DEMO_MODE']) {
if(isset($_ENV['DEMO_MODE']) && $_ENV['DEMO_MODE'] == 'true') {
$exitcodes = [...array_fill(0,120, $job->getData('http-status')[0]), ...array_keys(Response::$statusTexts)];
$return['exitcode'] = $exitcodes[random_int(0, 181)];
$return['failed'] = !in_array($return['exitcode'], $job->getData('http-status'));
@ -228,8 +228,8 @@ class JobRepository extends EntityRepository
*/
private function runCommandJob(Job &$job): array
{
if(isset($_ENV['DEMO_MODE']) && $_ENV['DEMO_MODE']) {
$exitcodes = [...array_fill(0,400, $job->getData('response')), ...range(0, 255)];
if(isset($_ENV['DEMO_MODE']) && $_ENV['DEMO_MODE'] == 'true') {
$exitcodes = [...array_fill(0,400, $job->getData('response')[0]), ...range(0, 255)];
$return['exitcode'] = $exitcodes[random_int(0, 655)];
$return['failed'] = !in_array($return['exitcode'], $job->getData('response'));
$return['output'] = 'Demo mode!';
@ -321,7 +321,7 @@ class JobRepository extends EntityRepository
{
$em = $this->getEntityManager();
if($job->getRunning() == 1) {
if(isset($_ENV['DEMO_MODE']) && $_ENV['DEMO_MODE']) {
if(isset($_ENV['DEMO_MODE']) && $_ENV['DEMO_MODE'] == 'true') {
$job->setRunning(time() + $job->getData('reboot-delay-secs') + ($job->getData('reboot-duration') * 60));
$em->persist($job);
$em->flush();
@ -362,8 +362,8 @@ class JobRepository extends EntityRepository
if($job->getRunning() > time()) {
return ['status' => 'deferred'];
}
if(isset($_ENV['DEMO_MODE']) && $_ENV['DEMO_MODE']) {
$exitcodes = [...array_fill(0,400, $job->getData('getservices-response')), ...range(0, 255)];
if(isset($_ENV['DEMO_MODE']) && $_ENV['DEMO_MODE'] == 'true') {
$exitcodes = [...array_fill(0,400, $job->getData('getservices-response')[0]), ...range(0, 255)];
$return['exitcode'] = $exitcodes[random_int(0, 655)];
$return['failed'] = !in_array($return['exitcode'], $job->getData('getservices-response'));
$return['output'] = 'Demo mode!';
@ -717,4 +717,4 @@ class JobRepository extends EntityRepository
return ['success' => true, 'message' => 'Cronjob succesfully deleted'];
}
}
}

@ -7,10 +7,10 @@
</div>
{% endfor %}
{% endfor %}
{% if app.request.server.get('DEMO_MODE') %}
{% if app.request.server.get('DEMO_MODE') == 'true' %}
<div class="alert alert-warning alert-dismissible fade show" role="alert">
{{ 'demomode.flashnotice' | trans }}
<button type="button" class="btn-close" data-dismiss="alert" aria-label="Close">
</button>
</div>
{% endif %}
{% endif %}

Loading…
Cancel
Save