2013-02-26 06:21:48 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ownCloud
|
|
|
|
*
|
|
|
|
* @author Michael Gapczynski
|
|
|
|
* @copyright 2013 Michael Gapczynski mtgap@owncloud.com
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* 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 along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OC\Files\Cache;
|
|
|
|
|
|
|
|
class Shared_Updater {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
// Correct Shared folders of other users shared with
|
|
|
|
$users = \OCP\Share::getUsersItemShared('file', $info['fileid'], $uidOwner, true);
|
|
|
|
if (!empty($users)) {
|
2013-03-06 22:33:27 +00:00
|
|
|
while (!empty($users)) {
|
|
|
|
$reshareUsers = array();
|
|
|
|
foreach ($users as $user) {
|
2013-03-20 11:58:39 +00:00
|
|
|
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', $info['fileid'], $user, true));
|
|
|
|
}
|
2013-02-26 06:21:48 +00:00
|
|
|
}
|
2013-03-06 22:33:27 +00:00
|
|
|
$users = $reshareUsers;
|
2013-02-26 06:21:48 +00:00
|
|
|
}
|
|
|
|
// Correct folders of shared file owner
|
2013-02-26 06:43:04 +00:00
|
|
|
$target = substr($target, 8);
|
2013-02-26 06:21:48 +00:00
|
|
|
if ($uidOwner !== $uid && $source = \OC_Share_Backend_File::getSource($target)) {
|
2013-02-26 06:43:04 +00:00
|
|
|
\OC\Files\Filesystem::initMountPoints($uidOwner);
|
|
|
|
$source = '/'.$uidOwner.'/'.$source['path'];
|
|
|
|
\OC\Files\Cache\Updater::correctFolder($source, $info['mtime']);
|
2013-02-26 06:21:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $params
|
|
|
|
*/
|
|
|
|
static public function writeHook($params) {
|
|
|
|
self::correctFolders($params['path']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $params
|
|
|
|
*/
|
|
|
|
static public function renameHook($params) {
|
|
|
|
self::correctFolders($params['newpath']);
|
2013-03-22 15:20:40 +00:00
|
|
|
self::correctFolders(pathinfo($params['oldpath'], PATHINFO_DIRNAME));
|
2013-02-26 06:21:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $params
|
|
|
|
*/
|
|
|
|
static public function deleteHook($params) {
|
|
|
|
self::correctFolders($params['path']);
|
|
|
|
}
|
|
|
|
|
2013-03-02 17:57:29 +00:00
|
|
|
/**
|
|
|
|
* @param array $params
|
|
|
|
*/
|
|
|
|
static public function shareHook($params) {
|
2013-03-02 18:11:57 +00:00
|
|
|
if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
|
2013-03-08 15:59:22 +00:00
|
|
|
$uidOwner = \OCP\User::getUser();
|
2013-03-08 16:32:04 +00:00
|
|
|
$users = \OCP\Share::getUsersItemShared($params['itemType'], $params['fileSource'], $uidOwner, true);
|
2013-03-08 15:59:22 +00:00
|
|
|
if (!empty($users)) {
|
|
|
|
while (!empty($users)) {
|
|
|
|
$reshareUsers = array();
|
|
|
|
foreach ($users as $user) {
|
2013-03-20 11:58:39 +00:00
|
|
|
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));
|
|
|
|
}
|
2013-03-08 15:59:22 +00:00
|
|
|
}
|
|
|
|
$users = $reshareUsers;
|
|
|
|
}
|
|
|
|
}
|
2013-03-02 17:57:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-07 15:00:03 +00:00
|
|
|
}
|