fix: do not require jobId for AdminShell jobGenerateCorrelation, create a new job if jobId is null. fixes #9206

pull/9296/head
Luciano Righetti 2023-09-11 10:36:56 +02:00
parent 1fdedb15c9
commit 53e16ce752
2 changed files with 15 additions and 3 deletions

View File

@ -126,11 +126,17 @@ class AdminShell extends AppShell
public function jobGenerateCorrelation()
{
if (empty($this->args[0])) {
die('Usage: ' . $this->Server->command_line_functions['console_admin_tasks']['data']['Generate correlation'] . PHP_EOL);
$jobId = $this->args[0] ?? null;
if (empty($jobId)) {
$jobId = $this->Job->createJob(
'SYSTEM',
Job::WORKER_DEFAULT,
'generate correlation',
'All attributes',
'Job created.'
);
}
$jobId = $this->args[0];
$this->Correlation->generateCorrelation($jobId);
}

View File

@ -140,9 +140,15 @@ class Correlation extends AppModel
$attributeCount = 0;
if (Configure::read('MISP.background_jobs') && $jobId) {
$this->Job = ClassRegistry::init('Job');
$this->Job->id = $jobId;
} else {
$jobId = false;
}
if(!$this->Job->exists()){
$jobId = false;
}
if (!empty($eventIds)) {
$eventCount = count($eventIds);
foreach ($eventIds as $j => $currentEventId) {