Refactoring of internal task events
This commit is contained in:
@@ -17,59 +17,27 @@ class NotificationJob extends BaseJob
|
||||
*
|
||||
* @param GenericEvent $event
|
||||
* @param string $eventName
|
||||
* @param string $eventObjectName
|
||||
* @return $this
|
||||
*/
|
||||
public function withParams(GenericEvent $event, $eventName, $eventObjectName)
|
||||
public function withParams(GenericEvent $event, $eventName)
|
||||
{
|
||||
$this->jobParams = array($event->getAll(), $eventName, $eventObjectName);
|
||||
$this->jobParams = array($event->getAll(), $eventName);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute job
|
||||
*
|
||||
* @param array $event
|
||||
* @param array $eventData
|
||||
* @param string $eventName
|
||||
* @param string $eventObjectName
|
||||
*/
|
||||
public function execute(array $event, $eventName, $eventObjectName)
|
||||
public function execute(array $eventData, $eventName)
|
||||
{
|
||||
$eventData = $this->getEventData($event, $eventObjectName);
|
||||
|
||||
if (! empty($eventData)) {
|
||||
if (! empty($event['mention'])) {
|
||||
$this->userNotificationModel->sendUserNotification($event['mention'], $eventName, $eventData);
|
||||
} else {
|
||||
$this->userNotificationModel->sendNotifications($eventName, $eventData);
|
||||
$this->projectNotificationModel->sendNotifications($eventData['task']['project_id'], $eventName, $eventData);
|
||||
}
|
||||
if (! empty($eventData['mention'])) {
|
||||
$this->userNotificationModel->sendUserNotification($eventData['mention'], $eventName, $eventData);
|
||||
} else {
|
||||
$this->userNotificationModel->sendNotifications($eventName, $eventData);
|
||||
$this->projectNotificationModel->sendNotifications($eventData['task']['project_id'], $eventName, $eventData);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get event data
|
||||
*
|
||||
* @param array $event
|
||||
* @param string $eventObjectName
|
||||
* @return array
|
||||
*/
|
||||
public function getEventData(array $event, $eventObjectName)
|
||||
{
|
||||
$values = array();
|
||||
|
||||
if (! empty($event['changes'])) {
|
||||
$values['changes'] = $event['changes'];
|
||||
}
|
||||
|
||||
switch ($eventObjectName) {
|
||||
case 'Kanboard\Event\TaskEvent':
|
||||
$values['task'] = $this->taskFinderModel->getDetails($event['task_id']);
|
||||
break;
|
||||
default:
|
||||
$values = $event;
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
|
||||
75
app/Job/TaskEventJob.php
Normal file
75
app/Job/TaskEventJob.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Job;
|
||||
|
||||
use Kanboard\Event\TaskEvent;
|
||||
use Kanboard\EventBuilder\TaskEventBuilder;
|
||||
use Kanboard\Model\TaskModel;
|
||||
|
||||
/**
|
||||
* Class TaskEventJob
|
||||
*
|
||||
* @package Kanboard\Job
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class TaskEventJob extends BaseJob
|
||||
{
|
||||
/**
|
||||
* Set job params
|
||||
*
|
||||
* @param int $taskId
|
||||
* @param array $eventNames
|
||||
* @param array $changes
|
||||
* @param array $values
|
||||
* @param array $task
|
||||
* @return $this
|
||||
*/
|
||||
public function withParams($taskId, array $eventNames, array $changes = array(), array $values = array(), array $task = array())
|
||||
{
|
||||
$this->jobParams = array($taskId, $eventNames, $changes, $values, $task);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute job
|
||||
*
|
||||
* @param int $taskId
|
||||
* @param array $eventNames
|
||||
* @param array $changes
|
||||
* @param array $values
|
||||
* @param array $task
|
||||
* @return $this
|
||||
*/
|
||||
public function execute($taskId, array $eventNames, array $changes = array(), array $values = array(), array $task = array())
|
||||
{
|
||||
$event = TaskEventBuilder::getInstance($this->container)
|
||||
->withTaskId($taskId)
|
||||
->withChanges($changes)
|
||||
->withValues($values)
|
||||
->withTask($task)
|
||||
->build();
|
||||
|
||||
if ($event !== null) {
|
||||
foreach ($eventNames as $eventName) {
|
||||
$this->fireEvent($eventName, $event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger event
|
||||
*
|
||||
* @access protected
|
||||
* @param string $eventName
|
||||
* @param TaskEvent $event
|
||||
*/
|
||||
protected function fireEvent($eventName, TaskEvent $event)
|
||||
{
|
||||
$this->logger->debug(__METHOD__.' Event fired: '.$eventName);
|
||||
$this->dispatcher->dispatch($eventName, $event);
|
||||
|
||||
if ($eventName === TaskModel::EVENT_CREATE) {
|
||||
$this->userMentionModel->fireEvents($event['task']['description'], TaskModel::EVENT_USER_MENTION, $event);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user