summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2021-08-04 18:59:47 +0200
committerJohn Molakvoæ <skjnldsv@protonmail.com>2021-10-19 11:31:07 +0200
commitab275c5e38de80b6cbc1a60890d8076f5075cace (patch)
tree098244abbe6919fd5847f8390f19cb0b8dc1b39e
parent1b16a136ebd8f63e09df061d383f34170e2cef35 (diff)
downloadnextcloud-server-ab275c5e38de80b6cbc1a60890d8076f5075cace.tar.gz
nextcloud-server-ab275c5e38de80b6cbc1a60890d8076f5075cace.zip
move files_sharing to IBootStrap
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r--apps/files_sharing/appinfo/app.php34
-rw-r--r--apps/files_sharing/lib/AppInfo/Application.php84
-rw-r--r--apps/files_sharing/lib/External/Manager.php31
3 files changed, 47 insertions, 102 deletions
diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php
deleted file mode 100644
index 79be3732773..00000000000
--- a/apps/files_sharing/appinfo/app.php
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Björn Schießle <bjoern@schiessle.org>
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- *
- * @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/>
- *
- */
-use OCA\Files_Sharing\ShareBackend\File;
-use OCA\Files_Sharing\ShareBackend\Folder;
-use OCA\Files_Sharing\AppInfo\Application;
-
-\OCA\Files_Sharing\Helper::registerHooks();
-
-\OC\Share\Share::registerBackend('file', File::class);
-\OC\Share\Share::registerBackend('folder', Folder::class, 'file');
-
-\OC::$server->query(Application::class);
diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php
index 2dfbe4d86a5..9d2ddec544a 100644
--- a/apps/files_sharing/lib/AppInfo/Application.php
+++ b/apps/files_sharing/lib/AppInfo/Application.php
@@ -29,10 +29,11 @@
*/
namespace OCA\Files_Sharing\AppInfo;
-use OC\AppFramework\Utility\SimpleContainer;
+use OC\Share\Share;
use OCA\Files_Sharing\Capabilities;
use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent;
use OCA\Files_Sharing\External\Manager;
+use OCA\Files_Sharing\Helper;
use OCA\Files_Sharing\Listener\LegacyBeforeTemplateRenderedListener;
use OCA\Files_Sharing\Listener\LoadAdditionalListener;
use OCA\Files_Sharing\Listener\LoadSidebarListener;
@@ -47,71 +48,35 @@ use OCA\Files_Sharing\Notification\Listener;
use OCA\Files_Sharing\Notification\Notifier;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\Files\Event\LoadSidebar;
+use OCA\Files_Sharing\ShareBackend\File;
+use OCA\Files_Sharing\ShareBackend\Folder;
use OCP\AppFramework\App;
+use OCP\AppFramework\Bootstrap\IBootContext;
+use OCP\AppFramework\Bootstrap\IBootstrap;
+use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Federation\ICloudIdManager;
use OCP\Files\Config\IMountProviderCollection;
use OCP\Group\Events\UserAddedEvent;
use OCP\IDBConnection;
use OCP\IGroup;
-use OCP\IServerContainer;
use OCP\IUserSession;
use OCP\Share\Events\ShareCreatedEvent;
use OCP\Share\IManager;
use OCP\Util;
use Psr\Container\ContainerInterface;
-use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
-class Application extends App {
+class Application extends App implements IBootstrap {
public const APP_ID = 'files_sharing';
public function __construct(array $urlParams = []) {
parent::__construct(self::APP_ID, $urlParams);
+ }
- $container = $this->getContainer();
-
- /** @var IServerContainer $server */
- $server = $container->getServer();
-
- /** @var IEventDispatcher $dispatcher */
- $dispatcher = $container->query(IEventDispatcher::class);
- $oldDispatcher = $container->getServer()->getEventDispatcher();
- $mountProviderCollection = $server->getMountProviderCollection();
- $notifications = $server->getNotificationManager();
-
- /**
- * Core class wrappers
- */
- $container->registerService(Manager::class, function (SimpleContainer $c) use ($server) {
- $user = $server->getUserSession()->getUser();
- $uid = $user ? $user->getUID() : null;
- return new \OCA\Files_Sharing\External\Manager(
- $server->getDatabaseConnection(),
- \OC\Files\Filesystem::getMountManager(),
- \OC\Files\Filesystem::getLoader(),
- $server->getHTTPClientService(),
- $server->getNotificationManager(),
- $server->query(\OCP\OCS\IDiscoveryService::class),
- $server->getCloudFederationProviderManager(),
- $server->getCloudFederationFactory(),
- $server->getGroupManager(),
- $server->getUserManager(),
- $uid,
- $server->query(IEventDispatcher::class),
- $server->get(LoggerInterface::class)
- );
- });
-
- /**
- * Middleware
- */
- $container->registerMiddleWare(SharingCheckMiddleware::class);
- $container->registerMiddleWare(OCSShareAPIMiddleware::class);
- $container->registerMiddleWare(ShareInfoMiddleware::class);
-
- $container->registerService('ExternalMountProvider', function (ContainerInterface $c) {
+ public function register(IRegistrationContext $context): void {
+ $context->registerService('ExternalMountProvider', function (ContainerInterface $c) {
return new \OCA\Files_Sharing\External\MountProvider(
$c->get(IDBConnection::class),
function () use ($c) {
@@ -122,15 +87,25 @@ class Application extends App {
});
/**
- * Register capabilities
+ * Middleware
*/
- $container->registerCapability(Capabilities::class);
+ $context->registerMiddleWare(SharingCheckMiddleware::class);
+ $context->registerMiddleWare(OCSShareAPIMiddleware::class);
+ $context->registerMiddleWare(ShareInfoMiddleware::class);
- $notifications->registerNotifierService(Notifier::class);
+ $context->registerCapability(Capabilities::class);
- $this->registerMountProviders($mountProviderCollection);
- $this->registerEventsScripts($dispatcher, $oldDispatcher);
- $this->setupSharingMenus();
+ $context->registerNotifierService(Notifier::class);
+ }
+
+ public function boot(IBootContext $context): void {
+ $context->injectFn([$this, 'registerMountProviders']);
+ $context->injectFn([$this, 'registerEventsScripts']);
+
+ Helper::registerHooks();
+
+ Share::registerBackend('file', File::class);
+ Share::registerBackend('folder', Folder::class, 'file');
/**
* Always add main sharing script
@@ -138,12 +113,13 @@ class Application extends App {
Util::addScript(self::APP_ID, 'dist/main');
}
- protected function registerMountProviders(IMountProviderCollection $mountProviderCollection) {
+
+ public function registerMountProviders(IMountProviderCollection $mountProviderCollection) {
$mountProviderCollection->registerProvider($this->getContainer()->query(MountProvider::class));
$mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider'));
}
- protected function registerEventsScripts(IEventDispatcher $dispatcher, EventDispatcherInterface $oldDispatcher) {
+ public function registerEventsScripts(IEventDispatcher $dispatcher, EventDispatcherInterface $oldDispatcher) {
// sidebar and files scripts
$dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class);
$dispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, LegacyBeforeTemplateRenderedListener::class);
diff --git a/apps/files_sharing/lib/External/Manager.php b/apps/files_sharing/lib/External/Manager.php
index d967f40cc32..a48e2a63ae4 100644
--- a/apps/files_sharing/lib/External/Manager.php
+++ b/apps/files_sharing/lib/External/Manager.php
@@ -31,6 +31,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
+
namespace OCA\Files_Sharing\External;
use Doctrine\DBAL\Driver\Exception;
@@ -47,6 +48,7 @@ use OCP\Http\Client\IClientService;
use OCP\IDBConnection;
use OCP\IGroupManager;
use OCP\IUserManager;
+use OCP\IUserSession;
use OCP\Notification\IManager;
use OCP\OCS\IDiscoveryService;
use OCP\Share;
@@ -83,7 +85,7 @@ class Manager {
/** @var ICloudFederationFactory */
private $cloudFederationFactory;
- /** @var IGroupManager */
+ /** @var IGroupManager */
private $groupManager;
/** @var IUserManager */
@@ -96,25 +98,26 @@ class Manager {
private $logger;
public function __construct(
- IDBConnection $connection,
- \OC\Files\Mount\Manager $mountManager,
- IStorageFactory $storageLoader,
- IClientService $clientService,
- IManager $notificationManager,
- IDiscoveryService $discoveryService,
+ IDBConnection $connection,
+ \OC\Files\Mount\Manager $mountManager,
+ IStorageFactory $storageLoader,
+ IClientService $clientService,
+ IManager $notificationManager,
+ IDiscoveryService $discoveryService,
ICloudFederationProviderManager $cloudFederationProviderManager,
- ICloudFederationFactory $cloudFederationFactory,
- IGroupManager $groupManager,
- IUserManager $userManager,
- ?string $uid,
- IEventDispatcher $eventDispatcher,
- LoggerInterface $logger
+ ICloudFederationFactory $cloudFederationFactory,
+ IGroupManager $groupManager,
+ IUserManager $userManager,
+ IUserSession $userSession,
+ IEventDispatcher $eventDispatcher,
+ LoggerInterface $logger
) {
+ $user = $userSession->getUser();
$this->connection = $connection;
$this->mountManager = $mountManager;
$this->storageLoader = $storageLoader;
$this->clientService = $clientService;
- $this->uid = $uid;
+ $this->uid = $user ? $user->getUID() : null;
$this->notificationManager = $notificationManager;
$this->discoveryService = $discoveryService;
$this->cloudFederationProviderManager = $cloudFederationProviderManager;