From 85783e45e92dcddd1402dfef23b6a6f902f866ea Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Tue, 8 Dec 2020 20:27:16 -0100 Subject: +ShareDeletedEvent Signed-off-by: Maxence Lange --- lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_static.php | 1 + lib/private/Share20/Manager.php | 2 + lib/public/Share/Events/ShareDeletedEvent.php | 80 +++++++++++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 lib/public/Share/Events/ShareDeletedEvent.php diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 282d8f402a9..4193aef1fda 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -477,6 +477,7 @@ return array( 'OCP\\Settings\\ISubAdminSettings' => $baseDir . '/lib/public/Settings/ISubAdminSettings.php', 'OCP\\Share' => $baseDir . '/lib/public/Share.php', 'OCP\\Share\\Events\\ShareCreatedEvent' => $baseDir . '/lib/public/Share/Events/ShareCreatedEvent.php', + 'OCP\\Share\\Events\\ShareDeletedEvent' => $baseDir . '/lib/public/Share/Events/ShareDeletedEvent.php', 'OCP\\Share\\Events\\VerifyMountPointEvent' => $baseDir . '/lib/public/Share/Events/VerifyMountPointEvent.php', 'OCP\\Share\\Exceptions\\GenericShareException' => $baseDir . '/lib/public/Share/Exceptions/GenericShareException.php', 'OCP\\Share\\Exceptions\\IllegalIDChangeException' => $baseDir . '/lib/public/Share/Exceptions/IllegalIDChangeException.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index bb11975d089..da56fe2d8b6 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -506,6 +506,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OCP\\Settings\\ISubAdminSettings' => __DIR__ . '/../../..' . '/lib/public/Settings/ISubAdminSettings.php', 'OCP\\Share' => __DIR__ . '/../../..' . '/lib/public/Share.php', 'OCP\\Share\\Events\\ShareCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/Share/Events/ShareCreatedEvent.php', + 'OCP\\Share\\Events\\ShareDeletedEvent' => __DIR__ . '/../../..' . '/lib/public/Share/Events/ShareDeletedEvent.php', 'OCP\\Share\\Events\\VerifyMountPointEvent' => __DIR__ . '/../../..' . '/lib/public/Share/Events/VerifyMountPointEvent.php', 'OCP\\Share\\Exceptions\\GenericShareException' => __DIR__ . '/../../..' . '/lib/public/Share/Exceptions/GenericShareException.php', 'OCP\\Share\\Exceptions\\IllegalIDChangeException' => __DIR__ . '/../../..' . '/lib/public/Share/Exceptions/IllegalIDChangeException.php', diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 0787f6d32aa..427b7b449ec 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -1168,6 +1168,8 @@ class Manager implements IManager { $provider = $this->factory->getProviderForType($share->getShareType()); $provider->delete($share); + $this->dispatcher->dispatchTyped(new Share\Events\ShareDeletedEvent($share, $deletedShares)); + // All the deleted shares caused by this delete $deletedShares[] = $share; diff --git a/lib/public/Share/Events/ShareDeletedEvent.php b/lib/public/Share/Events/ShareDeletedEvent.php new file mode 100644 index 00000000000..572b1238bce --- /dev/null +++ b/lib/public/Share/Events/ShareDeletedEvent.php @@ -0,0 +1,80 @@ + + * + * @author Maxence Lange + * + * @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 . + * + */ + +namespace OCP\Share\Events; + +use OCP\EventDispatcher\Event; +use OCP\Share\IShare; + +/** + * @since 21.0.0 + */ +class ShareDeletedEvent extends Event { + + /** @var IShare */ + private $share; + + /** @var array */ + private $children; + + /** + * @param IShare $share + * @param array $children + * + * @since 21.0.0 + */ + public function __construct(IShare $share, array $children = []) { + parent::__construct(); + + $this->share = $share; + $this->children = $children; + } + + /** + * @return IShare + * @since 21.0.0 + */ + public function getShare(): IShare { + return $this->share; + } + + /** + * @return IShare[] + * @since 21.0.0 + */ + public function getChildren(): array { + return $this->children; + } + + /** + * @return IShare[] + * @since 21.0.0 + */ + public function getAllDeletedShares(): array { + return array_merge([$this->share], $this->children); + } + +} -- cgit v1.2.3 From 874a1a4c43f6e67c56963bb8bc07761c80931cd0 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Tue, 8 Dec 2020 21:47:16 -0100 Subject: cs fix Signed-off-by: Maxence Lange --- lib/public/Share/Events/ShareDeletedEvent.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/public/Share/Events/ShareDeletedEvent.php b/lib/public/Share/Events/ShareDeletedEvent.php index 572b1238bce..4db0e6767e6 100644 --- a/lib/public/Share/Events/ShareDeletedEvent.php +++ b/lib/public/Share/Events/ShareDeletedEvent.php @@ -37,12 +37,13 @@ class ShareDeletedEvent extends Event { /** @var IShare */ private $share; - /** @var array */ + /** @var IShare[] */ private $children; /** + * * @param IShare $share - * @param array $children + * @param IShare[] $children * * @since 21.0.0 */ @@ -76,5 +77,4 @@ class ShareDeletedEvent extends Event { public function getAllDeletedShares(): array { return array_merge([$this->share], $this->children); } - } -- cgit v1.2.3 From e0bafb7475d34a4788e62c6485b7b090db284242 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 9 Dec 2020 13:51:59 -0100 Subject: deleteChildren only returns array Signed-off-by: Maxence Lange --- tests/lib/Share20/ManagerTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index efae909b99f..372f49ddf87 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -209,6 +209,8 @@ class ManagerTest extends \Test\TestCase { ->setMethods(['getShareById', 'deleteChildren']) ->getMock(); + $manager->method('deleteChildren')->willReturn([]); + $path = $this->createMock(File::class); $path->method('getId')->willReturn(1); @@ -254,6 +256,8 @@ class ManagerTest extends \Test\TestCase { ->setMethods(['getShareById', 'deleteChildren']) ->getMock(); + $manager->method('deleteChildren')->willReturn([]); + $share = $this->manager->newShare(); $share->setId(42) ->setProviderId('prov') -- cgit v1.2.3 From bb411c75c6a7272f62a8e6b97b92075477694a3c Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 23 Dec 2020 11:05:29 +0100 Subject: Move to single share event. Just emit more if needed Signed-off-by: Roeland Jago Douma --- lib/private/Share20/Manager.php | 3 ++- lib/public/Share/Events/ShareDeletedEvent.php | 22 +--------------------- 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 427b7b449ec..9a2b413896b 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -1138,6 +1138,7 @@ class Manager implements IManager { $deletedShares = array_merge($deletedShares, $deletedChildren); $provider->delete($child); + $this->dispatcher->dispatchTyped(new Share\Events\ShareDeletedEvent($child)); $deletedShares[] = $child; } @@ -1168,7 +1169,7 @@ class Manager implements IManager { $provider = $this->factory->getProviderForType($share->getShareType()); $provider->delete($share); - $this->dispatcher->dispatchTyped(new Share\Events\ShareDeletedEvent($share, $deletedShares)); + $this->dispatcher->dispatchTyped(new Share\Events\ShareDeletedEvent($share)); // All the deleted shares caused by this delete $deletedShares[] = $share; diff --git a/lib/public/Share/Events/ShareDeletedEvent.php b/lib/public/Share/Events/ShareDeletedEvent.php index 4db0e6767e6..4dca946aff3 100644 --- a/lib/public/Share/Events/ShareDeletedEvent.php +++ b/lib/public/Share/Events/ShareDeletedEvent.php @@ -37,9 +37,6 @@ class ShareDeletedEvent extends Event { /** @var IShare */ private $share; - /** @var IShare[] */ - private $children; - /** * * @param IShare $share @@ -47,11 +44,10 @@ class ShareDeletedEvent extends Event { * * @since 21.0.0 */ - public function __construct(IShare $share, array $children = []) { + public function __construct(IShare $share) { parent::__construct(); $this->share = $share; - $this->children = $children; } /** @@ -61,20 +57,4 @@ class ShareDeletedEvent extends Event { public function getShare(): IShare { return $this->share; } - - /** - * @return IShare[] - * @since 21.0.0 - */ - public function getChildren(): array { - return $this->children; - } - - /** - * @return IShare[] - * @since 21.0.0 - */ - public function getAllDeletedShares(): array { - return array_merge([$this->share], $this->children); - } } -- cgit v1.2.3