summaryrefslogtreecommitdiffstats
path: root/lib/private/share20/defaultshareprovider.php
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@owncloud.com>2015-11-10 14:14:49 +0100
committerRoeland Jago Douma <rullzer@owncloud.com>2015-11-23 12:28:54 +0100
commit1360e22d7c924f01c9eab1025271a3e84bd5b173 (patch)
tree8bf5c003e1db83f875fa439b934ad87283d5121c /lib/private/share20/defaultshareprovider.php
parentbf672d7e51bd3411130a3c3a41a931fb3d23ff68 (diff)
downloadnextcloud-server-1360e22d7c924f01c9eab1025271a3e84bd5b173.tar.gz
nextcloud-server-1360e22d7c924f01c9eab1025271a3e84bd5b173.zip
[Sharing 2.0] Move hook and delete children logic to share manager
To make sure hooks are always fired and child entries are always cleaned. This logic is moved to the share manager. * Updated unit tests
Diffstat (limited to 'lib/private/share20/defaultshareprovider.php')
-rw-r--r--lib/private/share20/defaultshareprovider.php53
1 files changed, 9 insertions, 44 deletions
diff --git a/lib/private/share20/defaultshareprovider.php b/lib/private/share20/defaultshareprovider.php
index 7f21d3aadf5..5805e41d411 100644
--- a/lib/private/share20/defaultshareprovider.php
+++ b/lib/private/share20/defaultshareprovider.php
@@ -69,19 +69,20 @@ class DefaultShareProvider implements IShareProvider {
}
/**
- * Get all childre of this share
+ * Get all children of this share
*
- * @param IShare $share
+ * @param IShare $parent
* @return IShare[]
*/
- private function getChildren(IShare $share) {
+ public function getChildren(IShare $parent) {
$children = [];
$qb = $this->dbConn->getQueryBuilder();
$qb->select('*')
->from('share')
->where($qb->expr()->eq('parent', $qb->createParameter('parent')))
- ->setParameter(':parent', $share->getId());
+ ->setParameter(':parent', $parent->getId())
+ ->orderBy('id');
$cursor = $qb->execute();
while($data = $cursor->fetch()) {
@@ -93,50 +94,15 @@ class DefaultShareProvider implements IShareProvider {
}
/**
- * Delete all the children of this share
- *
- * @param IShare $share
- */
- protected function deleteChildren(IShare $share) {
- foreach($this->getChildren($share) as $child) {
- $this->delete($child);
- }
- }
-
- /**
* Delete a share
*
- * @param Share $share
+ * @param IShare $share
* @throws BackendError
*/
public function delete(IShare $share) {
- $this->deleteChildren($share);
-
// Fetch share to make sure it exists
$share = $this->getShareById($share->getId());
- $shareType = $share->getShareType();
- $sharedWith = '';
- if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
- $sharedWith = $share->getSharedWith()->getUID();
- } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
- $sharedWith = $share->getSharedWith()->getGID();
- }
-
- $hookParams = [
- 'id' => $share->getId(),
- 'itemType' => $share->getPath() instanceof \OCP\Files\File ? 'file' : 'folder',
- 'itemSource' => $share->getPath()->getId(),
- 'shareType' => $shareType,
- 'shareWith' => $sharedWith,
- 'itemparent' => $share->getParent(),
- 'uidOwner' => $share->getSharedBy()->getUID(),
- 'fileSource' => $share->getPath()->getId(),
- 'fileTarget' => $share->getTarget()
- ];
-
- \OC_Hook::emit('OCP\Share', 'pre_unshare', $hookParams);
-
$qb = $this->dbConn->getQueryBuilder();
$qb->delete('share')
->where($qb->expr()->eq('id', $qb->createParameter('id')))
@@ -147,8 +113,6 @@ class DefaultShareProvider implements IShareProvider {
} catch (\Exception $e) {
throw new BackendError();
}
-
- \OC_Hook::emit('OCP\Share', 'post_unshare', $hookParams);
}
/**
@@ -195,8 +159,9 @@ class DefaultShareProvider implements IShareProvider {
/**
* Get shares for a given path
*
+ * @param \OCP\IUser $user
* @param \OCP\Files\Node $path
- * @param Share[]
+ * @return IShare[]
*/
public function getSharesByPath(\OCP\IUser $user, \OCP\Files\Node $path) {
throw new \Exception();
@@ -253,7 +218,7 @@ class DefaultShareProvider implements IShareProvider {
$share->setSharedBy($this->userManager->get($data['uid_owner']));
// TODO: getById can return an array. How to handle this properly??
- $path = $this->userFolder->getById($data['file_source']);
+ $path = $this->userFolder->getById((int)$data['file_source']);
$path = $path[0];
$share->setPath($path);