Skip to content

Commit

Permalink
fix: display flash message on invalid backup job name
Browse files Browse the repository at this point in the history
In backup job report, display flash message instead of throwing
excpeption if backup job name is invalid.
  • Loading branch information
dfranco committed Dec 29, 2023
1 parent cf3f411 commit e81b25e
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions application/Controller/BackupJobController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Core\Utils\CUtils;
use Core\Utils\DateTimeUtil;
use Core\Helpers\Sanitizer;
use Odan\Session\SessionInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use GuzzleHttp\Psr7\Response;
use Slim\Views\Twig;
Expand All @@ -41,10 +42,20 @@ class BackupJobController
{
private Twig $view;
private JobTable $jobTable;
private SessionInterface $session;

public function __construct(Twig $view, JobTable $jobTable) {
/**
* @var string|null
*/
private ?string $basePath;

public function __construct(Twig $view, JobTable $jobTable, SessionInterface $session) {
$this->view = $view;
$this->jobTable = $jobTable;
$this->session = $session;

FileConfig::open(CONFIG_FILE);
$this->basePath = FileConfig::get_Value('basepath') ?? null;
}

/**
Expand Down Expand Up @@ -107,10 +118,14 @@ public function index(Request $request, Response $response): Response
} else {
$tplData['no_report_options'] = 'false';

// Make sure provided backupjob_name exist
// Make sure provided backupjob_name does exists
if (!in_array($backupjob_name, $jobslist)) {
// TODO: Below should be included in flash and redirect user to another page (maybe referer)
throw new AppException('Wrong user input: invalid backupjob_name');
$this->session->getFlash()->set('error', ['Invalid Backup Job name']);
$this->session->save();

return $response
->withHeader('Location', $this->basePath . '/backupjob')
->withStatus(302);
}

$tplData['selected_jobname'] = $backupjob_name;
Expand Down

0 comments on commit e81b25e

Please sign in to comment.