diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2022-01-27 21:26:39 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-27 21:26:39 +0300 |
commit | d5bcbf1ea5d5b9ed1db98cc6b21bfcbe78d0911c (patch) | |
tree | e1eb69118f48396384c84ca2192311f0fc9d057d | |
parent | f01417635e91ef244f115de86dc93cce12c3d7a5 (diff) | |
parent | 4b4a141552e1acc43b155e7e48e90e82ef89511d (diff) |
Merge pull request #921 from nextcloud/backport/911/stable22v22.2.4
[stable22] remove shares during circles destruction, clean orphan shares on cron
-rw-r--r-- | lib/AppInfo/Application.php | 5 | ||||
-rw-r--r-- | lib/Command/CirclesMaintenance.php | 1 | ||||
-rw-r--r-- | lib/Listeners/Files/DestroyingCircle.php | 82 | ||||
-rw-r--r-- | lib/Service/MaintenanceService.php | 17 | ||||
-rw-r--r-- | lib/Service/ShareWrapperService.php | 7 |
5 files changed, 103 insertions, 9 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index cda03a39..0e1c81bc 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -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(); diff --git a/lib/Command/CirclesMaintenance.php b/lib/Command/CirclesMaintenance.php index d9e97fcc..8e704d7a 100644 --- a/lib/Command/CirclesMaintenance.php +++ b/lib/Command/CirclesMaintenance.php @@ -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); diff --git a/lib/Listeners/Files/DestroyingCircle.php b/lib/Listeners/Files/DestroyingCircle.php new file mode 100644 index 00000000..81181e65 --- /dev/null +++ b/lib/Listeners/Files/DestroyingCircle.php @@ -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()); + } +} diff --git a/lib/Service/MaintenanceService.php b/lib/Service/MaintenanceService.php index 4f95ddf2..4d5f0a47 100644 --- a/lib/Service/MaintenanceService.php +++ b/lib/Service/MaintenanceService.php @@ -197,7 +197,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) { } @@ -209,13 +209,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) { } @@ -227,7 +227,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) { } @@ -239,21 +239,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) { } diff --git a/lib/Service/ShareWrapperService.php b/lib/Service/ShareWrapperService.php index 81bd5ece..78c32354 100644 --- a/lib/Service/ShareWrapperService.php +++ b/lib/Service/ShareWrapperService.php @@ -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 |