看板初始化提交
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,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($event, $eventName);
|
||||
|
||||
if ($eventName === CommentModel::EVENT_CREATE) {
|
||||
$userMentionJob = $this->userMentionJob->withParams($event['comment']['comment'], CommentModel::EVENT_USER_MENTION, $event);
|
||||
$this->queueManager->push($userMentionJob);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Job;
|
||||
|
||||
/**
|
||||
* Class EmailJob
|
||||
*
|
||||
* @package Kanboard\Job
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class EmailJob extends BaseJob
|
||||
{
|
||||
/**
|
||||
* Set job parameters
|
||||
*
|
||||
* @access public
|
||||
* @param string $recipientEmail
|
||||
* @param string $recipientName
|
||||
* @param string $subject
|
||||
* @param string $html
|
||||
* @param string $authorName
|
||||
* @param string $authorEmail
|
||||
* @return $this
|
||||
*/
|
||||
public function withParams($recipientEmail, $recipientName, $subject, $html, $authorName, $authorEmail)
|
||||
{
|
||||
$this->jobParams = array($recipientEmail, $recipientName, $subject, $html, $authorName, $authorEmail);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute job
|
||||
*
|
||||
* @access public
|
||||
* @param string $recipientEmail
|
||||
* @param string $recipientName
|
||||
* @param string $subject
|
||||
* @param string $html
|
||||
* @param string $authorName
|
||||
* @param string $authorEmail
|
||||
*/
|
||||
public function execute($recipientEmail, $recipientName, $subject, $html, $authorName, $authorEmail)
|
||||
{
|
||||
$transport = $this->helper->mail->getMailTransport();
|
||||
$startTime = microtime(true);
|
||||
|
||||
$this->logger->debug(__METHOD__.' Sending email to: '.$recipientEmail.' using transport: '.$transport);
|
||||
|
||||
$this->emailClient
|
||||
->getTransport($transport)
|
||||
->sendEmail($recipientEmail, $recipientName, $subject, $html, $authorName, $authorEmail);
|
||||
|
||||
$this->logger->debug(__METHOD__.' Email sent in '.round(microtime(true) - $startTime, 6).' seconds');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Job;
|
||||
|
||||
/**
|
||||
* Async HTTP Client (fire and forget)
|
||||
*
|
||||
* @package Kanboard\Job
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class HttpAsyncJob extends BaseJob
|
||||
{
|
||||
/**
|
||||
* Set job parameters
|
||||
*
|
||||
* @access public
|
||||
* @param string $method
|
||||
* @param string $url
|
||||
* @param string $content
|
||||
* @param array $headers
|
||||
* @param bool $raiseForErrors
|
||||
* @return $this
|
||||
*/
|
||||
public function withParams($method, $url, $content, array $headers, $raiseForErrors = false)
|
||||
{
|
||||
$this->jobParams = array($method, $url, $content, $headers, $raiseForErrors);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set job parameters
|
||||
*
|
||||
* @access public
|
||||
* @param string $method
|
||||
* @param string $url
|
||||
* @param string $content
|
||||
* @param array $headers
|
||||
* @param bool $raiseForErrors
|
||||
*/
|
||||
public function execute($method, $url, $content, array $headers, $raiseForErrors = false)
|
||||
{
|
||||
$this->httpClient->doRequest($method, $url, $content, $headers, $raiseForErrors);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?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
|
||||
* @return $this
|
||||
*/
|
||||
public function withParams(GenericEvent $event, $eventName)
|
||||
{
|
||||
$this->jobParams = array($event->getAll(), $eventName);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute job
|
||||
*
|
||||
* @param array $eventData
|
||||
* @param string $eventName
|
||||
*/
|
||||
public function execute(array $eventData, $eventName)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Job;
|
||||
|
||||
use Kanboard\EventBuilder\ProjectFileEventBuilder;
|
||||
|
||||
/**
|
||||
* Class ProjectFileEventJob
|
||||
*
|
||||
* @package Kanboard\Job
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class ProjectFileEventJob extends BaseJob
|
||||
{
|
||||
/**
|
||||
* Set job params
|
||||
*
|
||||
* @param int $fileId
|
||||
* @param string $eventName
|
||||
* @return $this
|
||||
*/
|
||||
public function withParams($fileId, $eventName)
|
||||
{
|
||||
$this->jobParams = array($fileId, $eventName);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute job
|
||||
*
|
||||
* @param int $fileId
|
||||
* @param string $eventName
|
||||
*/
|
||||
public function execute($fileId, $eventName)
|
||||
{
|
||||
$event = ProjectFileEventBuilder::getInstance($this->container)
|
||||
->withFileId($fileId)
|
||||
->buildEvent();
|
||||
|
||||
if ($event !== null) {
|
||||
$this->dispatcher->dispatch($event, $eventName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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->projectDailyColumnStatsModel->updateTotals($projectId, $now);
|
||||
$this->projectDailyStatsModel->updateTotals($projectId, $now);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Job;
|
||||
|
||||
use Kanboard\EventBuilder\SubtaskEventBuilder;
|
||||
|
||||
/**
|
||||
* Class SubtaskEventJob
|
||||
*
|
||||
* @package Kanboard\Job
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class SubtaskEventJob extends BaseJob
|
||||
{
|
||||
/**
|
||||
* Set job params
|
||||
*
|
||||
* @param int $subtaskId
|
||||
* @param array $eventNames
|
||||
* @param array $values
|
||||
* @return $this
|
||||
*/
|
||||
public function withParams($subtaskId, array $eventNames, array $values = array())
|
||||
{
|
||||
$this->jobParams = array($subtaskId, $eventNames, $values);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute job
|
||||
*
|
||||
* @param int $subtaskId
|
||||
* @param array $eventNames
|
||||
* @param array $values
|
||||
*/
|
||||
public function execute($subtaskId, array $eventNames, array $values = array())
|
||||
{
|
||||
$event = SubtaskEventBuilder::getInstance($this->container)
|
||||
->withSubtaskId($subtaskId)
|
||||
->withValues($values)
|
||||
->buildEvent();
|
||||
|
||||
if ($event !== null) {
|
||||
foreach ($eventNames as $eventName) {
|
||||
$this->dispatcher->dispatch($event, $eventName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
*/
|
||||
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)
|
||||
->buildEvent();
|
||||
|
||||
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($event, $eventName);
|
||||
|
||||
if ($eventName === TaskModel::EVENT_CREATE) {
|
||||
$userMentionJob = $this->userMentionJob->withParams($event['task']['description'], TaskModel::EVENT_USER_MENTION, $event);
|
||||
$this->queueManager->push($userMentionJob);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Job;
|
||||
|
||||
use Kanboard\EventBuilder\TaskFileEventBuilder;
|
||||
|
||||
/**
|
||||
* Class TaskFileEventJob
|
||||
*
|
||||
* @package Kanboard\Job
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class TaskFileEventJob extends BaseJob
|
||||
{
|
||||
/**
|
||||
* Set job params
|
||||
*
|
||||
* @param int $fileId
|
||||
* @param string $eventName
|
||||
* @return $this
|
||||
*/
|
||||
public function withParams($fileId, $eventName)
|
||||
{
|
||||
$this->jobParams = array($fileId, $eventName);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute job
|
||||
*
|
||||
* @param int $fileId
|
||||
* @param string $eventName
|
||||
*/
|
||||
public function execute($fileId, $eventName)
|
||||
{
|
||||
$event = TaskFileEventBuilder::getInstance($this->container)
|
||||
->withFileId($fileId)
|
||||
->buildEvent();
|
||||
|
||||
if ($event !== null) {
|
||||
$this->dispatcher->dispatch($event, $eventName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Job;
|
||||
|
||||
use Kanboard\EventBuilder\TaskLinkEventBuilder;
|
||||
|
||||
/**
|
||||
* Class TaskLinkEventJob
|
||||
*
|
||||
* @package Kanboard\Job
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class TaskLinkEventJob extends BaseJob
|
||||
{
|
||||
/**
|
||||
* Set job params
|
||||
*
|
||||
* @param int $taskLinkId
|
||||
* @param string $eventName
|
||||
* @return $this
|
||||
*/
|
||||
public function withParams($taskLinkId, $eventName)
|
||||
{
|
||||
$this->jobParams = array($taskLinkId, $eventName);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute job
|
||||
*
|
||||
* @param int $taskLinkId
|
||||
* @param string $eventName
|
||||
*/
|
||||
public function execute($taskLinkId, $eventName)
|
||||
{
|
||||
$event = TaskLinkEventBuilder::getInstance($this->container)
|
||||
->withTaskLinkId($taskLinkId)
|
||||
->buildEvent();
|
||||
|
||||
if ($event !== null) {
|
||||
$this->dispatcher->dispatch($event, $eventName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Job;
|
||||
|
||||
use Kanboard\Event\GenericEvent;
|
||||
use Kanboard\Model\UserModel;
|
||||
|
||||
/**
|
||||
* Class UserMentionJob
|
||||
*
|
||||
* @package Kanboard\Job
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class UserMentionJob extends BaseJob
|
||||
{
|
||||
/**
|
||||
* Set job parameters
|
||||
*
|
||||
* @param string $text
|
||||
* @param string $eventName
|
||||
* @param GenericEvent $event
|
||||
* @return $this
|
||||
*/
|
||||
public function withParams($text, $eventName, GenericEvent $event)
|
||||
{
|
||||
$this->jobParams = array($text, $eventName, $event->getAll());
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute job
|
||||
*
|
||||
* @param string $text
|
||||
* @param string $eventName
|
||||
* @param array $eventData
|
||||
*/
|
||||
public function execute($text, $eventName, array $eventData)
|
||||
{
|
||||
$event = new GenericEvent($eventData);
|
||||
$users = $this->getMentionedUsers($text);
|
||||
|
||||
foreach ($users as $user) {
|
||||
if ($this->projectPermissionModel->isMember($event->getProjectId(), $user['id'])) {
|
||||
$event['mention'] = $user;
|
||||
$this->dispatcher->dispatch($event, $eventName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of mentioned users
|
||||
*
|
||||
* @access public
|
||||
* @param string $text
|
||||
* @return array
|
||||
*/
|
||||
public function getMentionedUsers($text)
|
||||
{
|
||||
$users = array();
|
||||
|
||||
if ($text !== null && preg_match_all('/@([^\s,!:?]+)/', $text, $matches)) {
|
||||
array_walk($matches[1], function (&$username) {
|
||||
$username = rtrim($username, '.');
|
||||
});
|
||||
$users = $this->db->table(UserModel::TABLE)
|
||||
->columns('id', 'username', 'name', 'email', 'language')
|
||||
->eq('notifications_enabled', 1)
|
||||
->neq('id', $this->userSession->getId())
|
||||
->in('username', array_unique($matches[1]))
|
||||
->findAll();
|
||||
}
|
||||
|
||||
return $users;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user