Use IBootstrap for the files_trashbin app
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
parent
c842678f0a
commit
e84504c4d6
|
@ -31,6 +31,8 @@ namespace OCA\Files_Sharing\Tests;
|
||||||
|
|
||||||
use OC\Files\View;
|
use OC\Files\View;
|
||||||
use OCA\Files_Sharing\SharedStorage;
|
use OCA\Files_Sharing\SharedStorage;
|
||||||
|
use OCA\Files_Trashbin\AppInfo\Application;
|
||||||
|
use OCP\AppFramework\Bootstrap\IBootContext;
|
||||||
use OCP\Files\NotFoundException;
|
use OCP\Files\NotFoundException;
|
||||||
use OCP\Share\IShare;
|
use OCP\Share\IShare;
|
||||||
|
|
||||||
|
@ -42,7 +44,9 @@ use OCP\Share\IShare;
|
||||||
class SharedStorageTest extends TestCase {
|
class SharedStorageTest extends TestCase {
|
||||||
protected function setUp(): void {
|
protected function setUp(): void {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
\OCA\Files_Trashbin\Trashbin::registerHooks();
|
// register trashbin hooks
|
||||||
|
$trashbinApp = new Application();
|
||||||
|
$trashbinApp->boot($this->createMock(IBootContext::class));
|
||||||
$this->folder = '/folder_share_storage_test';
|
$this->folder = '/folder_share_storage_test';
|
||||||
|
|
||||||
$this->filename = '/share-api-storage.txt';
|
$this->filename = '/share-api-storage.txt';
|
||||||
|
|
|
@ -31,6 +31,8 @@
|
||||||
|
|
||||||
namespace OCA\Files_Sharing\Tests;
|
namespace OCA\Files_Sharing\Tests;
|
||||||
|
|
||||||
|
use OCA\Files_Trashbin\AppInfo\Application;
|
||||||
|
use OCP\AppFramework\Bootstrap\IBootContext;
|
||||||
use OCP\Share\IShare;
|
use OCP\Share\IShare;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,8 +79,9 @@ class UpdaterTest extends TestCase {
|
||||||
$status = \OC::$server->getAppManager()->isEnabledForUser('files_trashbin');
|
$status = \OC::$server->getAppManager()->isEnabledForUser('files_trashbin');
|
||||||
(new \OC_App())->enable('files_trashbin');
|
(new \OC_App())->enable('files_trashbin');
|
||||||
|
|
||||||
|
// register trashbin hooks
|
||||||
\OCA\Files_Trashbin\Trashbin::registerHooks();
|
$trashbinApp = new Application();
|
||||||
|
$trashbinApp->boot($this->createMock(IBootContext::class));
|
||||||
|
|
||||||
$fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder);
|
$fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder);
|
||||||
$this->assertTrue($fileinfo instanceof \OC\Files\FileInfo);
|
$this->assertTrue($fileinfo instanceof \OC\Files\FileInfo);
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
||||||
*
|
|
||||||
* @author Christopher Schäpers <kondou@ts.unde.re>
|
|
||||||
* @author Florin Peter <github@florin-peter.de>
|
|
||||||
* @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
|
|
||||||
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
|
||||||
* @author Victor Dubiniuk <dubiniuk@owncloud.com>
|
|
||||||
* @author Vincent Petry <pvince81@owncloud.com>
|
|
||||||
*
|
|
||||||
* @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/>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
// register hooks
|
|
||||||
\OCA\Files_Trashbin\Trashbin::registerHooks();
|
|
||||||
|
|
||||||
\OCA\Files\App::getNavigationManager()->add(function () {
|
|
||||||
$l = \OC::$server->getL10N('files_trashbin');
|
|
||||||
return [
|
|
||||||
'id' => 'trashbin',
|
|
||||||
'appname' => 'files_trashbin',
|
|
||||||
'script' => 'list.php',
|
|
||||||
'order' => 50,
|
|
||||||
'name' => $l->t('Deleted files'),
|
|
||||||
'classes' => 'pinned',
|
|
||||||
];
|
|
||||||
});
|
|
|
@ -27,57 +27,59 @@
|
||||||
|
|
||||||
namespace OCA\Files_Trashbin\AppInfo;
|
namespace OCA\Files_Trashbin\AppInfo;
|
||||||
|
|
||||||
use OCA\DAV\CalDAV\Proxy\ProxyMapper;
|
|
||||||
use OCA\DAV\Connector\Sabre\Principal;
|
use OCA\DAV\Connector\Sabre\Principal;
|
||||||
use OCA\Files_Trashbin\Capabilities;
|
use OCA\Files_Trashbin\Capabilities;
|
||||||
use OCA\Files_Trashbin\Expiration;
|
use OCA\Files_Trashbin\Expiration;
|
||||||
use OCA\Files_Trashbin\Trash\ITrashManager;
|
use OCA\Files_Trashbin\Trash\ITrashManager;
|
||||||
use OCA\Files_Trashbin\Trash\TrashManager;
|
use OCA\Files_Trashbin\Trash\TrashManager;
|
||||||
|
use OCP\App\IAppManager;
|
||||||
use OCP\AppFramework\App;
|
use OCP\AppFramework\App;
|
||||||
|
use OCP\AppFramework\Bootstrap\IBootContext;
|
||||||
|
use OCP\AppFramework\Bootstrap\IBootstrap;
|
||||||
|
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
||||||
|
use OCP\ILogger;
|
||||||
|
use OCP\IServerContainer;
|
||||||
|
|
||||||
class Application extends App {
|
class Application extends App implements IBootstrap {
|
||||||
public function __construct(array $urlParams = []) {
|
public function __construct(array $urlParams = []) {
|
||||||
parent::__construct('files_trashbin', $urlParams);
|
parent::__construct('files_trashbin', $urlParams);
|
||||||
|
|
||||||
$container = $this->getContainer();
|
|
||||||
/*
|
|
||||||
* Register capabilities
|
|
||||||
*/
|
|
||||||
$container->registerCapability(Capabilities::class);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Register expiration
|
|
||||||
*/
|
|
||||||
$container->registerAlias('Expiration', Expiration::class);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Register $principalBackend for the DAV collection
|
|
||||||
*/
|
|
||||||
$container->registerService('principalBackend', function () {
|
|
||||||
return new Principal(
|
|
||||||
\OC::$server->getUserManager(),
|
|
||||||
\OC::$server->getGroupManager(),
|
|
||||||
\OC::$server->getShareManager(),
|
|
||||||
\OC::$server->getUserSession(),
|
|
||||||
\OC::$server->getAppManager(),
|
|
||||||
\OC::$server->query(ProxyMapper::class),
|
|
||||||
\OC::$server->getConfig()
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
$container->registerService(ITrashManager::class, function () {
|
|
||||||
return new TrashManager();
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->registerTrashBackends();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function registerTrashBackends() {
|
public function register(IRegistrationContext $context): void {
|
||||||
$server = $this->getContainer()->getServer();
|
$context->registerCapability(Capabilities::class);
|
||||||
$logger = $server->getLogger();
|
|
||||||
$appManager = $server->getAppManager();
|
$context->registerServiceAlias('Expiration', Expiration::class);
|
||||||
/** @var ITrashManager $trashManager */
|
$context->registerServiceAlias(ITrashManager::class, TrashManager::class);
|
||||||
$trashManager = $this->getContainer()->getServer()->query(ITrashManager::class);
|
/** Register $principalBackend for the DAV collection */
|
||||||
|
$context->registerServiceAlias('principalBackend', Principal::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function boot(IBootContext $context): void {
|
||||||
|
$context->injectFn([$this, 'registerTrashBackends']);
|
||||||
|
|
||||||
|
// create storage wrapper on setup
|
||||||
|
\OCP\Util::connectHook('OC_Filesystem', 'preSetup', 'OCA\Files_Trashbin\Storage', 'setupStorage');
|
||||||
|
//Listen to delete user signal
|
||||||
|
\OCP\Util::connectHook('OC_User', 'pre_deleteUser', 'OCA\Files_Trashbin\Hooks', 'deleteUser_hook');
|
||||||
|
//Listen to post write hook
|
||||||
|
\OCP\Util::connectHook('OC_Filesystem', 'post_write', 'OCA\Files_Trashbin\Hooks', 'post_write_hook');
|
||||||
|
// pre and post-rename, disable trash logic for the copy+unlink case
|
||||||
|
\OCP\Util::connectHook('OC_Filesystem', 'delete', 'OCA\Files_Trashbin\Trashbin', 'ensureFileScannedHook');
|
||||||
|
|
||||||
|
\OCA\Files\App::getNavigationManager()->add(function () {
|
||||||
|
$l = \OC::$server->getL10N('files_trashbin');
|
||||||
|
return [
|
||||||
|
'id' => 'trashbin',
|
||||||
|
'appname' => 'files_trashbin',
|
||||||
|
'script' => 'list.php',
|
||||||
|
'order' => 50,
|
||||||
|
'name' => $l->t('Deleted files'),
|
||||||
|
'classes' => 'pinned',
|
||||||
|
];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function registerTrashBackends(IServerContainer $serverContainer, ILogger $logger, IAppManager $appManager, ITrashManager $trashManager) {
|
||||||
foreach ($appManager->getInstalledApps() as $app) {
|
foreach ($appManager->getInstalledApps() as $app) {
|
||||||
$appInfo = $appManager->getAppInfo($app);
|
$appInfo = $appManager->getAppInfo($app);
|
||||||
if (isset($appInfo['trash'])) {
|
if (isset($appInfo['trash'])) {
|
||||||
|
@ -87,7 +89,7 @@ class Application extends App {
|
||||||
$for = $backend['@attributes']['for'];
|
$for = $backend['@attributes']['for'];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$backendObject = $server->query($class);
|
$backendObject = $serverContainer->query($class);
|
||||||
$trashManager->registerBackend($for, $backendObject);
|
$trashManager->registerBackend($for, $backendObject);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$logger->logException($e);
|
$logger->logException($e);
|
||||||
|
|
|
@ -1008,20 +1008,6 @@ class Trashbin {
|
||||||
return isset($fileInfo['size']) ? $fileInfo['size'] : 0;
|
return isset($fileInfo['size']) ? $fileInfo['size'] : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* register hooks
|
|
||||||
*/
|
|
||||||
public static function registerHooks() {
|
|
||||||
// create storage wrapper on setup
|
|
||||||
\OCP\Util::connectHook('OC_Filesystem', 'preSetup', 'OCA\Files_Trashbin\Storage', 'setupStorage');
|
|
||||||
//Listen to delete user signal
|
|
||||||
\OCP\Util::connectHook('OC_User', 'pre_deleteUser', 'OCA\Files_Trashbin\Hooks', 'deleteUser_hook');
|
|
||||||
//Listen to post write hook
|
|
||||||
\OCP\Util::connectHook('OC_Filesystem', 'post_write', 'OCA\Files_Trashbin\Hooks', 'post_write_hook');
|
|
||||||
// pre and post-rename, disable trash logic for the copy+unlink case
|
|
||||||
\OCP\Util::connectHook('OC_Filesystem', 'delete', 'OCA\Files_Trashbin\Trashbin', 'ensureFileScannedHook');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if trash bin is empty for a given user
|
* check if trash bin is empty for a given user
|
||||||
*
|
*
|
||||||
|
|
|
@ -34,9 +34,11 @@ namespace OCA\Files_Trashbin\Tests;
|
||||||
|
|
||||||
use OC\Files\Filesystem;
|
use OC\Files\Filesystem;
|
||||||
use OC\Files\Storage\Temporary;
|
use OC\Files\Storage\Temporary;
|
||||||
|
use OCA\Files_Trashbin\AppInfo\Application;
|
||||||
use OCA\Files_Trashbin\Events\MoveToTrashEvent;
|
use OCA\Files_Trashbin\Events\MoveToTrashEvent;
|
||||||
use OCA\Files_Trashbin\Storage;
|
use OCA\Files_Trashbin\Storage;
|
||||||
use OCA\Files_Trashbin\Trash\ITrashManager;
|
use OCA\Files_Trashbin\Trash\ITrashManager;
|
||||||
|
use OCP\AppFramework\Bootstrap\IBootContext;
|
||||||
use OCP\AppFramework\Utility\ITimeFactory;
|
use OCP\AppFramework\Utility\ITimeFactory;
|
||||||
use OCP\Files\Cache\ICache;
|
use OCP\Files\Cache\ICache;
|
||||||
use OCP\Files\Folder;
|
use OCP\Files\Folder;
|
||||||
|
@ -75,7 +77,9 @@ class StorageTest extends \Test\TestCase {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
\OC_Hook::clear();
|
\OC_Hook::clear();
|
||||||
\OCA\Files_Trashbin\Trashbin::registerHooks();
|
// register trashbin hooks
|
||||||
|
$trashbinApp = new Application();
|
||||||
|
$trashbinApp->boot($this->createMock(IBootContext::class));
|
||||||
|
|
||||||
$this->user = $this->getUniqueId('user');
|
$this->user = $this->getUniqueId('user');
|
||||||
\OC::$server->getUserManager()->createUser($this->user, $this->user);
|
\OC::$server->getUserManager()->createUser($this->user, $this->user);
|
||||||
|
|
|
@ -30,6 +30,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use OCA\Files_Sharing\AppInfo\Application;
|
use OCA\Files_Sharing\AppInfo\Application;
|
||||||
|
use OCA\Files_Trashbin\AppInfo\Application as TrashbinApplication;
|
||||||
|
use OC\AppFramework\Bootstrap\BootContext;
|
||||||
|
use OC\AppFramework\DependencyInjection\DIContainer;
|
||||||
use OCP\Share\IShare;
|
use OCP\Share\IShare;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,8 +86,9 @@ class TrashbinTest extends \Test\TestCase {
|
||||||
$expiration = \OC::$server->query(\OCA\Files_Trashbin\Expiration::class);
|
$expiration = \OC::$server->query(\OCA\Files_Trashbin\Expiration::class);
|
||||||
$expiration->setRetentionObligation('auto, 2');
|
$expiration->setRetentionObligation('auto, 2');
|
||||||
|
|
||||||
// register hooks
|
// register trashbin hooks
|
||||||
\OCA\Files_Trashbin\Trashbin::registerHooks();
|
$trashbinApp = new TrashbinApplication();
|
||||||
|
$trashbinApp->boot(new BootContext(new DIContainer('', [], \OC::$server)));
|
||||||
|
|
||||||
// create test user
|
// create test user
|
||||||
self::loginHelper(self::TEST_TRASHBIN_USER2, true);
|
self::loginHelper(self::TEST_TRASHBIN_USER2, true);
|
||||||
|
|
Loading…
Reference in New Issue