remove shares during circles destruction, clean orphan shares on cron

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
This commit is contained in:
Maxence Lange 2022-01-20 16:20:21 -01:00
parent 8d45443c01
commit ef8cc805b2
5 changed files with 103 additions and 9 deletions

View file

@ -38,6 +38,7 @@ use Closure;
use OC;
use OCA\Circles\Events\AddingCircleMemberEvent;
use OCA\Circles\Events\CircleMemberAddedEvent;
use OCA\Circles\Events\DestroyingCircleEvent;
use OCA\Circles\Events\Files\CreatingFileShareEvent;
use OCA\Circles\Events\Files\FileShareCreatedEvent;
use OCA\Circles\Events\Files\PreparingFileShareEvent;
@ -54,9 +55,10 @@ use OCA\Circles\Listeners\Examples\ExampleMembershipsRemoved;
use OCA\Circles\Listeners\Examples\ExampleRequestingCircleMember;
use OCA\Circles\Listeners\Files\AddingMemberSendMail as ListenerFilesAddingMemberSendMail;
use OCA\Circles\Listeners\Files\CreatingShareSendMail as ListenerFilesCreatingShareSendMail;
use OCA\Circles\Listeners\Files\PreparingShareSendMail as ListenerFilesPreparingShareSendMail;
use OCA\Circles\Listeners\Files\DestroyingCircle as ListenerFilesDestroyingCircle;
use OCA\Circles\Listeners\Files\MemberAddedSendMail as ListenerFilesMemberAddedSendMail;
use OCA\Circles\Listeners\Files\PreparingMemberSendMail as ListenerFilesPreparingMemberSendMail;
use OCA\Circles\Listeners\Files\PreparingShareSendMail as ListenerFilesPreparingShareSendMail;
use OCA\Circles\Listeners\Files\RemovingMember as ListenerFilesRemovingMember;
use OCA\Circles\Listeners\Files\ShareCreatedSendMail as ListenerFilesShareCreatedSendMail;
use OCA\Circles\Listeners\GroupCreated;
@ -174,6 +176,7 @@ class Application extends App implements IBootstrap {
RequestingCircleMemberEvent::class,
ListenerNotificationsRequestingMember::class
);
$context->registerEventListener(DestroyingCircleEvent::class, ListenerFilesDestroyingCircle::class);
// It seems that AccountManager use deprecated dispatcher, let's use a deprecated listener
$dispatcher = OC::$server->getEventDispatcher();

View file

@ -155,6 +155,7 @@ class CirclesMaintenance extends Base {
}
$this->outputService->setOccOutput($output);
$this->maintenanceService->setOccOutput($output);
for ($i = 1; $i <= $level; $i++) {
try {
$this->maintenanceService->runMaintenance($i);

View file

@ -0,0 +1,82 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2021
* @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\Circles\Listeners\Files;
use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger;
use ArtificialOwl\MySmallPhpTools\Traits\TStringTools;
use OCA\Circles\AppInfo\Application;
use OCA\Circles\Events\DestroyingCircleEvent;
use OCA\Circles\Exceptions\RequestBuilderException;
use OCA\Circles\Service\ShareWrapperService;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
/**
* Class AddingMemberSendMail
*
* @package OCA\Circles\Listeners\Files
*/
class DestroyingCircle implements IEventListener {
use TStringTools;
use TNC22Logger;
/** @var ShareWrapperService */
private $shareWrapperService;
/**
* AddingMember constructor.
*
* @param ShareWrapperService $shareWrapperService
*/
public function __construct(ShareWrapperService $shareWrapperService) {
$this->shareWrapperService = $shareWrapperService;
$this->setup('app', Application::APP_ID);
}
/**
* @param Event $event
*
* @throws RequestBuilderException
*/
public function handle(Event $event): void {
if (!$event instanceof DestroyingCircleEvent) {
return;
}
$circle = $event->getCircle();
$this->shareWrapperService->deleteSharesToCircle($circle->getSingleId());
}
}

View file

@ -191,7 +191,7 @@ class MaintenanceService {
*/
private function runMaintenance1(): void {
try {
$this->output('remove circles with no owner');
$this->output('Remove circles with no owner');
$this->removeCirclesWithNoOwner();
} catch (Exception $e) {
}
@ -203,13 +203,13 @@ class MaintenanceService {
*/
private function runMaintenance2(): void {
try {
$this->output('remove members with no circles');
$this->output('Remove members with no circles');
$this->removeMembersWithNoCircles();
} catch (Exception $e) {
}
try {
$this->output('retry failed FederatedEvents (asap)');
$this->output('Retry failed FederatedEvents (asap)');
$this->eventWrapperService->retry(EventWrapperService::RETRY_ASAP);
} catch (Exception $e) {
}
@ -221,7 +221,7 @@ class MaintenanceService {
*/
private function runMaintenance3(): void {
try {
$this->output('retry failed FederatedEvents (hourly)');
$this->output('Retry failed FederatedEvents (hourly)');
$this->eventWrapperService->retry(EventWrapperService::RETRY_HOURLY);
} catch (Exception $e) {
}
@ -233,21 +233,22 @@ class MaintenanceService {
*/
private function runMaintenance4(): void {
try {
$this->output('retry failed FederatedEvents (daily)');
$this->output('Retry failed FederatedEvents (daily)');
$this->eventWrapperService->retry(EventWrapperService::RETRY_DAILY);
} catch (Exception $e) {
}
try {
// TODO: waiting for confirmation of a good migration before cleaning orphan shares
if ($this->configService->getAppValue(ConfigService::MIGRATION_22_CONFIRMED)) {
$this->output('remove deprecated shares');
if ($this->configService->getAppValueBool(ConfigService::MIGRATION_22_CONFIRMED)) {
$this->output('Remove deprecated shares');
$this->removeDeprecatedShares();
}
} catch (Exception $e) {
}
try {
$this->output('synchronizing local entities');
$this->output('Synchronizing local entities');
$this->syncService->sync();
} catch (Exception $e) {
}

View file

@ -102,6 +102,13 @@ class ShareWrapperService {
$this->shareWrapperRequest->delete((int)$shareWrapper->getId());
}
/**
* @param string $circleId
*/
public function deleteSharesToCircle(string $circleId) {
$this->shareWrapperRequest->deleteFromCircle($circleId);
}
/**
* @param string $circleId