summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/files_sharing/appinfo/app.php2
-rw-r--r--apps/files_sharing/lib/helper.php35
-rw-r--r--apps/files_sharing/lib/updater.php77
3 files changed, 68 insertions, 46 deletions
diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php
index 217bc005faf..0ef34578117 100644
--- a/apps/files_sharing/appinfo/app.php
+++ b/apps/files_sharing/appinfo/app.php
@@ -17,6 +17,4 @@ OCP\Util::addScript('files_sharing', 'share');
\OC_Hook::connect('OC_Filesystem', 'post_delete', '\OC\Files\Cache\Shared_Updater', 'postDeleteHook');
\OC_Hook::connect('OC_Filesystem', 'delete', '\OC\Files\Cache\Shared_Updater', 'deleteHook');
\OC_Hook::connect('OC_Filesystem', 'post_rename', '\OC\Files\Cache\Shared_Updater', 'renameHook');
-\OC_Hook::connect('OCP\Share', 'post_shared', '\OC\Files\Cache\Shared_Updater', 'shareHook');
-\OC_Hook::connect('OCP\Share', 'pre_unshare', '\OC\Files\Cache\Shared_Updater', 'shareHook');
\OC_Hook::connect('OC_Appconfig', 'post_set_value', '\OCA\Files\Share\Maintainer', 'configChangeHook');
diff --git a/apps/files_sharing/lib/helper.php b/apps/files_sharing/lib/helper.php
index b602fe3599d..1381c0002d3 100644
--- a/apps/files_sharing/lib/helper.php
+++ b/apps/files_sharing/lib/helper.php
@@ -111,4 +111,39 @@ class Helper {
}
return true;
}
+
+ public static function getSharesFromItem($target) {
+ $result = array();
+ $owner = \OC\Files\Filesystem::getOwner($target);
+ \OC\Files\Filesystem::initMountPoints($owner);
+ $info = \OC\Files\Filesystem::getFileInfo($target);
+ $ownerView = new \OC\Files\View('/'.$owner.'/files');
+ if ( $owner != \OCP\User::getUser() ) {
+ $path = $ownerView->getPath($info['fileid']);
+ } else {
+ $path = $target;
+ }
+
+
+ $ids = array();
+ while ($path !== '' && $path !== '.' && $path !== '/') {
+ $info = $ownerView->getFileInfo($path);
+ $ids[] = $info['fileid'];
+ $path = dirname($path);
+ }
+
+ if (!empty($ids)) {
+
+ $idList = array_chunk($ids, 99, true);
+
+ foreach ($idList as $subList) {
+ $statement = "SELECT `share_with`, `share_type`, `file_target` FROM `*PREFIX*share` WHERE `file_source` IN (" . implode(',', $subList) . ") AND `share_type` IN (0, 1, 2)";
+ $query = \OCP\DB::prepare($statement);
+ $r = $query->execute();
+ $result = array_merge($result, $r->fetchAll());
+ }
+ }
+
+ return $result;
+ }
}
diff --git a/apps/files_sharing/lib/updater.php b/apps/files_sharing/lib/updater.php
index e3a7679292d..f7c0a75aeeb 100644
--- a/apps/files_sharing/lib/updater.php
+++ b/apps/files_sharing/lib/updater.php
@@ -27,30 +27,47 @@ class Shared_Updater {
static private $toRemove = array();
/**
+ * @brief walk up the users file tree and update the etags
+ * @param string $user
+ * @param string $path
+ */
+ static private function correctUsersFolder($user, $path) {
+ // $path points to the mount point which is a virtual folder, so we start with
+ // the parent
+ $path = '/files' . dirname($path);
+ \OC\Files\Filesystem::initMountPoints($user);
+ $view = new \OC\Files\View('/' . $user);
+ if ($view->file_exists($path)) {
+ while ($path !== '/') {
+ $etag = $view->getETag($path);
+ $view->putFileInfo($path, array('etag' => $etag));
+ $path = dirname($path);
+ }
+ } else {
+ error_log("error!" . 'can not update etags on ' . $path . ' for user ' . $user);
+ \OCP\Util::writeLog('files_sharing', 'can not update etags on ' . $path . ' for user ' . $user, \OCP\Util::ERROR);
+ }
+ }
+
+ /**
* Correct the parent folders' ETags for all users shared the file at $target
*
* @param string $target
*/
static public function correctFolders($target) {
- $uid = \OCP\User::getUser();
- $uidOwner = \OC\Files\Filesystem::getOwner($target);
- $info = \OC\Files\Filesystem::getFileInfo($target);
- $checkedUser = array($uidOwner);
// Correct Shared folders of other users shared with
- $users = \OCP\Share::getUsersItemShared('file', $info['fileid'], $uidOwner, true);
- if (!empty($users)) {
- while (!empty($users)) {
- $reshareUsers = array();
+ $shares = \OCA\Files_Sharing\Helper::getSharesFromItem($target);
+
+ foreach ($shares as $share) {
+ if ((int)$share['share_type'] === \OCP\Share::SHARE_TYPE_USER) {
+ self::correctUsersFolder($share['share_with'], $share['file_target']);
+ } elseif ((int)$share['share_type'] === \OCP\Share::SHARE_TYPE_GROUP) {
+ $users = \OC_Group::usersInGroup($share['share_with']);
foreach ($users as $user) {
- if ( !in_array($user, $checkedUser) ) {
- $etag = \OC\Files\Filesystem::getETag('');
- \OCP\Config::setUserValue($user, 'files_sharing', 'etag', $etag);
- // Look for reshares
- $reshareUsers = array_merge($reshareUsers, \OCP\Share::getUsersItemShared('file', $info['fileid'], $user, true));
- $checkedUser[] = $user;
- }
+ self::correctUsersFolder($user, $share['file_target']);
}
- $users = $reshareUsers;
+ } else { //unique name for group share
+ self::correctUsersFolder($share['share_with'], $share['file_target']);
}
}
}
@@ -108,34 +125,6 @@ class Shared_Updater {
}
/**
- * @param array $params
- */
- static public function shareHook($params) {
- if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
- if (isset($params['uidOwner'])) {
- $uidOwner = $params['uidOwner'];
- } else {
- $uidOwner = \OCP\User::getUser();
- }
- $users = \OCP\Share::getUsersItemShared($params['itemType'], $params['fileSource'], $uidOwner, true, false);
- if (!empty($users)) {
- while (!empty($users)) {
- $reshareUsers = array();
- foreach ($users as $user) {
- if ($user !== $uidOwner) {
- $etag = \OC\Files\Filesystem::getETag('');
- \OCP\Config::setUserValue($user, 'files_sharing', 'etag', $etag);
- // Look for reshares
- $reshareUsers = array_merge($reshareUsers, \OCP\Share::getUsersItemShared('file', $params['fileSource'], $user, true));
- }
- }
- $users = $reshareUsers;
- }
- }
- }
- }
-
- /**
* clean up oc_share table from files which are no longer exists
*
* This fixes issues from updates from files_sharing < 0.3.5.6 (ownCloud 4.5)