Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding a ShareDeletedEvent #24610

Merged
merged 4 commits into from
Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@
'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',
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,7 @@ protected function deleteChildren(IShare $share) {
$deletedShares = array_merge($deletedShares, $deletedChildren);

$provider->delete($child);
$this->dispatcher->dispatchTyped(new Share\Events\ShareDeletedEvent($child));
$deletedShares[] = $child;
}

Expand Down Expand Up @@ -1168,6 +1169,8 @@ public function deleteShare(IShare $share) {
$provider = $this->factory->getProviderForType($share->getShareType());
$provider->delete($share);

$this->dispatcher->dispatchTyped(new Share\Events\ShareDeletedEvent($share));

// All the deleted shares caused by this delete
$deletedShares[] = $share;

Expand Down
60 changes: 60 additions & 0 deletions lib/public/Share/Events/ShareDeletedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2020, Maxence Lange <maxence@artificial-owl.com>
*
* @author Maxence Lange <maxence@artificial-owl.com>
*
* @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 OCP\Share\Events;

use OCP\EventDispatcher\Event;
use OCP\Share\IShare;

/**
* @since 21.0.0
*/
class ShareDeletedEvent extends Event {

/** @var IShare */
private $share;

/**
*
* @param IShare $share
* @param IShare[] $children
*
* @since 21.0.0
*/
public function __construct(IShare $share) {
parent::__construct();

$this->share = $share;
}

/**
* @return IShare
* @since 21.0.0
*/
public function getShare(): IShare {
return $this->share;
}
}
4 changes: 4 additions & 0 deletions tests/lib/Share20/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ public function testDelete($shareType, $sharedWith) {
->setMethods(['getShareById', 'deleteChildren'])
->getMock();

$manager->method('deleteChildren')->willReturn([]);

$path = $this->createMock(File::class);
$path->method('getId')->willReturn(1);

Expand Down Expand Up @@ -254,6 +256,8 @@ public function testDeleteLazyShare() {
->setMethods(['getShareById', 'deleteChildren'])
->getMock();

$manager->method('deleteChildren')->willReturn([]);

$share = $this->manager->newShare();
$share->setId(42)
->setProviderId('prov')
Expand Down