Skip to content

Commit

Permalink
fix(provisioning): Clean up orphaned accounts
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <[email protected]>
  • Loading branch information
ChristophWurst committed Oct 24, 2023
1 parent 246ba42 commit b088b96
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
18 changes: 18 additions & 0 deletions lib/Db/MailAccountMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,24 @@ public function deleteProvisionedAccountsByUid(string $uid): void {
$delete->executeStatement();
}

public function deleteProvisionedOrphanAccounts(): void {
$inner = $this->db->getQueryBuilder()
->select('id')
->from('mail_provisionings');

$delete = $this->db->getQueryBuilder();
$delete->delete($this->getTableName())
->where(
$delete->expr()->isNotNull('provisioning_id'),
$delete->expr()->notIn(
'provisioning_id',
$delete->createFunction($inner->getSQL()),
IQueryBuilder::PARAM_INT_ARRAY
));

$delete->executeStatement();
}

/**
* @return MailAccount[]
*/
Expand Down
9 changes: 7 additions & 2 deletions lib/Service/CleanupService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@

use OCA\Mail\Db\AliasMapper;
use OCA\Mail\Db\CollectedAddressMapper;
use OCA\Mail\Db\MailAccountMapper;
use OCA\Mail\Db\MailboxMapper;
use OCA\Mail\Db\MessageMapper;
use OCA\Mail\Db\MessageRetentionMapper;
use OCA\Mail\Db\MessageSnoozeMapper;
use OCA\Mail\Db\TagMapper;

class CleanupService {
private MailAccountMapper $mailAccountMapper;

/** @var AliasMapper */
private $aliasMapper;

Expand All @@ -50,10 +53,10 @@ class CleanupService {
private $tagMapper;

private MessageRetentionMapper $messageRetentionMapper;

private MessageSnoozeMapper $messageSnoozeMapper;

public function __construct(AliasMapper $aliasMapper,
public function __construct(MailAccountMapper $mailAccountMapper,
AliasMapper $aliasMapper,
MailboxMapper $mailboxMapper,
MessageMapper $messageMapper,
CollectedAddressMapper $collectedAddressMapper,
Expand All @@ -67,9 +70,11 @@ public function __construct(AliasMapper $aliasMapper,
$this->tagMapper = $tagMapper;
$this->messageRetentionMapper = $messageRetentionMapper;
$this->messageSnoozeMapper = $messageSnoozeMapper;
$this->mailAccountMapper = $mailAccountMapper;
}

public function cleanUp(): void {
$this->mailAccountMapper->deleteProvisionedOrphanAccounts();
$this->aliasMapper->deleteOrphans();
$this->mailboxMapper->deleteOrphans();
$this->messageMapper->deleteOrphans();
Expand Down

0 comments on commit b088b96

Please sign in to comment.