2014-07-20 12:26:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Action;
|
|
|
|
|
2014-11-23 20:13:38 +01:00
|
|
|
use Model\GithubWebhook;
|
2014-07-20 12:26:15 +02:00
|
|
|
use Model\Task;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close automatically a task
|
|
|
|
*
|
|
|
|
* @package action
|
|
|
|
* @author Frederic Guillot
|
|
|
|
*/
|
|
|
|
class TaskClose extends Base
|
|
|
|
{
|
|
|
|
/**
|
2014-11-23 20:13:38 +01:00
|
|
|
* Get the list of compatible events
|
2014-07-20 12:26:15 +02:00
|
|
|
*
|
|
|
|
* @access public
|
2014-11-23 20:13:38 +01:00
|
|
|
* @return array
|
2014-07-20 12:26:15 +02:00
|
|
|
*/
|
2014-11-23 20:13:38 +01:00
|
|
|
public function getCompatibleEvents()
|
2014-07-20 12:26:15 +02:00
|
|
|
{
|
2014-11-23 20:13:38 +01:00
|
|
|
return array(
|
|
|
|
Task::EVENT_MOVE_COLUMN,
|
|
|
|
GithubWebhook::EVENT_COMMIT,
|
|
|
|
GithubWebhook::EVENT_ISSUE_CLOSED,
|
|
|
|
);
|
2014-07-20 12:26:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the required parameter for the action (defined by the user)
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getActionRequiredParameters()
|
|
|
|
{
|
2014-11-23 20:13:38 +01:00
|
|
|
switch ($this->event_name) {
|
|
|
|
case GithubWebhook::EVENT_COMMIT:
|
|
|
|
case GithubWebhook::EVENT_ISSUE_CLOSED:
|
|
|
|
return array();
|
|
|
|
default:
|
|
|
|
return array('column_id' => t('Column'));
|
|
|
|
}
|
2014-07-20 12:26:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the required parameter for the event
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return string[]
|
|
|
|
*/
|
|
|
|
public function getEventRequiredParameters()
|
|
|
|
{
|
2014-11-23 20:13:38 +01:00
|
|
|
switch ($this->event_name) {
|
|
|
|
case GithubWebhook::EVENT_COMMIT:
|
|
|
|
case GithubWebhook::EVENT_ISSUE_CLOSED:
|
|
|
|
return array('task_id');
|
|
|
|
default:
|
|
|
|
return array('task_id', 'column_id');
|
|
|
|
}
|
2014-07-20 12:26:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-11-23 20:13:38 +01:00
|
|
|
* Execute the action (close the task)
|
2014-07-20 12:26:15 +02:00
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param array $data Event data dictionary
|
|
|
|
* @return bool True if the action was executed or false when not executed
|
|
|
|
*/
|
|
|
|
public function doAction(array $data)
|
|
|
|
{
|
2014-11-23 20:13:38 +01:00
|
|
|
return $this->task->close($data['task_id']);
|
|
|
|
}
|
2014-07-20 12:26:15 +02:00
|
|
|
|
2014-11-23 20:13:38 +01:00
|
|
|
/**
|
|
|
|
* Check if the event data meet the action condition
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param array $data Event data dictionary
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasRequiredCondition(array $data)
|
|
|
|
{
|
|
|
|
switch ($this->event_name) {
|
|
|
|
case GithubWebhook::EVENT_COMMIT:
|
|
|
|
case GithubWebhook::EVENT_ISSUE_CLOSED:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return $data['column_id'] == $this->getParam('column_id');
|
|
|
|
}
|
2014-07-20 12:26:15 +02:00
|
|
|
}
|
|
|
|
}
|