Commit 76074b6b authored by Roman Ondráček's avatar Roman Ondráček

Config: add redirect to datagrid if scheduler task does not exist

Signed-off-by: Roman Ondráček's avatarRoman Ondráček <ondracek.roman@centrum.cz>
parent c92b8b1a
Pipeline #2113 passed with stages
in 14 minutes and 27 seconds
......@@ -104,7 +104,6 @@ class SchedulerManager {
/**
* Gets task's files
* @return string[] Files with tasks
* @throws JsonException
*/
public function getTaskFiles(): array {
$dir = $this->fileManager->getDirectory();
......@@ -115,9 +114,13 @@ class SchedulerManager {
foreach (Finder::findFiles('*.json')->from($dir) as $file) {
$dirPathPattern = ['~^' . realpath($dir) . '/~', '/.json$/'];
$fileName = Strings::replace($file->getRealPath(), $dirPathPattern, '');
$json = $this->fileManager->read($fileName);
if (array_key_exists('taskId', $json)) {
$files[$json['taskId']] = $fileName;
try {
$json = $this->fileManager->read($fileName);
if (array_key_exists('taskId', $json)) {
$files[$json['taskId']] = $fileName;
}
} catch (JsonException $e) {
// Skip invalid JSON files
}
}
asort($files);
......
......@@ -100,6 +100,9 @@ class SchedulerPresenter extends ProtectedPresenter {
* @param int $id ID of task in Scheduler
*/
public function renderEdit(int $id): void {
if (!array_key_exists($id, $this->manager->getTaskFiles())) {
$this->redirect('Scheduler:default');
}
$this->template->id = $id;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment