diff options
Diffstat (limited to 'lib/public/share.php')
-rw-r--r-- | lib/public/share.php | 67 |
1 files changed, 46 insertions, 21 deletions
diff --git a/lib/public/share.php b/lib/public/share.php index caa274b8579..6b3397c85c6 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -244,7 +244,9 @@ class Share { * Get the items of item type shared with the current user * @param string Item type * @param int Format (optional) Format type must be defined by the backend + * @param mixed Parameters (optional) * @param int Number of items to return (optional) Returns all by default + * @param bool include collections (optional) * @return Return depends on format */ public static function getItemsSharedWith($itemType, $format = self::FORMAT_NONE, @@ -256,8 +258,10 @@ class Share { /** * Get the item of item type shared with the current user * @param string $itemType - * @param string $ItemTarget + * @param string $itemTarget * @param int $format (optional) Format type must be defined by the backend + * @param mixed Parameters (optional) + * @param bool include collections (optional) * @return Return depends on format */ public static function getItemSharedWith($itemType, $itemTarget, $format = self::FORMAT_NONE, @@ -268,8 +272,8 @@ class Share { /** * Get the item of item type shared with a given user by source - * @param string $ItemType - * @param string $ItemSource + * @param string $itemType + * @param string $itemSource * @param string $user User user to whom the item was shared * @return array Return list of items with file_target, permissions and expiration */ @@ -419,11 +423,13 @@ class Share { * @param string Item source * @param string Owner * @param bool Include collections + * @praram bool check expire date * @return Return array of users */ - public static function getUsersItemShared($itemType, $itemSource, $uidOwner, $includeCollections = false) { + public static function getUsersItemShared($itemType, $itemSource, $uidOwner, $includeCollections = false, $checkExpireDate = true) { + $users = array(); - $items = self::getItems($itemType, $itemSource, null, null, $uidOwner, self::FORMAT_NONE, null, -1, $includeCollections); + $items = self::getItems($itemType, $itemSource, null, null, $uidOwner, self::FORMAT_NONE, null, -1, $includeCollections, false, $checkExpireDate); if ($items) { foreach ($items as $item) { if ((int)$item['share_type'] === self::SHARE_TYPE_USER) { @@ -823,11 +829,12 @@ class Share { $date = null; } else { $date = new \DateTime($date); - $date = date('Y-m-d H:i', $date->format('U') - $date->getOffset()); } $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `expiration` = ? WHERE `id` = ?'); + $query->bindValue(1, $date, 'datetime'); foreach ($items as $item) { - $query->execute(array($date, $item['id'])); + $query->bindValue(2, (int) $item['id']); + $query->execute(); } return true; } @@ -843,7 +850,8 @@ class Share { protected static function expireItem(array $item) { if (!empty($item['expiration'])) { $now = new \DateTime(); - $expirationDate = new \DateTime($item['expiration'], new \DateTimeZone('UTC')); + $expirationDate = \Doctrine\DBAL\Types\Type::getType('datetime') + ->convertToPhpValue($item['expiration'], \OC_DB::getConnection()->getDatabasePlatform()); if ($now > $expirationDate) { self::unshareItem($item); return true; @@ -860,12 +868,14 @@ class Share { protected static function unshareItem(array $item) { // Pass all the vars we have for now, they may be useful $hookParams = array( - 'itemType' => $item['item_type'], - 'itemSource' => $item['item_source'], - 'shareType' => $item['share_type'], - 'shareWith' => $item['share_with'], - 'itemParent' => $item['parent'], + 'itemType' => $item['item_type'], + 'itemSource' => $item['item_source'], + 'shareType' => $item['share_type'], + 'shareWith' => $item['share_with'], + 'itemParent' => $item['parent'], + 'uidOwner' => $item['uid_owner'], ); + \OC_Hook::emit('OCP\Share', 'pre_unshare', $hookParams + array( 'fileSource' => $item['file_source'], )); @@ -954,6 +964,8 @@ class Share { * @param mixed Parameters to pass to formatItems() * @param int Number of items to return, -1 to return all matches (optional) * @param bool Include collection item types (optional) + * @param bool TODO (optional) + * @prams bool check expire date * @return mixed * * See public functions getItem(s)... for parameter usage @@ -961,7 +973,7 @@ class Share { */ private static function getItems($itemType, $item = null, $shareType = null, $shareWith = null, $uidOwner = null, $format = self::FORMAT_NONE, $parameters = null, $limit = -1, - $includeCollections = false, $itemShareWithBySource = false) { + $includeCollections = false, $itemShareWithBySource = false, $checkExpireDate = true) { if (!self::isEnabled()) { if ($limit == 1 || (isset($uidOwner) && isset($item))) { return false; @@ -1101,19 +1113,19 @@ class Share { if ($format == self::FORMAT_STATUSES) { if ($itemType == 'file' || $itemType == 'folder') { $select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `*PREFIX*share`.`parent`,' - .' `share_type`, `file_source`, `path`, `expiration`, `storage`, `mail_send`'; + .' `share_type`, `file_source`, `path`, `expiration`, `storage`, `share_with`, `mail_send`, `uid_owner`'; } else { - $select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `expiration`, `mail_send`'; + $select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `share_with`, `expiration`, `mail_send`, `uid_owner`'; } } else { if (isset($uidOwner)) { if ($itemType == 'file' || $itemType == 'folder') { $select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `*PREFIX*share`.`parent`,' .' `share_type`, `share_with`, `file_source`, `path`, `permissions`, `stime`,' - .' `expiration`, `token`, `storage`, `mail_send`'; + .' `expiration`, `token`, `storage`, `mail_send`, `uid_owner`'; } else { $select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `share_with`, `permissions`,' - .' `stime`, `file_source`, `expiration`, `token`, `mail_send`'; + .' `stime`, `file_source`, `expiration`, `token`, `mail_send`, `uid_owner`'; } } else { if ($fileDependent) { @@ -1227,8 +1239,10 @@ class Share { } } } - if (self::expireItem($row)) { - continue; + if($checkExpireDate) { + if (self::expireItem($row)) { + continue; + } } // Check if resharing is allowed, if not remove share permission if (isset($row['permissions']) && !self::isResharingAllowed()) { @@ -1354,8 +1368,11 @@ class Share { * @param string Item source * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK * @param string User or group the item is being shared with + * @param string User that is the owner of shared item * @param int CRUDS permissions * @param bool|array Parent folder target (optional) + * @param string token (optional) + * @param string name of the source item (optional) * @return bool Returns true on success or false on failure */ private static function put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, @@ -1593,6 +1610,7 @@ class Share { * @param string Item source * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK * @param string User or group the item is being shared with + * @param string User that is the owner of shared item * @param string The suggested target originating from a reshare (optional) * @param int The id of the parent group share (optional) * @return string Item target @@ -1780,6 +1798,7 @@ class Share { */ /** + * Function that is called after a user is deleted. Cleans up the shares of that user. * @param array arguments */ public static function post_deleteUser($arguments) { @@ -1796,6 +1815,8 @@ class Share { } /** + * Function that is called after a user is added to a group. + * TODO what does it do? * @param array arguments */ public static function post_addToGroup($arguments) { @@ -1829,6 +1850,7 @@ class Share { } /** + * Function that is called after a user is removed from a group. Shares are cleaned up. * @param array arguments */ public static function post_removeFromGroup($arguments) { @@ -1848,6 +1870,7 @@ class Share { } /** + * Function that is called after a group is removed. Cleans up the shares to that group. * @param array arguments */ public static function post_deleteGroup($arguments) { @@ -1894,7 +1917,7 @@ interface Share_Backend { * Converts the shared item sources back into the item in the specified format * @param array Shared items * @param int Format - * @return ? + * @return TODO * * The items array is a 3-dimensional array with the item_source as the * first key and the share id as the second key to an array with the share @@ -1923,6 +1946,8 @@ interface Share_Backend_File_Dependent extends Share_Backend { /** * Get the file path of the item + * @param string Item source + * @param string User that is the owner of shared item */ public function getFilePath($itemSource, $uidOwner); |