Handle circle deletion event and add cleanup job
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
36
lib/Migration/DeletedCircleCleanup.php
Normal file
36
lib/Migration/DeletedCircleCleanup.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace OCA\Deck\Migration;
|
||||
|
||||
use OCA\Deck\Db\Acl;
|
||||
use OCA\Deck\Db\AclMapper;
|
||||
use OCA\Deck\Service\CirclesService;
|
||||
use OCP\Migration\IOutput;
|
||||
use OCP\Migration\IRepairStep;
|
||||
|
||||
class DeletedCircleCleanup implements IRepairStep {
|
||||
private AclMapper $aclMapper;
|
||||
private CirclesService $circleService;
|
||||
|
||||
public function __construct(AclMapper $aclMapper, CirclesService $circlesService) {
|
||||
$this->aclMapper = $aclMapper;
|
||||
$this->circleService = $circlesService;
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
return 'Cleanup Deck ACL entries for circles which have been already deleted';
|
||||
}
|
||||
|
||||
public function run(IOutput $output) {
|
||||
if (!$this->circleService->isCirclesEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->aclMapper->findByType(Acl::PERMISSION_TYPE_CIRCLE) as $acl) {
|
||||
if ($this->circleService->getCircle($acl->getParticipant()) === null) {
|
||||
$this->aclMapper->delete($acl);
|
||||
$output->info('Removed circle with id ' . $acl->getParticipant());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user