2013-02-26 06:21:48 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Björn Schießle <schiessle@owncloud.com>
|
|
|
|
* @author Joas Schilling <nickvergessen@owncloud.com>
|
|
|
|
* @author Michael Gapczynski <GapczynskiM@gmail.com>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
2013-02-26 06:21:48 +00:00
|
|
|
*
|
2015-03-26 10:44:34 +00:00
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
|
|
|
* @license AGPL-3.0
|
2013-02-26 06:21:48 +00:00
|
|
|
*
|
2015-03-26 10:44:34 +00:00
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
2013-02-26 06:21:48 +00:00
|
|
|
*
|
2015-03-26 10:44:34 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2013-02-26 06:21:48 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-03-26 10:44:34 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2013-02-26 06:21:48 +00:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 10:37:37 +00:00
|
|
|
|
2013-02-26 06:21:48 +00:00
|
|
|
namespace OC\Files\Cache;
|
|
|
|
|
|
|
|
class Shared_Updater {
|
|
|
|
|
2014-04-14 15:08:46 +00:00
|
|
|
/**
|
2015-04-22 15:24:40 +00:00
|
|
|
* Walk up the users file tree and update the etags.
|
|
|
|
*
|
|
|
|
* @param string $user user id
|
|
|
|
* @param string $path share mount point path, relative to the user's "files" folder
|
2014-04-14 15:08:46 +00:00
|
|
|
*/
|
|
|
|
static private function correctUsersFolder($user, $path) {
|
|
|
|
// $path points to the mount point which is a virtual folder, so we start with
|
|
|
|
// the parent
|
2015-04-22 15:24:40 +00:00
|
|
|
$path = '/' . ltrim($path, '/');
|
2014-04-14 15:08:46 +00:00
|
|
|
$path = '/files' . dirname($path);
|
|
|
|
\OC\Files\Filesystem::initMountPoints($user);
|
|
|
|
$view = new \OC\Files\View('/' . $user);
|
|
|
|
if ($view->file_exists($path)) {
|
2014-05-07 15:37:49 +00:00
|
|
|
while ($path !== dirname($path)) {
|
2014-04-14 15:08:46 +00:00
|
|
|
$etag = $view->getETag($path);
|
|
|
|
$view->putFileInfo($path, array('etag' => $etag));
|
|
|
|
$path = dirname($path);
|
|
|
|
}
|
|
|
|
} else {
|
2014-05-07 15:56:52 +00:00
|
|
|
\OCP\Util::writeLog('files_sharing', 'can not update etags on ' . $path . ' for user ' . $user . '. Path does not exists', \OCP\Util::DEBUG);
|
2014-04-14 15:08:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-26 06:21:48 +00:00
|
|
|
/**
|
|
|
|
* @param array $params
|
|
|
|
*/
|
|
|
|
static public function renameHook($params) {
|
2014-07-02 13:35:15 +00:00
|
|
|
self::renameChildren($params['oldpath'], $params['newpath']);
|
2013-02-26 06:21:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $params
|
|
|
|
*/
|
|
|
|
static public function deleteHook($params) {
|
2014-04-30 14:56:09 +00:00
|
|
|
$path = $params['path'];
|
2013-11-27 16:22:48 +00:00
|
|
|
}
|
2013-10-02 11:26:38 +00:00
|
|
|
|
2014-06-24 15:04:27 +00:00
|
|
|
/**
|
|
|
|
* update etags if a file was shared
|
|
|
|
* @param array $params
|
|
|
|
*/
|
|
|
|
static public function postShareHook($params) {
|
|
|
|
|
|
|
|
if ($params['itemType'] === 'folder' || $params['itemType'] === 'file') {
|
|
|
|
|
|
|
|
$shareWith = $params['shareWith'];
|
|
|
|
$shareType = $params['shareType'];
|
|
|
|
|
|
|
|
if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
|
2015-06-22 16:21:54 +00:00
|
|
|
self::correctUsersFolder($shareWith, $params['fileTarget']);
|
2014-06-24 15:04:27 +00:00
|
|
|
} elseif ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
|
|
|
|
foreach (\OC_Group::usersInGroup($shareWith) as $user) {
|
2015-06-22 16:21:54 +00:00
|
|
|
self::correctUsersFolder($user, $params['fileTarget']);
|
2014-06-24 15:04:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* update etags if a file was unshared
|
|
|
|
*
|
|
|
|
* @param array $params
|
|
|
|
*/
|
|
|
|
static public function postUnshareHook($params) {
|
|
|
|
|
2014-12-04 18:51:04 +00:00
|
|
|
// only update etags for file/folders shared to local users/groups
|
|
|
|
if (($params['itemType'] === 'file' || $params['itemType'] === 'folder') &&
|
|
|
|
$params['shareType'] !== \OCP\Share::SHARE_TYPE_LINK &&
|
|
|
|
$params['shareType'] !== \OCP\Share::SHARE_TYPE_REMOTE) {
|
2014-06-24 15:04:27 +00:00
|
|
|
|
|
|
|
$deletedShares = isset($params['deletedShares']) ? $params['deletedShares'] : array();
|
|
|
|
|
|
|
|
foreach ($deletedShares as $share) {
|
|
|
|
if ($share['shareType'] === \OCP\Share::SHARE_TYPE_GROUP) {
|
|
|
|
foreach (\OC_Group::usersInGroup($share['shareWith']) as $user) {
|
2015-04-22 15:24:40 +00:00
|
|
|
self::correctUsersFolder($user, $share['fileTarget']);
|
2014-06-24 15:04:27 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-04-22 15:24:40 +00:00
|
|
|
self::correctUsersFolder($share['shareWith'], $share['fileTarget']);
|
2014-06-24 15:04:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* update etags if file was unshared from self
|
|
|
|
* @param array $params
|
|
|
|
*/
|
|
|
|
static public function postUnshareFromSelfHook($params) {
|
|
|
|
if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
|
|
|
|
foreach ($params['unsharedItems'] as $item) {
|
|
|
|
if ($item['shareType'] === \OCP\Share::SHARE_TYPE_GROUP) {
|
|
|
|
foreach (\OC_Group::usersInGroup($item['shareWith']) as $user) {
|
2015-04-22 15:24:40 +00:00
|
|
|
self::correctUsersFolder($user, $item['fileTarget']);
|
2014-06-24 15:04:27 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-04-22 15:24:40 +00:00
|
|
|
self::correctUsersFolder($item['shareWith'], $item['fileTarget']);
|
2014-06-24 15:04:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-20 14:21:53 +00:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
* It will just be called during the update of the app
|
|
|
|
*/
|
|
|
|
static public function fixBrokenSharesOnAppUpdate() {
|
|
|
|
// delete all shares where the original file no longer exists
|
2015-04-08 13:21:52 +00:00
|
|
|
$findAndRemoveShares = \OCP\DB::prepare('DELETE FROM `*PREFIX*share` ' .
|
2014-07-08 10:51:32 +00:00
|
|
|
'WHERE `item_type` IN (\'file\', \'folder\') ' .
|
|
|
|
'AND `file_source` NOT IN (SELECT `fileid` FROM `*PREFIX*filecache`)'
|
2014-03-03 18:59:25 +00:00
|
|
|
);
|
|
|
|
$findAndRemoveShares->execute(array());
|
2014-02-20 14:21:53 +00:00
|
|
|
}
|
|
|
|
|
2014-07-02 13:35:15 +00:00
|
|
|
/**
|
|
|
|
* rename mount point from the children if the parent was renamed
|
2014-12-04 18:51:04 +00:00
|
|
|
*
|
2014-07-02 13:35:15 +00:00
|
|
|
* @param string $oldPath old path relative to data/user/files
|
|
|
|
* @param string $newPath new path relative to data/user/files
|
|
|
|
*/
|
|
|
|
static private function renameChildren($oldPath, $newPath) {
|
|
|
|
|
|
|
|
$absNewPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $newPath);
|
|
|
|
$absOldPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $oldPath);
|
|
|
|
|
|
|
|
$mountManager = \OC\Files\Filesystem::getMountManager();
|
|
|
|
$mountedShares = $mountManager->findIn('/' . \OCP\User::getUser() . '/files/' . $oldPath);
|
|
|
|
foreach ($mountedShares as $mount) {
|
|
|
|
if ($mount->getStorage()->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')) {
|
|
|
|
$mountPoint = $mount->getMountPoint();
|
|
|
|
$target = str_replace($absOldPath, $absNewPath, $mountPoint);
|
|
|
|
$mount->moveMount($target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-07 15:00:03 +00:00
|
|
|
}
|