summaryrefslogtreecommitdiff
path: root/app/Job/CommentEventJob.php
blob: 62fae40a9408c90f1d3504cc391622352f64d85a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php

namespace Kanboard\Job;

use Kanboard\EventBuilder\CommentEventBuilder;
use Kanboard\Model\CommentModel;

/**
 * Class CommentEventJob
 *
 * @package Kanboard\Job
 * @author  Frederic Guillot
 */
class CommentEventJob extends BaseJob
{
    /**
     * Set job params
     *
     * @param  int    $commentId
     * @param  string $eventName
     * @return $this
     */
    public function withParams($commentId, $eventName)
    {
        $this->jobParams = array($commentId, $eventName);
        return $this;
    }

    /**
     * Execute job
     *
     * @param  int    $commentId
     * @param  string $eventName
     */
    public function execute($commentId, $eventName)
    {
        $event = CommentEventBuilder::getInstance($this->container)
            ->withCommentId($commentId)
            ->buildEvent();

        if ($event !== null) {
            $this->dispatcher->dispatch($eventName, $event);

            if ($eventName === CommentModel::EVENT_CREATE) {
                $userMentionJob = $this->userMentionJob->withParams($event['comment']['comment'], CommentModel::EVENT_USER_MENTION, $event);
                $this->queueManager->push($userMentionJob);
            }
        }
    }
}