mirror of https://github.com/MISP/MISP
chg: use new bg job tool in post model, refactor command
parent
efd55c362c
commit
c3c0c15182
|
@ -307,23 +307,35 @@ class EventShell extends AppShell
|
|||
public function postsemail()
|
||||
{
|
||||
$this->ConfigLoad->execute();
|
||||
if (empty($this->args[0]) || empty($this->args[1]) || empty($this->args[2]) ||
|
||||
empty($this->args[3]) || empty($this->args[4]) || empty($this->args[5])) {
|
||||
if (
|
||||
empty($this->args[0]) || empty($this->args[1]) || empty($this->args[2]) ||
|
||||
empty($this->args[3]) || empty($this->args[4]) || empty($this->args[5])
|
||||
) {
|
||||
die('Usage: ' . $this->Server->command_line_functions['event_management_tasks']['data']['Posts email'] . PHP_EOL);
|
||||
}
|
||||
|
||||
$userId = $this->args[0];
|
||||
$postId = $this->args[1];
|
||||
$eventId = $this->args[2];
|
||||
$userId = intval($this->args[0]);
|
||||
$postId = intval($this->args[1]);
|
||||
$eventId = intval($this->args[2]);
|
||||
$title = $this->args[3];
|
||||
$message = $this->args[4];
|
||||
$processId = $this->args[5];
|
||||
$this->Job->id = $processId;
|
||||
$this->Job->id = intval($this->args[5]);
|
||||
|
||||
$result = $this->Post->sendPostsEmail($userId, $postId, $eventId, $title, $message);
|
||||
$job['Job']['progress'] = 100;
|
||||
$job['Job']['message'] = 'Emails sent.';
|
||||
$job['Job']['date_modified'] = date("Y-m-d H:i:s");
|
||||
$this->Job->save($job);
|
||||
|
||||
if ($result) {
|
||||
$this->Job->save([
|
||||
'progress' => 100,
|
||||
'message' => 'Emails sent.',
|
||||
'date_modified' => date('Y-m-d H:i:s'),
|
||||
'status' => Job::STATUS_COMPLETED
|
||||
]);
|
||||
} else {
|
||||
$this->Job->save([
|
||||
'date_modified' => date('Y-m-d H:i:s'),
|
||||
'status' => Job::STATUS_FAILED
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function enqueueCaching()
|
||||
|
|
|
@ -32,27 +32,33 @@ class Post extends AppModel
|
|||
{
|
||||
if (Configure::read('MISP.background_jobs')) {
|
||||
$user = $this->User->findById($user_id);
|
||||
|
||||
/** @var Job $job */
|
||||
$job = ClassRegistry::init('Job');
|
||||
$job->create();
|
||||
$data = array(
|
||||
'worker' => 'email',
|
||||
'job_type' => 'posts_alert',
|
||||
'job_input' => 'Post: ' . $post_id,
|
||||
'status' => 0,
|
||||
'retries' => 0,
|
||||
'org_id' => $user['User']['org_id'],
|
||||
'org' => $user['Organisation']['name'],
|
||||
'message' => 'Sending...',
|
||||
$jobId = $job->createJob(
|
||||
$user['User'],
|
||||
Job::WORKER_EMAIL,
|
||||
'posts_alert',
|
||||
'Post: ' . $post_id,
|
||||
'Sending...'
|
||||
);
|
||||
$job->save($data);
|
||||
$jobId = $job->id;
|
||||
$process_id = CakeResque::enqueue(
|
||||
'email',
|
||||
'EventShell',
|
||||
array('postsemail', $user_id, $post_id, $event_id, $title, $message, $jobId),
|
||||
true
|
||||
|
||||
$this->getBackgroundJobsTool()->enqueue(
|
||||
BackgroundJobsTool::EMAIL_QUEUE,
|
||||
BackgroundJobsTool::CMD_EVENT,
|
||||
[
|
||||
'postsemail',
|
||||
$user_id,
|
||||
$post_id,
|
||||
$event_id,
|
||||
$title,
|
||||
$message,
|
||||
$jobId
|
||||
],
|
||||
true,
|
||||
$jobId
|
||||
);
|
||||
$job->saveField('process_id', $process_id);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return $this->sendPostsEmail($user_id, $post_id, $event_id, $title, $message);
|
||||
|
|
Loading…
Reference in New Issue