From 0f22a8db1d29b6be8ec13dcb92ba5f344f2a34f0 Mon Sep 17 00:00:00 2001
From: Roeland Jago Douma <rullzer@owncloud.com>
Date: Thu, 4 Feb 2016 14:28:09 +0100
Subject: Also add type (file/folder) to IShare object

We need this for the hooks :(
---
 lib/private/share20/defaultshareprovider.php |  1 +
 lib/private/share20/manager.php              |  6 ++---
 lib/private/share20/share.php                | 37 ++++++++++++++++++++++++++++
 lib/public/share/ishare.php                  | 26 +++++++++++++++++++
 4 files changed, 67 insertions(+), 3 deletions(-)

(limited to 'lib')

diff --git a/lib/private/share20/defaultshareprovider.php b/lib/private/share20/defaultshareprovider.php
index 48164a5d419..0ab0dc81fa7 100644
--- a/lib/private/share20/defaultshareprovider.php
+++ b/lib/private/share20/defaultshareprovider.php
@@ -745,6 +745,7 @@ class DefaultShareProvider implements IShareProvider {
 		}
 
 		$share->setNodeId((int)$data['file_source']);
+		$share->setNodeType($data['item_type']);
 
 		if ($data['expiration'] !== null) {
 			$expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);
diff --git a/lib/private/share20/manager.php b/lib/private/share20/manager.php
index 3db76d92ac7..6ea638b84e6 100644
--- a/lib/private/share20/manager.php
+++ b/lib/private/share20/manager.php
@@ -663,13 +663,13 @@ class Manager implements IManager {
 
 			$hookParams = [
 				'id'         => $share->getId(),
-				'itemType'   => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
-				'itemSource' => $share->getNode()->getId(),
+				'itemType'   => $share->getNodeType(),
+				'itemSource' => $share->getNodeId(),
 				'shareType'  => $shareType,
 				'shareWith'  => $sharedWith,
 				'itemparent' => $share->getParent(),
 				'uidOwner'   => $share->getSharedBy(),
-				'fileSource' => $share->getNode()->getId(),
+				'fileSource' => $share->getNodeId(),
 				'fileTarget' => $share->getTarget()
 			];
 			return $hookParams;
diff --git a/lib/private/share20/share.php b/lib/private/share20/share.php
index 5b7945b1da8..448b05d20a3 100644
--- a/lib/private/share20/share.php
+++ b/lib/private/share20/share.php
@@ -20,6 +20,7 @@
  */
 namespace OC\Share20;
 
+use OCP\Files\File;
 use OCP\Files\IRootFolder;
 use OCP\Files\Node;
 use OCP\Files\NotFoundException;
@@ -36,6 +37,8 @@ class Share implements \OCP\Share\IShare {
 	private $node;
 	/** @var int */
 	private $fileId;
+	/** @var string */
+	private $nodeType;
 	/** @var int */
 	private $shareType;
 	/** @var string */
@@ -138,6 +141,40 @@ class Share implements \OCP\Share\IShare {
 		return $this;
 	}
 
+	/**
+	 * @inheritdoc
+	 */
+	public function getNodeId() {
+		if ($this->fileId === null) {
+			$this->fileId = $this->getNode()->getId();
+		}
+
+		return $this->fileId;
+	}
+
+	/**
+	 * @inheritdoc
+	 */
+	public function setNodeType($type) {
+		if ($type !== 'file' && $type !== 'folder') {
+			throw new \InvalidArgumentException();
+		}
+
+		$this->nodeType = $type;
+	}
+
+	/**
+	 * @inheritdoc
+	 */
+	public function getNodeType() {
+		if ($this->nodeType === null) {
+			$node = $this->getNode();
+			$this->nodeType = $node instanceof File ? 'file' : 'folder';
+		}
+
+		return $this->nodeType;
+	}
+
 	/**
 	 * @inheritdoc
 	 */
diff --git a/lib/public/share/ishare.php b/lib/public/share/ishare.php
index 074f4117584..5054a886af5 100644
--- a/lib/public/share/ishare.php
+++ b/lib/public/share/ishare.php
@@ -77,6 +77,32 @@ interface IShare {
 	 */
 	public function setNodeId($fileId);
 
+	/**
+	 * Get the fileid of the node of this share
+	 * @return int
+	 * @since 9.0.0
+	 * @throws NotFoundException
+	 */
+	public function getNodeId();
+
+	/**
+	 * Set the type of node (file/folder)
+	 *
+	 * @param string $type
+	 * @return \OCP\Share\IShare The modified object
+	 * @since 9.0.0
+	 */
+	public function setNodeType($type);
+
+	/**
+	 * Get the type of node (file/folder)
+	 *
+	 * @return string
+	 * @since 9.0.0
+	 * @throws NotFoundException
+	 */
+	public function getNodeType();
+
 	/**
 	 * Set the shareType
 	 *
-- 
cgit v1.2.3