From 06575f75f6e8d5644a12ae925e8f9a398c268db1 Mon Sep 17 00:00:00 2001 From: Hugo Gonzalez Labrador Date: Thu, 9 Jul 2015 09:06:00 +0200 Subject: [PATCH] Move logic to EosUtil --- lib/private/files/objectstore/eosutil.php | 12 +++++++++-- lib/private/share/share.php | 25 ++++++++--------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/lib/private/files/objectstore/eosutil.php b/lib/private/files/objectstore/eosutil.php index 1b870c0f0742..b63495670c9e 100644 --- a/lib/private/files/objectstore/eosutil.php +++ b/lib/private/files/objectstore/eosutil.php @@ -720,8 +720,7 @@ public static function createVersion($eosPath) { // this function returns the fileid of the versions folder of a file // if versions folder does not exist, it will create it - public static function getFileIDFromVersionsFolder($id) { - /* HUGO if we receive itemType = file and an itemSource then we need to point to the versions folder */ + public static function getVersionsFolderIDFromFileID($id) { $meta = self::getFileById($id); // here we can receive the file to convert to version folder // or the version folder itself @@ -742,4 +741,13 @@ public static function getFileIDFromVersionsFolder($id) { return $versionInfo['fileid']; } } + // given the fileid of a versions folder, returns the metadata of the real file + public static function getFileMetaFromVersionsFolderID($id) { + $meta = \OC\Files\ObjectStore\EosUtil::getFileById($id); + $dirname = dirname($meta['eospath']); + $basename = basename($meta['eospath']); + $realfile = $dirname . "/" . substr($basename, 8); + $realfilemeta = \OC\Files\ObjectStore\EosUtil::getFileByEosPath($realfile); + return $realfilemeta; + } } diff --git a/lib/private/share/share.php b/lib/private/share/share.php index e70708be3ff0..6d7a8a5a2e19 100644 --- a/lib/private/share/share.php +++ b/lib/private/share/share.php @@ -447,14 +447,9 @@ public static function getShareByToken($token, $checkPasswordProtection = true) } /* HUGO if we receive itemType = file and an itemSource then we need to point to the versions folder */ if($row['item_type'] === 'file') { // this MUST be a version folder already - $meta = \OC\Files\ObjectStore\EosUtil::getFileById($row['item_source']); - $dirname = dirname($meta['eospath']); - $basename = basename($meta['eospath']); - $realfile = $dirname . "/" . substr($basename, 8); - $realfilemeta = \OC\Files\ObjectStore\EosUtil::getFileByEosPath($realfile); + $realfilemeta = \OC\Files\ObjectStore\EosUtil::getFileMetaFromVersionsFolderID($row['item_source']); $row['item_source'] = $realfilemeta['fileid']; $row['file_source'] = (int)$realfilemeta['fileid']; - } return $row; @@ -553,7 +548,7 @@ public static function getUsersItemShared($itemType, $itemSource, $uidOwner, $in public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName = null, \DateTime $expirationDate = null) { /* HUGO try to put here the logic to convert file share via link to version folder share */ if($shareType === 3 && $itemType === 'file') { - $itemSource = \OC\Files\ObjectStore\EosUtil::getFileIDFromVersionsFolder($itemSource); + $itemSource = \OC\Files\ObjectStore\EosUtil::getVersionsFolderIDFromFileID($itemSource); } $backend = self::getBackend($itemType); @@ -800,7 +795,7 @@ public static function unshare($itemType, $itemSource, $shareType, $shareWith, $ * Hooks under hooks.php that could call unshare are related to groups so for us they will not been called */ if($itemType === 'file' && is_numeric($itemSource)) { - $itemSource = \OC\Files\ObjectStore\EosUtil::getFileIDFromVersionsFolder($itemSource); + $itemSource = \OC\Files\ObjectStore\EosUtil::getVersionsFolderIDFromFileID($itemSource); } // check if it is a valid itemType self::getBackend($itemType); @@ -998,7 +993,7 @@ public static function setSendMailStatus($itemType, $itemSource, $shareType, $re public static function setPermissions($itemType, $itemSource, $shareType, $shareWith, $permissions) { // HUGO if($itemType === 'file' && is_numeric($itemSource)) { - $itemSource = \OC\Files\ObjectStore\EosUtil::getFileIDFromVersionsFolder($itemSource); + $itemSource = \OC\Files\ObjectStore\EosUtil::getVersionsFolderIDFromFileID($itemSource); } $l = \OC::$server->getL10N('lib'); if ($item = self::getItems($itemType, $itemSource, $shareType, $shareWith, @@ -1147,7 +1142,7 @@ private static function validateExpireDate($expireDate, $shareTime, $itemType, $ public static function setExpirationDate($itemType, $itemSource, $date, $shareTime = null) { // HUGO if($itemType === 'file' && is_numeric($itemSource)) { - $itemSource = \OC\Files\ObjectStore\EosUtil::getFileIDFromVersionsFolder($itemSource); + $itemSource = \OC\Files\ObjectStore\EosUtil::getVersionsFolderIDFromFileID($itemSource); } $user = \OC_User::getUser(); @@ -1404,7 +1399,7 @@ public static function getItems($itemType, $item = null, $shareType = null, $sha $includeCollections = false, $itemShareWithBySource = false, $checkExpireDate = true) { /* HUGO if we receive itemType = file and an itemSource then we need to point to the versions folder */ if($itemType === 'file' && is_numeric($item)) { - $item = \OC\Files\ObjectStore\EosUtil::getFileIDFromVersionsFolder($item); + $item = \OC\Files\ObjectStore\EosUtil::getVersionsFolderIDFromFileID($item); } if (!self::isEnabled()) { return array(); @@ -1695,13 +1690,9 @@ public static function getItems($itemType, $item = null, $shareType = null, $sha if ( isset($row['uid_owner']) && $row['uid_owner'] != '') { $row['displayname_owner'] = \OCP\User::getDisplayName($row['uid_owner']); } - /* HUGO if we receive itemType = file and an itemSource then we need to point to the versions folder */ + /* HUGO convert versions folder to file*/ if($row['item_type'] === 'file') { // this MUST be a version folder already - $meta = \OC\Files\ObjectStore\EosUtil::getFileById($row['item_source']); - $dirname = dirname($meta['eospath']); - $basename = basename($meta['eospath']); - $realfile = $dirname . "/" . substr($basename, 8); - $realfilemeta = \OC\Files\ObjectStore\EosUtil::getFileByEosPath($realfile); + $realfilemeta = \OC\Files\ObjectStore\EosUtil::getFileMetaFromVersionsFolderID($row['item_source']); $row['item_source'] = $realfilemeta['fileid']; $row['file_source'] = (int)$realfilemeta['fileid']; $row['file_target'] = basename($realfilemeta['path']);