KanboardPlugin-RemoveClosed.../Action/RemoveClosedTasks.php

94 lines
2.1 KiB
PHP
Raw Normal View History

<?php
namespace Kanboard\Plugin\RemoveClosedTasks\Action;
use Kanboard\Model\TaskModel;
use Kanboard\Action\Base;
/**
* Rename Task Title
*
* @package action
* @author Error
*/
class RemoveClosedTasks extends Base
{
/**
* Get automatic action description
*
* @access public
* @return string
*/
public function getDescription()
{
return t('Remove tasks once they have been closed for some time');
}
/**
* Get the list of compatible events
*
* @access public
* @return array
*/
public function getCompatibleEvents()
{
return array(TaskModel::EVENT_DAILY_CRONJOB);
}
/**
* Get the required parameter for the action (defined by the user)
*
* @access public
* @return array
*/
public function getActionRequiredParameters()
{
return array('age' => t('Threshold age in hours'));
}
/**
* Get the required parameter for the event
*
* @access public
* @return string[]
*/
public function getEventRequiredParameters()
{
return array('project_id');
}
/**
* Execute the action
*
* @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)
{
$result = true;
$threshold = $this->getParam('age') * 3600;
foreach ($this->taskFinderModel->getAll($data['project_id'], TaskModel::STATUS_CLOSED) as $task)
{
$closed_age = time() - $task['date_completed'];
if ($closed_age > $threshold)
{
$result = $this->taskModel->remove($task['id']) && $result;
}
}
return $result;
}
/**
* Check if the event data meet the action condition
*
* @access public
* @param array $data Event data dictionary
* @return bool
*/
public function hasRequiredCondition(array $data)
{
return true;
}
}