summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/Console/BaseCommand.php1
-rw-r--r--app/Console/ProjectActivityArchiveCommand.php21
-rw-r--r--app/Model/ProjectActivityModel.php18
-rw-r--r--app/ServiceProvider/CommandProvider.php2
-rw-r--r--app/constants.php2
5 files changed, 29 insertions, 15 deletions
diff --git a/app/Console/BaseCommand.php b/app/Console/BaseCommand.php
index 09059ecf..8ea67ae4 100644
--- a/app/Console/BaseCommand.php
+++ b/app/Console/BaseCommand.php
@@ -18,6 +18,7 @@ use Symfony\Component\Console\Command\Command;
* @property \Kanboard\Export\TransitionExport $transitionExport
* @property \Kanboard\Model\NotificationModel $notificationModel
* @property \Kanboard\Model\ProjectModel $projectModel
+ * @property \Kanboard\Model\ProjectActivityModel $projectActivityModel
* @property \Kanboard\Model\ProjectPermissionModel $projectPermissionModel
* @property \Kanboard\Model\ProjectDailyColumnStatsModel $projectDailyColumnStatsModel
* @property \Kanboard\Model\ProjectDailyStatsModel $projectDailyStatsModel
diff --git a/app/Console/ProjectActivityArchiveCommand.php b/app/Console/ProjectActivityArchiveCommand.php
new file mode 100644
index 00000000..18a4d7d7
--- /dev/null
+++ b/app/Console/ProjectActivityArchiveCommand.php
@@ -0,0 +1,21 @@
+<?php
+
+namespace Kanboard\Console;
+
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class ProjectActivityArchiveCommand extends BaseCommand
+{
+ protected function configure()
+ {
+ $this
+ ->setName('projects:archive-activities')
+ ->setDescription('Remove project activities after one year');
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $this->projectActivityModel->cleanup(strtotime('-1 year'));
+ }
+}
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();
}
}
diff --git a/app/ServiceProvider/CommandProvider.php b/app/ServiceProvider/CommandProvider.php
index 0c6ca5ee..70968306 100644
--- a/app/ServiceProvider/CommandProvider.php
+++ b/app/ServiceProvider/CommandProvider.php
@@ -11,6 +11,7 @@ use Kanboard\Console\LocaleSyncCommand;
use Kanboard\Console\PluginInstallCommand;
use Kanboard\Console\PluginUninstallCommand;
use Kanboard\Console\PluginUpgradeCommand;
+use Kanboard\Console\ProjectActivityArchiveCommand;
use Kanboard\Console\ProjectArchiveCommand;
use Kanboard\Console\ProjectDailyColumnStatsExportCommand;
use Kanboard\Console\ProjectDailyStatsCalculationCommand;
@@ -48,6 +49,7 @@ class CommandProvider implements ServiceProviderInterface
$application->add(new SubtaskExportCommand($container));
$application->add(new TaskExportCommand($container));
$application->add(new ProjectArchiveCommand($container));
+ $application->add(new ProjectActivityArchiveCommand($container));
$application->add(new ProjectDailyStatsCalculationCommand($container));
$application->add(new ProjectDailyColumnStatsExportCommand($container));
$application->add(new TransitionExportCommand($container));
diff --git a/app/constants.php b/app/constants.php
index 591d433a..7029ce03 100644
--- a/app/constants.php
+++ b/app/constants.php
@@ -148,7 +148,5 @@ defined('HTTP_VERIFY_SSL_CERTIFICATE') or define('HTTP_VERIFY_SSL_CERTIFICATE',
defined('TOTP_ISSUER') or define('TOTP_ISSUER', 'Kanboard');
-defined('PROJECT_ACTIVITIES_MAX_EVENTS') or define('PROJECT_ACTIVITIES_MAX_EVENTS', 10000);
-
// Comma separated list of fields to not synchronize when using external authentication providers
defined('EXTERNAL_AUTH_EXCLUDE_FIELDS') or define('EXTERNAL_AUTH_EXCLUDE_FIELDS', 'username');