Skip to content

Commit

Permalink
Exclude certain users from activity expiration
Browse files Browse the repository at this point in the history
Signed-off-by: Akhil <[email protected]>
Co-authored-by: Louis <[email protected]>
  • Loading branch information
akhil1508 committed Apr 16, 2024
1 parent 5d0e920 commit fac1883
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
});

Expand Down
26 changes: 22 additions & 4 deletions lib/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -48,7 +49,9 @@ class Data {
public function __construct(
protected IManager $activityManager,
protected IDBConnection $connection,
protected LoggerInterface $logger) {
protected LoggerInterface $logger,
protected IConfig $config,
) {
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit fac1883

Please sign in to comment.