Skip to content

Commit

Permalink
Move logic to EosUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Gonzalez Labrador committed Jul 9, 2015
1 parent ff9383e commit 06575f7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
12 changes: 10 additions & 2 deletions lib/private/files/objectstore/eosutil.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
}
25 changes: 8 additions & 17 deletions lib/private/share/share.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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']);
Expand Down

0 comments on commit 06575f7

Please sign in to comment.