diff options
Diffstat (limited to 'app/Job')
-rw-r--r-- | app/Job/BaseJob.php | 33 | ||||
-rw-r--r-- | app/Job/EmailJob.php | 54 | ||||
-rw-r--r-- | app/Job/NotificationJob.php | 85 | ||||
-rw-r--r-- | app/Job/ProjectMetricJob.php | 40 |
4 files changed, 212 insertions, 0 deletions
diff --git a/app/Job/BaseJob.php b/app/Job/BaseJob.php new file mode 100644 index 00000000..60522ac6 --- /dev/null +++ b/app/Job/BaseJob.php @@ -0,0 +1,33 @@ +<?php + +namespace Kanboard\Job; + +use Kanboard\Core\Base; + +/** + * Class BaseJob + * + * @package Kanboard\Job + * @author Frederic Guillot + */ +abstract class BaseJob extends Base +{ + /** + * Job parameters + * + * @access protected + * @var array + */ + protected $jobParams = array(); + + /** + * Get job parameters + * + * @access public + * @return array + */ + public function getJobParams() + { + return $this->jobParams; + } +} diff --git a/app/Job/EmailJob.php b/app/Job/EmailJob.php new file mode 100644 index 00000000..9293a1d4 --- /dev/null +++ b/app/Job/EmailJob.php @@ -0,0 +1,54 @@ +<?php + +namespace Kanboard\Job; + +/** + * Class EmailJob + * + * @package Kanboard\Job + * @author Frederic Guillot + */ +class EmailJob extends BaseJob +{ + /** + * Set job parameters + * + * @access public + * @param string $email + * @param string $name + * @param string $subject + * @param string $html + * @param string $author + * @return $this + */ + public function withParams($email, $name, $subject, $html, $author) + { + $this->jobParams = array($email, $name, $subject, $html, $author); + return $this; + } + + /** + * Execute job + * + * @access public + * @param string $email + * @param string $name + * @param string $subject + * @param string $html + * @param string $author + */ + public function execute($email, $name, $subject, $html, $author) + { + $this->logger->debug(__METHOD__.' Sending email to '.$email.' via '.MAIL_TRANSPORT); + $startTime = microtime(true); + + $this->emailClient + ->getTransport(MAIL_TRANSPORT) + ->sendEmail($email, $name, $subject, $html, $author) + ; + + if (DEBUG) { + $this->logger->debug('Email sent in '.round(microtime(true) - $startTime, 6).' seconds'); + } + } +} diff --git a/app/Job/NotificationJob.php b/app/Job/NotificationJob.php new file mode 100644 index 00000000..d5fce222 --- /dev/null +++ b/app/Job/NotificationJob.php @@ -0,0 +1,85 @@ +<?php + +namespace Kanboard\Job; + +use Kanboard\Event\GenericEvent; + +/** + * Class NotificationJob + * + * @package Kanboard\Job + * @author Frederic Guillot + */ +class NotificationJob extends BaseJob +{ + /** + * Set job parameters + * + * @param GenericEvent $event + * @param string $eventName + * @param string $eventObjectName + * @return $this + */ + public function withParams(GenericEvent $event, $eventName, $eventObjectName) + { + $this->jobParams = array($event->getAll(), $eventName, $eventObjectName); + return $this; + } + + /** + * Execute job + * + * @param array $event + * @param string $eventName + * @param string $eventObjectName + */ + public function execute(array $event, $eventName, $eventObjectName) + { + $eventData = $this->getEventData($event, $eventObjectName); + + if (! empty($eventData)) { + if (! empty($event['mention'])) { + $this->userNotification->sendUserNotification($event['mention'], $eventName, $eventData); + } else { + $this->userNotification->sendNotifications($eventName, $eventData); + $this->projectNotification->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->taskFinder->getDetails($event['task_id']); + break; + case 'Kanboard\Event\SubtaskEvent': + $values['subtask'] = $this->subtask->getById($event['id'], true); + $values['task'] = $this->taskFinder->getDetails($values['subtask']['task_id']); + break; + case 'Kanboard\Event\FileEvent': + $values['file'] = $event; + $values['task'] = $this->taskFinder->getDetails($values['file']['task_id']); + break; + case 'Kanboard\Event\CommentEvent': + $values['comment'] = $this->comment->getById($event['id']); + $values['task'] = $this->taskFinder->getDetails($values['comment']['task_id']); + break; + } + + return $values; + } +} diff --git a/app/Job/ProjectMetricJob.php b/app/Job/ProjectMetricJob.php new file mode 100644 index 00000000..2c3e589c --- /dev/null +++ b/app/Job/ProjectMetricJob.php @@ -0,0 +1,40 @@ +<?php + +namespace Kanboard\Job; + +/** + * Class ProjectMetricJob + * + * @package Kanboard\Job + * @author Frederic Guillot + */ +class ProjectMetricJob extends BaseJob +{ + /** + * Set job parameters + * + * @access public + * @param integer $projectId + * @return $this + */ + public function withParams($projectId) + { + $this->jobParams = array($projectId); + return $this; + } + + /** + * Execute job + * + * @access public + * @param integer $projectId + */ + public function execute($projectId) + { + $this->logger->debug(__METHOD__.' Run project metrics calculation'); + $now = date('Y-m-d'); + + $this->projectDailyColumnStats->updateTotals($projectId, $now); + $this->projectDailyStats->updateTotals($projectId, $now); + } +} |