Przeglądaj źródła

extract the mount provider from the manager

tags/v8.2RC2
Robin Appelman 8 lat temu
rodzic
commit
e1c562f66b

+ 12
- 1
apps/files_sharing/appinfo/application.php Wyświetl plik

@@ -118,6 +118,17 @@ class Application extends App {
);
});

$container->registerService('ExternalMountProvider', function (IContainer $c) {
/** @var \OCP\IServerContainer $server */
$server = $c->query('ServerContainer');
return new \OCA\Files_Sharing\External\MountProvider(
$server->getDatabaseConnection(),
function() use ($c) {
return $c->query('ExternalManager');
}
);
});

$container->registerService('PropagationManager', function (IContainer $c) {
/** @var \OCP\IServerContainer $server */
$server = $c->query('ServerContainer');
@@ -138,7 +149,7 @@ class Application extends App {
$server = $this->getContainer()->query('ServerContainer');
$mountProviderCollection = $server->getMountProviderCollection();
$mountProviderCollection->registerProvider($this->getContainer()->query('MountProvider'));
$mountProviderCollection->registerProvider($this->getContainer()->query('ExternalManager'));
$mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider'));
}

public function setupPropagation() {

+ 4
- 23
apps/files_sharing/lib/external/manager.php Wyświetl plik

@@ -28,12 +28,9 @@ namespace OCA\Files_Sharing\External;

use OC\Files\Filesystem;
use OCP\Files;
use OCP\Files\Config\IMountProvider;
use OCP\Files\Storage\IStorageFactory;
use OC\Notification\IManager;
use OCP\IUser;

class Manager implements IMountProvider {
class Manager {
const STORAGE = '\OCA\Files_Sharing\External\Storage';

/**
@@ -155,22 +152,6 @@ class Manager implements IMountProvider {
return $this->mountShare($options);
}

public function getMountsForUser(IUser $user, IStorageFactory $loader) {
$query = $this->connection->prepare('
SELECT `remote`, `share_token`, `password`, `mountpoint`, `owner`
FROM `*PREFIX*share_external`
WHERE `user` = ? AND `accepted` = ?
');
$query->execute([$user->getUID(), 1]);
$mounts = [];
while ($row = $query->fetch()) {
$row['manager'] = $this;
$row['token'] = $row['share_token'];
$mounts[] = $this->getMount($row, $loader);
}
return $mounts;
}

/**
* get share
*
@@ -283,12 +264,12 @@ class Manager implements IMountProvider {
return rtrim(substr($path, strlen($prefix)), '/');
}

protected function getMount($data, IStorageFactory $storageFactory) {
public function getMount($data) {
$data['manager'] = $this;
$mountPoint = '/' . $this->uid . '/files' . $data['mountpoint'];
$data['mountpoint'] = $mountPoint;
$data['certificateManager'] = \OC::$server->getCertificateManager($this->uid);
return new Mount(self::STORAGE, $mountPoint, $data, $this, $storageFactory);
return new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader);
}

/**
@@ -296,7 +277,7 @@ class Manager implements IMountProvider {
* @return Mount
*/
protected function mountShare($data) {
$mount = $this->getMount($data, $this->storageLoader);
$mount = $this->getMount($data);
$this->mountManager->addMount($mount);
return $mount;
}

+ 75
- 0
apps/files_sharing/lib/external/mountprovider.php Wyświetl plik

@@ -0,0 +1,75 @@
<?php
/**
* @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/>
*
*/

namespace OCA\Files_Sharing\External;

use OCP\Files\Config\IMountProvider;
use OCP\Files\Storage\IStorageFactory;
use OCP\IDBConnection;
use OCP\IUser;

class MountProvider implements IMountProvider {
const STORAGE = '\OCA\Files_Sharing\External\Storage';

/**
* @var \OCP\IDBConnection
*/
private $connection;

/**
* @var callable
*/
private $managerProvider;

/**
* @param \OCP\IDBConnection $connection
* @param callable $managerProvider due to setup order we need a callable that return the manager instead of the manager itself
*/
public function __construct(IDBConnection $connection, callable $managerProvider) {
$this->connection = $connection;
$this->managerProvider = $managerProvider;
}

public function getMount(IUser $user, $data, IStorageFactory $storageFactory) {
$data['manager'] = $this;
$mountPoint = '/' . $user->getUID() . '/files' . $data['mountpoint'];
$data['mountpoint'] = $mountPoint;
$data['certificateManager'] = \OC::$server->getCertificateManager($user->getUID());
$managerProvider = $this->managerProvider;
return new Mount(self::STORAGE, $mountPoint, $data, $managerProvider(), $storageFactory);
}

public function getMountsForUser(IUser $user, IStorageFactory $loader) {
$query = $this->connection->prepare('
SELECT `remote`, `share_token`, `password`, `mountpoint`, `owner`
FROM `*PREFIX*share_external`
WHERE `user` = ? AND `accepted` = ?
');
$query->execute([$user->getUID(), 1]);
$mounts = [];
while ($row = $query->fetch()) {
$row['manager'] = $this;
$row['token'] = $row['share_token'];
$mounts[] = $this->getMount($user, $row, $loader);
}
return $mounts;
}
}

Ładowanie…
Anuluj
Zapisz