Selaa lähdekoodia

Use IBootstrap for the files_trashbin app

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
tags/v20.0.0beta1
Morris Jobke 3 vuotta sitten
vanhempi
commit
e84504c4d6
No account linked to committer's email address

+ 5
- 1
apps/files_sharing/tests/SharedStorageTest.php Näytä tiedosto

@@ -31,6 +31,8 @@ namespace OCA\Files_Sharing\Tests;

use OC\Files\View;
use OCA\Files_Sharing\SharedStorage;
use OCA\Files_Trashbin\AppInfo\Application;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\Files\NotFoundException;
use OCP\Share\IShare;

@@ -42,7 +44,9 @@ use OCP\Share\IShare;
class SharedStorageTest extends TestCase {
protected function setUp(): void {
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->filename = '/share-api-storage.txt';

+ 5
- 2
apps/files_sharing/tests/UpdaterTest.php Näytä tiedosto

@@ -31,6 +31,8 @@

namespace OCA\Files_Sharing\Tests;

use OCA\Files_Trashbin\AppInfo\Application;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\Share\IShare;

/**
@@ -77,8 +79,9 @@ class UpdaterTest extends TestCase {
$status = \OC::$server->getAppManager()->isEnabledForUser('files_trashbin');
(new \OC_App())->enable('files_trashbin');


\OCA\Files_Trashbin\Trashbin::registerHooks();
// register trashbin hooks
$trashbinApp = new Application();
$trashbinApp->boot($this->createMock(IBootContext::class));

$fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder);
$this->assertTrue($fileinfo instanceof \OC\Files\FileInfo);

+ 0
- 41
apps/files_trashbin/appinfo/app.php Näytä tiedosto

@@ -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',
];
});

+ 38
- 36
apps/files_trashbin/lib/AppInfo/Application.php Näytä tiedosto

@@ -27,57 +27,59 @@

namespace OCA\Files_Trashbin\AppInfo;

use OCA\DAV\CalDAV\Proxy\ProxyMapper;
use OCA\DAV\Connector\Sabre\Principal;
use OCA\Files_Trashbin\Capabilities;
use OCA\Files_Trashbin\Expiration;
use OCA\Files_Trashbin\Trash\ITrashManager;
use OCA\Files_Trashbin\Trash\TrashManager;
use OCP\App\IAppManager;
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 = []) {
parent::__construct('files_trashbin', $urlParams);
}

$container = $this->getContainer();
/*
* Register capabilities
*/
$container->registerCapability(Capabilities::class);
public function register(IRegistrationContext $context): void {
$context->registerCapability(Capabilities::class);

/*
* Register expiration
*/
$container->registerAlias('Expiration', Expiration::class);
$context->registerServiceAlias('Expiration', Expiration::class);
$context->registerServiceAlias(ITrashManager::class, TrashManager::class);
/** Register $principalBackend for the DAV collection */
$context->registerServiceAlias('principalBackend', Principal::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()
);
});
public function boot(IBootContext $context): void {
$context->injectFn([$this, 'registerTrashBackends']);

$container->registerService(ITrashManager::class, function () {
return new TrashManager();
});
// 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');

$this->registerTrashBackends();
\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() {
$server = $this->getContainer()->getServer();
$logger = $server->getLogger();
$appManager = $server->getAppManager();
/** @var ITrashManager $trashManager */
$trashManager = $this->getContainer()->getServer()->query(ITrashManager::class);
public function registerTrashBackends(IServerContainer $serverContainer, ILogger $logger, IAppManager $appManager, ITrashManager $trashManager) {
foreach ($appManager->getInstalledApps() as $app) {
$appInfo = $appManager->getAppInfo($app);
if (isset($appInfo['trash'])) {
@@ -87,7 +89,7 @@ class Application extends App {
$for = $backend['@attributes']['for'];

try {
$backendObject = $server->query($class);
$backendObject = $serverContainer->query($class);
$trashManager->registerBackend($for, $backendObject);
} catch (\Exception $e) {
$logger->logException($e);

+ 0
- 14
apps/files_trashbin/lib/Trashbin.php Näytä tiedosto

@@ -1008,20 +1008,6 @@ class Trashbin {
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
*

+ 5
- 1
apps/files_trashbin/tests/StorageTest.php Näytä tiedosto

@@ -34,9 +34,11 @@ namespace OCA\Files_Trashbin\Tests;

use OC\Files\Filesystem;
use OC\Files\Storage\Temporary;
use OCA\Files_Trashbin\AppInfo\Application;
use OCA\Files_Trashbin\Events\MoveToTrashEvent;
use OCA\Files_Trashbin\Storage;
use OCA\Files_Trashbin\Trash\ITrashManager;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\Cache\ICache;
use OCP\Files\Folder;
@@ -75,7 +77,9 @@ class StorageTest extends \Test\TestCase {
parent::setUp();

\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');
\OC::$server->getUserManager()->createUser($this->user, $this->user);

+ 6
- 2
apps/files_trashbin/tests/TrashbinTest.php Näytä tiedosto

@@ -30,6 +30,9 @@
*/

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;

/**
@@ -83,8 +86,9 @@ class TrashbinTest extends \Test\TestCase {
$expiration = \OC::$server->query(\OCA\Files_Trashbin\Expiration::class);
$expiration->setRetentionObligation('auto, 2');

// register hooks
\OCA\Files_Trashbin\Trashbin::registerHooks();
// register trashbin hooks
$trashbinApp = new TrashbinApplication();
$trashbinApp->boot(new BootContext(new DIContainer('', [], \OC::$server)));

// create test user
self::loginHelper(self::TEST_TRASHBIN_USER2, true);

Loading…
Peruuta
Tallenna