diff options
author | Frédéric Guillot <fred@kanboard.net> | 2017-12-01 11:54:02 -0800 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2017-12-01 11:54:02 -0800 |
commit | 0153cb33dede09a0167d490204bdf10151ed15cc (patch) | |
tree | 74ead58a5060b423b05a60114bd5b7e33828f3e6 /app/Model | |
parent | 0573c92d09544799f6f517e60ca2a0fa7c0fb0f3 (diff) |
Add command to remove project activities after one year
Diffstat (limited to 'app/Model')
-rw-r--r-- | app/Model/ProjectActivityModel.php | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/app/Model/ProjectActivityModel.php b/app/Model/ProjectActivityModel.php index 17cf6485..739fd787 100644 --- a/app/Model/ProjectActivityModel.php +++ b/app/Model/ProjectActivityModel.php @@ -33,17 +33,14 @@ class ProjectActivityModel extends Base */ public function createEvent($project_id, $task_id, $creator_id, $event_name, array $data) { - $values = array( + return $this->db->table(self::TABLE)->insert(array( 'project_id' => $project_id, 'task_id' => $task_id, 'creator_id' => $creator_id, 'event_name' => $event_name, 'date_creation' => time(), 'data' => json_encode($data), - ); - - $this->cleanup(PROJECT_ACTIVITIES_MAX_EVENTS - 1); - return $this->db->table(self::TABLE)->insert($values); + )); } /** @@ -73,15 +70,10 @@ class ProjectActivityModel extends Base * Remove old event entries to avoid large table * * @access public - * @param integer $max Maximum number of items to keep in the table + * @param integer $ts Timestamp */ - public function cleanup($max) + public function cleanup($ts) { - $total = $this->db->table(self::TABLE)->count(); - - if ($total > $max) { - $ids = $this->db->table(self::TABLE)->asc('id')->limit($total - $max)->findAllByColumn('id'); - $this->db->table(self::TABLE)->in('id', $ids)->remove(); - } + $this->db->table(self::TABLE)->lt('date_creation', $ts)->remove(); } } |