Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude specified users from activity expiration #1635

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
21 changes: 17 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,21 @@ 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) {
$conditions[] = [
'affecteduser' => [$user, '!=']
];
}
}

$this->deleteActivities($conditions);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion tests/DataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
use OCA\Activity\Data;
use OCP\Activity\IManager;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IConfig;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\IUserSession;
Expand Down Expand Up @@ -66,11 +68,13 @@ protected function setUp(): void {
$this->dbConnection = \OC::$server->get(IDBConnection::class);
$this->realActivityManager = \OC::$server->get(IManager::class);
$this->logger = \OC::$server->get(NullLogger::class);
$this->config = $this->createMock(IConfig::class);

$this->data = new Data(
$activityManager,
$this->dbConnection,
$this->logger
$this->logger,
$this->config
);
}

Expand Down
Loading