Skip to content

Commit

Permalink
Merge pull request #1583 from nextcloud/bugfix/1572/delete-settings-o…
Browse files Browse the repository at this point in the history
…n-user-deletion

fix(settings): Delete settings when a user is deleted
  • Loading branch information
nickvergessen authored Jun 21, 2023
2 parents e05ba30 + b0b3a38 commit be44291
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/Listener/UserDeletedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/**
* @copyright Copyright (c) 2020, Daniel Kesselberg <mail@danielkesselberg.de>
*
* @author Joas Schilling <coding@schilljs.com>
* @author Daniel Kesselberg <mail@danielkesselberg.de>
*
* @license AGPL-3.0-or-later
Expand All @@ -27,6 +28,7 @@
namespace OCA\Notifications\Listener;

use OCA\Notifications\Handler;
use OCA\Notifications\Model\SettingsMapper;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\User\Events\UserDeletedEvent;
Expand All @@ -36,9 +38,14 @@
*/
class UserDeletedListener implements IEventListener {
private Handler $handler;
private SettingsMapper $settingsMapper;

public function __construct(Handler $handler) {
public function __construct(
Handler $handler,
SettingsMapper $settingsMapper,
) {
$this->handler = $handler;
$this->settingsMapper = $settingsMapper;
}

public function handle(Event $event): void {
Expand All @@ -49,5 +56,6 @@ public function handle(Event $event): void {

$user = $event->getUser();
$this->handler->deleteByUser($user->getUID());
$this->settingsMapper->deleteSettingsByUser($user->getUID());
}
}
13 changes: 13 additions & 0 deletions lib/Model/SettingsMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ public function getSettingsByUser(string $userId): Settings {
return $this->findEntity($query);
}

/**
* @param string $userId
* @throws DBException
*/
public function deleteSettingsByUser(string $userId): void {
$query = $this->db->getQueryBuilder();

$query->delete($this->getTableName())
->where($query->expr()->eq('user_id', $query->createNamedParameter($userId)));

$query->executeStatement();
}

public function setBatchSettingForUser(string $userId, int $batchSetting): void {
try {
$settings = $this->getSettingsByUser($userId);
Expand Down

0 comments on commit be44291

Please sign in to comment.