diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 1d6e02294..319445cd3 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -115,6 +115,7 @@ public function register(IRegistrationContext $context): void { $c->get(IManager::class), $c->get('ActivityConnectionAdapter'), $c->get(LoggerInterface::class), + $c->get(IConfig::class), ); }); diff --git a/lib/Data.php b/lib/Data.php index 2f07c722d..9f6a7648b 100755 --- a/lib/Data.php +++ b/lib/Data.php @@ -33,6 +33,7 @@ use OCP\Activity\IFilter; use OCP\Activity\IManager; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\IConfig; use OCP\IDBConnection; use Psr\Log\LoggerInterface; @@ -48,7 +49,9 @@ class Data { public function __construct( protected IManager $activityManager, protected IDBConnection $connection, - protected LoggerInterface $logger) { + protected LoggerInterface $logger, + protected IConfig $config, + ) { } /** @@ -347,11 +350,26 @@ public function validateFilter($filterValue) { */ public function expire($expireDays = 365) { $ttl = (60 * 60 * 24 * max(1, $expireDays)); - $timelimit = time() - $ttl; - $this->deleteActivities([ + $conditions = [ 'timestamp' => [$timelimit, '<'], - ]); + ]; + + $excludedUsers = $this->config->getSystemValue('activity_expire_exclude_users', []); + if (!empty($excludedUsers)) { + foreach ($excludedUsers as $user) { + $condition1 = [ + 'user' => [$user, '!='] + ]; + $condition2 = [ + 'affecteduser' => [$user, '!='] + ]; + $conditions[] = $condition1; + $conditions[] = $condition2; + } + } + + $this->deleteActivities($conditions); } /**