From ff4a209d99f3ba72f73fb345b8a08709cfa84d82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Sat, 2 Jan 2016 11:13:51 +0100 Subject: [PATCH] More task deletion changes Completed tasks can be deleted by anyone after a configurable time unless they have reverse dependencies. --- includes/config-sample.inc.php | 3 +++ includes/t-data/dao_tasks.inc.php | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/includes/config-sample.inc.php b/includes/config-sample.inc.php index 4857c7d..c88e6be 100644 --- a/includes/config-sample.inc.php +++ b/includes/config-sample.inc.php @@ -5,3 +5,6 @@ $config[ 'core' ][ 'db' ][ 'user' ] = '...'; $config[ 'core' ][ 'db' ][ 'password' ] = '...'; $config[ 'core' ][ 'pages' ][ 'baseTitle' ] = 'Tasks'; + +/* Minimal time before a completed task can be deleted. The default is one week. */ +// $config[ 't-data' ][ 'minDeletionTime' ] = 7 * 3600 * 24; diff --git a/includes/t-data/dao_tasks.inc.php b/includes/t-data/dao_tasks.inc.php index 4191924..eafb798 100644 --- a/includes/t-data/dao_tasks.inc.php +++ b/includes/t-data/dao_tasks.inc.php @@ -2,6 +2,7 @@ class DAO_Tasks extends DAO + implements PackageAware { private static $priorities = array( '1' => 'Lowest' , @@ -11,6 +12,16 @@ class DAO_Tasks '5' => 'Very high' , ); + private $package; + + public function setPackage( Package $package ) + { + if ( $this->package !== null ) { + throw new Exception( 'trying to call setPackage() twice' ); + } + $this->package = $package; + } + public function translatePriority( $value ) { @@ -175,9 +186,11 @@ class DAO_Tasks public function canDelete( $task ) { if ( $task->completed_by !== null ) { + $minDeletionTime = $this->package->config( + 'minDeletionTime' , 7 * 3600 * 24 ); $ts = strtotime( $task->completed_at ); return empty( $task->reverseDependencies ) - && ( time() - $ts > 7 * 3600 * 24 ); + && ( time() - $ts > $minDeletionTime ); } return empty( $task->subtasks ) && empty( $task->reverseDependencies )