2015-03-09 18:20:18 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2015-06-25 12:43:55 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Robin Appelman <icewind@owncloud.com>
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This program 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, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
2015-03-09 18:20:18 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Files_Sharing\Propagation;
|
|
|
|
|
|
|
|
use OC\Files\Cache\ChangePropagator;
|
2015-04-20 17:46:35 +03:00
|
|
|
use OC\Files\Filesystem;
|
2015-03-09 18:20:18 +03:00
|
|
|
use OC\Files\View;
|
|
|
|
use OCA\Files_Sharing\SharedMount;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Watch for changes made in a shared mount and propagate the changes to the share owner
|
|
|
|
*/
|
|
|
|
class ChangeWatcher {
|
|
|
|
/**
|
|
|
|
* The user view for the logged in user
|
|
|
|
*
|
|
|
|
* @var \OC\Files\View
|
|
|
|
*/
|
|
|
|
private $baseView;
|
|
|
|
|
2015-06-23 15:52:31 +03:00
|
|
|
/**
|
|
|
|
* @var RecipientPropagator
|
|
|
|
*/
|
|
|
|
private $recipientPropagator;
|
|
|
|
|
2015-04-20 14:32:09 +03:00
|
|
|
/**
|
|
|
|
* @param \OC\Files\View $baseView the view for the logged in user
|
2015-06-23 15:52:31 +03:00
|
|
|
* @param RecipientPropagator $recipientPropagator
|
2015-04-20 14:32:09 +03:00
|
|
|
*/
|
2015-06-23 15:52:31 +03:00
|
|
|
public function __construct(View $baseView, RecipientPropagator $recipientPropagator) {
|
2015-03-09 18:20:18 +03:00
|
|
|
$this->baseView = $baseView;
|
2015-06-23 15:52:31 +03:00
|
|
|
$this->recipientPropagator = $recipientPropagator;
|
2015-03-09 18:20:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function writeHook($params) {
|
|
|
|
$path = $params['path'];
|
|
|
|
$fullPath = $this->baseView->getAbsolutePath($path);
|
|
|
|
$mount = $this->baseView->getMount($path);
|
|
|
|
if ($mount instanceof SharedMount) {
|
|
|
|
$this->propagateForOwner($mount->getShare(), $mount->getInternalPath($fullPath), $mount->getOwnerPropagator());
|
|
|
|
}
|
2015-06-23 15:52:31 +03:00
|
|
|
$info = $this->baseView->getFileInfo($path);
|
|
|
|
if ($info) {
|
2015-06-25 15:29:40 +03:00
|
|
|
// trigger propagation if the subject of the write hook is shared.
|
|
|
|
// if a parent folder of $path is shared the propagation will be triggered from the change propagator hooks
|
2015-06-23 15:52:31 +03:00
|
|
|
$this->recipientPropagator->propagateById($info->getId());
|
|
|
|
}
|
2015-03-09 18:20:18 +03:00
|
|
|
}
|
|
|
|
|
2015-04-17 14:31:22 +03:00
|
|
|
public function renameHook($params) {
|
|
|
|
$path1 = $params['oldpath'];
|
|
|
|
$path2 = $params['newpath'];
|
|
|
|
$fullPath1 = $this->baseView->getAbsolutePath($path1);
|
|
|
|
$fullPath2 = $this->baseView->getAbsolutePath($path2);
|
|
|
|
$mount1 = $this->baseView->getMount($path1);
|
|
|
|
$mount2 = $this->baseView->getMount($path2);
|
2015-04-20 17:46:35 +03:00
|
|
|
if ($mount1 instanceof SharedMount and $mount1->getInternalPath($fullPath1) !== '') {
|
2015-04-17 14:31:22 +03:00
|
|
|
$this->propagateForOwner($mount1->getShare(), $mount1->getInternalPath($fullPath1), $mount1->getOwnerPropagator());
|
|
|
|
}
|
2015-04-20 17:46:35 +03:00
|
|
|
if ($mount1 !== $mount2 and $mount2 instanceof SharedMount and $mount2->getInternalPath($fullPath2) !== '') {
|
2015-04-17 14:31:22 +03:00
|
|
|
$this->propagateForOwner($mount2->getShare(), $mount2->getInternalPath($fullPath2), $mount2->getOwnerPropagator());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-09 18:20:18 +03:00
|
|
|
/**
|
|
|
|
* @param array $share
|
|
|
|
* @param string $internalPath
|
|
|
|
* @param \OC\Files\Cache\ChangePropagator $propagator
|
|
|
|
*/
|
|
|
|
private function propagateForOwner($share, $internalPath, ChangePropagator $propagator) {
|
|
|
|
// note that we have already set up the filesystem for the owner when mounting the share
|
|
|
|
$view = new View('/' . $share['uid_owner'] . '/files');
|
|
|
|
|
|
|
|
$shareRootPath = $view->getPath($share['item_source']);
|
2015-04-20 14:32:09 +03:00
|
|
|
if (!is_null($shareRootPath)) {
|
2015-03-09 18:20:18 +03:00
|
|
|
$path = $shareRootPath . '/' . $internalPath;
|
2015-04-20 17:46:35 +03:00
|
|
|
$path = Filesystem::normalizePath($path);
|
2015-03-09 18:20:18 +03:00
|
|
|
$propagator->addChange($path);
|
|
|
|
$propagator->propagateChanges();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|