summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2019-09-24 21:56:50 +0200
committerGitHub <noreply@github.com>2019-09-24 21:56:50 +0200
commit88b2d8f2200c856bb0bbef61cbf4539436142ee7 (patch)
tree6a0a08fe69c497442dcb72be8d7d6f60303e8d09
parent61d22ff6cf54af0250a9917ab1b30a5dff1cb236 (diff)
parent5694a04b700114fbf617d068a3a5ba9a4a8a1ca2 (diff)
downloadnextcloud-server-88b2d8f2200c856bb0bbef61cbf4539436142ee7.tar.gz
nextcloud-server-88b2d8f2200c856bb0bbef61cbf4539436142ee7.zip
Merge pull request #16641 from nextcloud/enh/files_additionalscripts
Files additionalscripts to real event
-rw-r--r--apps/comments/composer/composer/autoload_classmap.php1
-rw-r--r--apps/comments/composer/composer/autoload_static.php1
-rw-r--r--apps/comments/lib/AppInfo/Application.php17
-rw-r--r--apps/comments/lib/Listener/LoadAdditionalScripts.php41
-rw-r--r--apps/files/composer/composer/autoload_classmap.php2
-rw-r--r--apps/files/composer/composer/autoload_static.php2
-rw-r--r--apps/files/lib/AppInfo/Application.php7
-rw-r--r--apps/files/lib/Controller/ViewController.php17
-rw-r--r--apps/files/lib/Event/LoadAdditionalScriptsEvent.php40
-rw-r--r--apps/files/lib/Listener/LegacyLoadAdditionalScriptsAdapter.php56
-rw-r--r--apps/files/tests/Controller/ViewControllerTest.php3
11 files changed, 168 insertions, 19 deletions
diff --git a/apps/comments/composer/composer/autoload_classmap.php b/apps/comments/composer/composer/autoload_classmap.php
index 580d38a8439..4f2cfaebde5 100644
--- a/apps/comments/composer/composer/autoload_classmap.php
+++ b/apps/comments/composer/composer/autoload_classmap.php
@@ -15,6 +15,7 @@ return array(
'OCA\\Comments\\Controller\\Notifications' => $baseDir . '/../lib/Controller/Notifications.php',
'OCA\\Comments\\EventHandler' => $baseDir . '/../lib/EventHandler.php',
'OCA\\Comments\\JSSettingsHelper' => $baseDir . '/../lib/JSSettingsHelper.php',
+ 'OCA\\Comments\\Listener\\LoadAdditionalScripts' => $baseDir . '/../lib/Listener/LoadAdditionalScripts.php',
'OCA\\Comments\\Notification\\Listener' => $baseDir . '/../lib/Notification/Listener.php',
'OCA\\Comments\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php',
'OCA\\Comments\\Search\\Provider' => $baseDir . '/../lib/Search/Provider.php',
diff --git a/apps/comments/composer/composer/autoload_static.php b/apps/comments/composer/composer/autoload_static.php
index 46074d6ab80..685a2d3296b 100644
--- a/apps/comments/composer/composer/autoload_static.php
+++ b/apps/comments/composer/composer/autoload_static.php
@@ -30,6 +30,7 @@ class ComposerStaticInitComments
'OCA\\Comments\\Controller\\Notifications' => __DIR__ . '/..' . '/../lib/Controller/Notifications.php',
'OCA\\Comments\\EventHandler' => __DIR__ . '/..' . '/../lib/EventHandler.php',
'OCA\\Comments\\JSSettingsHelper' => __DIR__ . '/..' . '/../lib/JSSettingsHelper.php',
+ 'OCA\\Comments\\Listener\\LoadAdditionalScripts' => __DIR__ . '/..' . '/../lib/Listener/LoadAdditionalScripts.php',
'OCA\\Comments\\Notification\\Listener' => __DIR__ . '/..' . '/../lib/Notification/Listener.php',
'OCA\\Comments\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php',
'OCA\\Comments\\Search\\Provider' => __DIR__ . '/..' . '/../lib/Search/Provider.php',
diff --git a/apps/comments/lib/AppInfo/Application.php b/apps/comments/lib/AppInfo/Application.php
index 916345e4a5f..793d1e9f7be 100644
--- a/apps/comments/lib/AppInfo/Application.php
+++ b/apps/comments/lib/AppInfo/Application.php
@@ -26,10 +26,13 @@ namespace OCA\Comments\AppInfo;
use OCA\Comments\Controller\Notifications;
use OCA\Comments\EventHandler;
use OCA\Comments\JSSettingsHelper;
+use OCA\Comments\Listener\LoadAdditionalScripts;
use OCA\Comments\Notification\Notifier;
use OCA\Comments\Search\Provider;
+use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCP\AppFramework\App;
use OCP\Comments\CommentsEntityEvent;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Util;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -48,7 +51,8 @@ class Application extends App {
public function register() {
$server = $this->getContainer()->getServer();
- $dispatcher = $server->getEventDispatcher();
+ /** @var IEventDispatcher $newDispatcher */
+ $dispatcher = $server->query(IEventDispatcher::class);
$this->registerSidebarScripts($dispatcher);
$this->registerDavEntity($dispatcher);
$this->registerNotifier();
@@ -57,16 +61,11 @@ class Application extends App {
$server->getSearch()->registerProvider(Provider::class, ['apps' => ['files']]);
}
- protected function registerSidebarScripts(EventDispatcherInterface $dispatcher) {
- $dispatcher->addListener(
- 'OCA\Files::loadAdditionalScripts',
- function() {
- Util::addScript('comments', 'comments');
- }
- );
+ protected function registerSidebarScripts(IEventDispatcher $dispatcher) {
+ $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalScripts::class);
}
- protected function registerDavEntity(EventDispatcherInterface $dispatcher) {
+ protected function registerDavEntity(IEventDispatcher $dispatcher) {
$dispatcher->addListener(CommentsEntityEvent::EVENT_ENTITY, function(CommentsEntityEvent $event) {
$event->addEntityCollection('files', function($name) {
$nodes = \OC::$server->getUserFolder()->getById((int)$name);
diff --git a/apps/comments/lib/Listener/LoadAdditionalScripts.php b/apps/comments/lib/Listener/LoadAdditionalScripts.php
new file mode 100644
index 00000000000..b1e9447beab
--- /dev/null
+++ b/apps/comments/lib/Listener/LoadAdditionalScripts.php
@@ -0,0 +1,41 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Comments\Listener;
+
+use OCA\Files\Event\LoadAdditionalScriptsEvent;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use OCP\Util;
+
+class LoadAdditionalScripts implements IEventListener {
+ public function handle(Event $event): void {
+ if (!($event instanceof LoadAdditionalScriptsEvent)) {
+ return;
+ }
+
+ Util::addScript('comments', 'comments');
+ }
+
+}
diff --git a/apps/files/composer/composer/autoload_classmap.php b/apps/files/composer/composer/autoload_classmap.php
index dd0bea25644..3aa59c88b74 100644
--- a/apps/files/composer/composer/autoload_classmap.php
+++ b/apps/files/composer/composer/autoload_classmap.php
@@ -32,6 +32,8 @@ return array(
'OCA\\Files\\Controller\\AjaxController' => $baseDir . '/../lib/Controller/AjaxController.php',
'OCA\\Files\\Controller\\ApiController' => $baseDir . '/../lib/Controller/ApiController.php',
'OCA\\Files\\Controller\\ViewController' => $baseDir . '/../lib/Controller/ViewController.php',
+ 'OCA\\Files\\Event\\LoadAdditionalScriptsEvent' => $baseDir . '/../lib/Event/LoadAdditionalScriptsEvent.php',
'OCA\\Files\\Helper' => $baseDir . '/../lib/Helper.php',
+ 'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => $baseDir . '/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php',
'OCA\\Files\\Service\\TagService' => $baseDir . '/../lib/Service/TagService.php',
);
diff --git a/apps/files/composer/composer/autoload_static.php b/apps/files/composer/composer/autoload_static.php
index ae748b5d4d8..07df2f173f8 100644
--- a/apps/files/composer/composer/autoload_static.php
+++ b/apps/files/composer/composer/autoload_static.php
@@ -47,7 +47,9 @@ class ComposerStaticInitFiles
'OCA\\Files\\Controller\\AjaxController' => __DIR__ . '/..' . '/../lib/Controller/AjaxController.php',
'OCA\\Files\\Controller\\ApiController' => __DIR__ . '/..' . '/../lib/Controller/ApiController.php',
'OCA\\Files\\Controller\\ViewController' => __DIR__ . '/..' . '/../lib/Controller/ViewController.php',
+ 'OCA\\Files\\Event\\LoadAdditionalScriptsEvent' => __DIR__ . '/..' . '/../lib/Event/LoadAdditionalScriptsEvent.php',
'OCA\\Files\\Helper' => __DIR__ . '/..' . '/../lib/Helper.php',
+ 'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => __DIR__ . '/..' . '/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php',
'OCA\\Files\\Service\\TagService' => __DIR__ . '/..' . '/../lib/Service/TagService.php',
);
diff --git a/apps/files/lib/AppInfo/Application.php b/apps/files/lib/AppInfo/Application.php
index cef4b31f85f..6f06faa3cae 100644
--- a/apps/files/lib/AppInfo/Application.php
+++ b/apps/files/lib/AppInfo/Application.php
@@ -30,9 +30,12 @@ use OCA\Files\Activity\Helper;
use OCA\Files\Collaboration\Resources\Listener;
use OCA\Files\Collaboration\Resources\ResourceProvider;
use OCA\Files\Controller\ApiController;
+use OCA\Files\Event\LoadAdditionalScriptsEvent;
+use OCA\Files\Listener\LegacyLoadAdditionalScriptsAdapter;
use OCP\AppFramework\App;
use \OCA\Files\Service\TagService;
use OCP\Collaboration\Resources\IManager;
+use OCP\EventDispatcher\IEventDispatcher;
use \OCP\IContainer;
use OCA\Files\Controller\ViewController;
use OCA\Files\Capabilities;
@@ -85,5 +88,9 @@ class Application extends App {
$resourceManager = $container->query(IManager::class);
$resourceManager->registerResourceProvider(ResourceProvider::class);
Listener::register($server->getEventDispatcher());
+
+ /** @var IEventDispatcher $dispatcher */
+ $dispatcher = $container->query(IEventDispatcher::class);
+ $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LegacyLoadAdditionalScriptsAdapter::class);
}
}
diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php
index 509f927a295..518bbc1bf08 100644
--- a/apps/files/lib/Controller/ViewController.php
+++ b/apps/files/lib/Controller/ViewController.php
@@ -29,13 +29,14 @@
namespace OCA\Files\Controller;
use OCA\Files\Activity\Helper;
+use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\ContentSecurityPolicy;
-use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\App\IAppManager;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
@@ -44,8 +45,6 @@ use OCP\IL10N;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserSession;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
/**
* Class ViewController
@@ -63,7 +62,7 @@ class ViewController extends Controller {
protected $l10n;
/** @var IConfig */
protected $config;
- /** @var EventDispatcherInterface */
+ /** @var IEventDispatcher */
protected $eventDispatcher;
/** @var IUserSession */
protected $userSession;
@@ -79,7 +78,7 @@ class ViewController extends Controller {
IURLGenerator $urlGenerator,
IL10N $l10n,
IConfig $config,
- EventDispatcherInterface $eventDispatcherInterface,
+ IEventDispatcher $eventDispatcher,
IUserSession $userSession,
IAppManager $appManager,
IRootFolder $rootFolder,
@@ -91,7 +90,7 @@ class ViewController extends Controller {
$this->urlGenerator = $urlGenerator;
$this->l10n = $l10n;
$this->config = $config;
- $this->eventDispatcher = $eventDispatcherInterface;
+ $this->eventDispatcher = $eventDispatcher;
$this->userSession = $userSession;
$this->appManager = $appManager;
$this->rootFolder = $rootFolder;
@@ -267,8 +266,8 @@ class ViewController extends Controller {
];
}
- $event = new GenericEvent(null, ['hiddenFields' => []]);
- $this->eventDispatcher->dispatch('OCA\Files::loadAdditionalScripts', $event);
+ $event = new LoadAdditionalScriptsEvent();
+ $this->eventDispatcher->dispatch(LoadAdditionalScriptsEvent::class, $event);
$params = [];
$params['usedSpacePercent'] = (int) $storageInfo['relative'];
@@ -285,7 +284,7 @@ class ViewController extends Controller {
$params['fileNotFound'] = $fileNotFound ? 1 : 0;
$params['appNavigation'] = $nav;
$params['appContents'] = $contentItems;
- $params['hiddenFields'] = $event->getArgument('hiddenFields');
+ $params['hiddenFields'] = $event->getHiddenFields();
$response = new TemplateResponse(
$this->appName,
diff --git a/apps/files/lib/Event/LoadAdditionalScriptsEvent.php b/apps/files/lib/Event/LoadAdditionalScriptsEvent.php
new file mode 100644
index 00000000000..bd3d1a8f4e3
--- /dev/null
+++ b/apps/files/lib/Event/LoadAdditionalScriptsEvent.php
@@ -0,0 +1,40 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Files\Event;
+
+use OCP\EventDispatcher\Event;
+
+class LoadAdditionalScriptsEvent extends Event {
+
+ private $hiddenFields = [];
+
+ public function addHiddenField(string $name, string $value): void {
+ $this->hiddenFields[$name] = $value;
+ }
+
+ public function getHiddenFields(): array {
+ return $this->hiddenFields;
+ }
+}
diff --git a/apps/files/lib/Listener/LegacyLoadAdditionalScriptsAdapter.php b/apps/files/lib/Listener/LegacyLoadAdditionalScriptsAdapter.php
new file mode 100644
index 00000000000..ba89d591227
--- /dev/null
+++ b/apps/files/lib/Listener/LegacyLoadAdditionalScriptsAdapter.php
@@ -0,0 +1,56 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Files\Listener;
+
+use OC\EventDispatcher\SymfonyAdapter;
+use OCA\Files\Event\LoadAdditionalScriptsEvent;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use Symfony\Component\EventDispatcher\GenericEvent;
+
+class LegacyLoadAdditionalScriptsAdapter implements IEventListener {
+
+ /** @var SymfonyAdapter */
+ private $dispatcher;
+
+ public function __construct(SymfonyAdapter $dispatcher) {
+ $this->dispatcher = $dispatcher;
+ }
+
+ public function handle(Event $event): void {
+ if (!($event instanceof LoadAdditionalScriptsEvent)) {
+ return;
+ }
+
+ $legacyEvent = new GenericEvent(null, ['hiddenFields' => []]);
+ $this->dispatcher->dispatch('OCA\Files::loadAdditionalScripts', $legacyEvent);
+
+ $hiddenFields = $legacyEvent->getArgument('hiddenFields');
+ foreach ($hiddenFields as $name => $value) {
+ $event->addHiddenField($name, $value);
+ }
+ }
+
+}
diff --git a/apps/files/tests/Controller/ViewControllerTest.php b/apps/files/tests/Controller/ViewControllerTest.php
index d051ab7258d..eb4e4f6ca2c 100644
--- a/apps/files/tests/Controller/ViewControllerTest.php
+++ b/apps/files/tests/Controller/ViewControllerTest.php
@@ -32,6 +32,7 @@ namespace OCA\Files\Tests\Controller;
use OCA\Files\Activity\Helper;
use OCA\Files\Controller\ViewController;
use OCP\AppFramework\Http;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
@@ -81,7 +82,7 @@ class ViewControllerTest extends TestCase {
$this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->getMock();
$this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
$this->config = $this->getMockBuilder(IConfig::class)->getMock();
- $this->eventDispatcher = $this->getMockBuilder('\Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
+ $this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->userSession = $this->getMockBuilder(IUserSession::class)->getMock();
$this->appManager = $this->getMockBuilder('\OCP\App\IAppManager')->getMock();
$this->user = $this->getMockBuilder(IUser::class)->getMock();