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

fix(preferences): Remove unchangable activity preferences #1446

Merged
Merged
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
3 changes: 2 additions & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
More information is available in the Activity documentation.
</description>

<version>2.21.0</version>
<version>2.21.1</version>
<licence>agpl</licence>
<author>Frank Karlitschek</author>
<author>Joas Schilling</author>
Expand Down Expand Up @@ -41,6 +41,7 @@
<job>OCA\Activity\BackgroundJob\EmailNotification</job>
<job>OCA\Activity\BackgroundJob\ExpireActivities</job>
<job>OCA\Activity\BackgroundJob\DigestMail</job>
<job>OCA\Activity\BackgroundJob\RemoveFormerActivitySettings</job>
</background-jobs>

<commands>
Expand Down
72 changes: 72 additions & 0 deletions lib/BackgroundJob/RemoveFormerActivitySettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2023 Joas Schilling <[email protected]>
*
* @author Joas Schilling <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Activity\BackgroundJob;

use OCP\Activity\IExtension;
use OCP\Activity\IManager;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;

class RemoveFormerActivitySettings extends TimedJob {
public function __construct(
ITimeFactory $time,
protected IManager $manager,
protected IDBConnection $db,
) {
parent::__construct($time);
$this->setInterval(24 * 60 * 60);
}

protected function run($argument): void {
$preferencesToKeep = [
'notify_setting_activity_digest',
'notify_setting_batchtime',
'notify_setting_self',
'notify_setting_selfemail',
];
foreach ($this->manager->getSettings() as $setting) {
if ($setting->canChangeMail()) {
$preferencesToKeep[] = 'notify_' . IExtension::METHOD_MAIL . '_' . $setting->getIdentifier();
}
if ($setting->canChangeNotification()) {
$preferencesToKeep[] = 'notify_' . IExtension::METHOD_NOTIFICATION . '_' . $setting->getIdentifier();
}
}

$this->removeFormerPreference($preferencesToKeep);
}

protected function removeFormerPreference(array $preferencesToKeep): void {
$query = $this->db->getQueryBuilder();
$query->delete('preferences')
->where($query->expr()->eq('appid', $query->createNamedParameter('activity')))
->andWhere($query->expr()->like('configkey', $query->createNamedParameter($this->db->escapeLikeParameter('notify_') . '%')))
->andWhere($query->expr()->notIn('configkey', $query->createNamedParameter($preferencesToKeep, IQueryBuilder::PARAM_STR_ARRAY)));
$query->executeStatement();
}
}
Loading