diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2019-11-06 10:11:23 +0100 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2019-11-06 10:11:23 +0100 |
commit | 866c513871a71d0054f8a098893a3a5535ff4c5d (patch) | |
tree | e4cabe6052ac707d757796c1c177c38b19cb75c6 /apps/files_versions | |
parent | 6ba2a608d08ec3c1fd440ac2d0a9cfad569da234 (diff) | |
download | nextcloud-server-866c513871a71d0054f8a098893a3a5535ff4c5d.tar.gz nextcloud-server-866c513871a71d0054f8a098893a3a5535ff4c5d.zip |
Fix files_versions app LoadSidebar event
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/files_versions')
-rw-r--r-- | apps/files_versions/appinfo/app.php | 3 | ||||
-rw-r--r-- | apps/files_versions/composer/composer/autoload_classmap.php | 2 | ||||
-rw-r--r-- | apps/files_versions/composer/composer/autoload_static.php | 2 | ||||
-rw-r--r-- | apps/files_versions/lib/AppInfo/Application.php | 39 | ||||
-rw-r--r-- | apps/files_versions/lib/Hooks.php | 43 | ||||
-rw-r--r-- | apps/files_versions/lib/Listener/LoadAdditionalListener.php | 45 | ||||
-rw-r--r-- | apps/files_versions/lib/Listener/LoadSidebarListener.php | 45 |
7 files changed, 149 insertions, 30 deletions
diff --git a/apps/files_versions/appinfo/app.php b/apps/files_versions/appinfo/app.php index f28210553c2..030e8c80bff 100644 --- a/apps/files_versions/appinfo/app.php +++ b/apps/files_versions/appinfo/app.php @@ -22,4 +22,5 @@ * */ -\OCA\Files_Versions\Hooks::connectHooks(); +\OC::$server->query(\OCA\Files_Versions\AppInfo\Application::class); + diff --git a/apps/files_versions/composer/composer/autoload_classmap.php b/apps/files_versions/composer/composer/autoload_classmap.php index 40daaff2cc5..19f08f9927d 100644 --- a/apps/files_versions/composer/composer/autoload_classmap.php +++ b/apps/files_versions/composer/composer/autoload_classmap.php @@ -16,6 +16,8 @@ return array( 'OCA\\Files_Versions\\Events\\CreateVersionEvent' => $baseDir . '/../lib/Events/CreateVersionEvent.php', 'OCA\\Files_Versions\\Expiration' => $baseDir . '/../lib/Expiration.php', 'OCA\\Files_Versions\\Hooks' => $baseDir . '/../lib/Hooks.php', + 'OCA\\Files_Versions\\Listener\\LoadAdditionalListener' => $baseDir . '/../lib/Listener/LoadAdditionalListener.php', + 'OCA\\Files_Versions\\Listener\\LoadSidebarListener' => $baseDir . '/../lib/Listener/LoadSidebarListener.php', 'OCA\\Files_Versions\\Sabre\\Plugin' => $baseDir . '/../lib/Sabre/Plugin.php', 'OCA\\Files_Versions\\Sabre\\RestoreFolder' => $baseDir . '/../lib/Sabre/RestoreFolder.php', 'OCA\\Files_Versions\\Sabre\\RootCollection' => $baseDir . '/../lib/Sabre/RootCollection.php', diff --git a/apps/files_versions/composer/composer/autoload_static.php b/apps/files_versions/composer/composer/autoload_static.php index 46ed474dc31..a6fa927bc12 100644 --- a/apps/files_versions/composer/composer/autoload_static.php +++ b/apps/files_versions/composer/composer/autoload_static.php @@ -31,6 +31,8 @@ class ComposerStaticInitFiles_Versions 'OCA\\Files_Versions\\Events\\CreateVersionEvent' => __DIR__ . '/..' . '/../lib/Events/CreateVersionEvent.php', 'OCA\\Files_Versions\\Expiration' => __DIR__ . '/..' . '/../lib/Expiration.php', 'OCA\\Files_Versions\\Hooks' => __DIR__ . '/..' . '/../lib/Hooks.php', + 'OCA\\Files_Versions\\Listener\\LoadAdditionalListener' => __DIR__ . '/..' . '/../lib/Listener/LoadAdditionalListener.php', + 'OCA\\Files_Versions\\Listener\\LoadSidebarListener' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarListener.php', 'OCA\\Files_Versions\\Sabre\\Plugin' => __DIR__ . '/..' . '/../lib/Sabre/Plugin.php', 'OCA\\Files_Versions\\Sabre\\RestoreFolder' => __DIR__ . '/..' . '/../lib/Sabre/RestoreFolder.php', 'OCA\\Files_Versions\\Sabre\\RootCollection' => __DIR__ . '/..' . '/../lib/Sabre/RootCollection.php', diff --git a/apps/files_versions/lib/AppInfo/Application.php b/apps/files_versions/lib/AppInfo/Application.php index 919a9b42d79..c5791f33d3a 100644 --- a/apps/files_versions/lib/AppInfo/Application.php +++ b/apps/files_versions/lib/AppInfo/Application.php @@ -25,24 +25,37 @@ namespace OCA\Files_Versions\AppInfo; use OCA\DAV\CalDAV\Proxy\ProxyMapper; use OCA\DAV\Connector\Sabre\Principal; +use OCA\Files_Versions\Capabilities; +use OCA\Files_Versions\Listener\LoadAdditionalListener; +use OCA\Files_Versions\Listener\LoadSidebarListener; use OCA\Files_Versions\Versions\IVersionManager; use OCA\Files_Versions\Versions\VersionManager; +use OCA\Files_Versions\Hooks; +use OCA\Files\Event\LoadAdditionalScriptsEvent; +use OCA\Files\Event\LoadSidebar; use OCP\AppFramework\App; use OCP\AppFramework\IAppContainer; -use OCA\Files_Versions\Capabilities; +use OCP\EventDispatcher\IEventDispatcher; class Application extends App { - public function __construct(array $urlParams = array()) { - parent::__construct('files_versions', $urlParams); + + const APP_ID = 'files_versions'; + + public function __construct(array $urlParams = []) { + parent::__construct(self::APP_ID, $urlParams); $container = $this->getContainer(); + $server = $container->getServer(); + + /** @var IEventDispatcher $newDispatcher */ + $dispatcher = $server->query(IEventDispatcher::class); - /* + /** * Register capabilities */ $container->registerCapability(Capabilities::class); - /* + /** * Register $principalBackend for the DAV collection */ $container->registerService('principalBackend', function (IAppContainer $c) { @@ -62,6 +75,16 @@ class Application extends App { }); $this->registerVersionBackends(); + + /** + * Register Events + */ + $this->registerEvents($dispatcher); + + /** + * Register hooks + */ + Hooks::connectHooks(); } public function registerVersionBackends() { @@ -98,4 +121,10 @@ class Application extends App { $logger->logException($e); } } + + protected function registerEvents(IEventDispatcher $dispatcher) { + $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class); + $dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarListener::class); + } + } diff --git a/apps/files_versions/lib/Hooks.php b/apps/files_versions/lib/Hooks.php index 4e2dcfa3087..953bd5deca2 100644 --- a/apps/files_versions/lib/Hooks.php +++ b/apps/files_versions/lib/Hooks.php @@ -35,28 +35,30 @@ namespace OCA\Files_Versions; +use OC\Files\Filesystem; +use OC\Files\Mount\MoveableMount; +use OC\Files\View; +use OCP\Util; + class Hooks { public static function connectHooks() { // Listen to write signals - \OCP\Util::connectHook('OC_Filesystem', 'write', Hooks::class, 'write_hook'); + Util::connectHook('OC_Filesystem', 'write', Hooks::class, 'write_hook'); // Listen to delete and rename signals - \OCP\Util::connectHook('OC_Filesystem', 'post_delete', Hooks::class, 'remove_hook'); - \OCP\Util::connectHook('OC_Filesystem', 'delete', Hooks::class, 'pre_remove_hook'); - \OCP\Util::connectHook('OC_Filesystem', 'post_rename', Hooks::class, 'rename_hook'); - \OCP\Util::connectHook('OC_Filesystem', 'post_copy', Hooks::class, 'copy_hook'); - \OCP\Util::connectHook('OC_Filesystem', 'rename', Hooks::class, 'pre_renameOrCopy_hook'); - \OCP\Util::connectHook('OC_Filesystem', 'copy', Hooks::class, 'pre_renameOrCopy_hook'); - - $eventDispatcher = \OC::$server->getEventDispatcher(); - $eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', [Hooks::class, 'onLoadFilesAppScripts']); + Util::connectHook('OC_Filesystem', 'post_delete', Hooks::class, 'remove_hook'); + Util::connectHook('OC_Filesystem', 'delete', Hooks::class, 'pre_remove_hook'); + Util::connectHook('OC_Filesystem', 'post_rename', Hooks::class, 'rename_hook'); + Util::connectHook('OC_Filesystem', 'post_copy', Hooks::class, 'copy_hook'); + Util::connectHook('OC_Filesystem', 'rename', Hooks::class, 'pre_renameOrCopy_hook'); + Util::connectHook('OC_Filesystem', 'copy', Hooks::class, 'pre_renameOrCopy_hook'); } /** * listen to write event. */ public static function write_hook( $params ) { - $path = $params[\OC\Files\Filesystem::signal_param_path]; + $path = $params[Filesystem::signal_param_path]; if($path !== '') { Storage::store($path); } @@ -71,7 +73,7 @@ class Hooks { * cleanup the versions directory if the actual file gets deleted */ public static function remove_hook($params) { - $path = $params[\OC\Files\Filesystem::signal_param_path]; + $path = $params[Filesystem::signal_param_path]; if($path !== '') { Storage::delete($path); } @@ -82,7 +84,7 @@ class Hooks { * @param array $params */ public static function pre_remove_hook($params) { - $path = $params[\OC\Files\Filesystem::signal_param_path]; + $path = $params[Filesystem::signal_param_path]; if($path !== '') { Storage::markDeletedFile($path); } @@ -129,26 +131,19 @@ class Hooks { public static function pre_renameOrCopy_hook($params) { // if we rename a movable mount point, then the versions don't have // to be renamed - $absOldPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files' . $params['oldpath']); - $manager = \OC\Files\Filesystem::getMountManager(); + $absOldPath = Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files' . $params['oldpath']); + $manager = Filesystem::getMountManager(); $mount = $manager->find($absOldPath); $internalPath = $mount->getInternalPath($absOldPath); - if ($internalPath === '' and $mount instanceof \OC\Files\Mount\MoveableMount) { + if ($internalPath === '' and $mount instanceof MoveableMount) { return; } - $view = new \OC\Files\View(\OCP\User::getUser() . '/files'); + $view = new View(\OCP\User::getUser() . '/files'); if ($view->file_exists($params['newpath'])) { Storage::store($params['newpath']); } else { Storage::setSourcePathAndUser($params['oldpath']); } } - - /** - * Load additional scripts when the files app is visible - */ - public static function onLoadFilesAppScripts() { - \OCP\Util::addScript('files_versions', 'files_versions'); - } } diff --git a/apps/files_versions/lib/Listener/LoadAdditionalListener.php b/apps/files_versions/lib/Listener/LoadAdditionalListener.php new file mode 100644 index 00000000000..ad08f10e46c --- /dev/null +++ b/apps/files_versions/lib/Listener/LoadAdditionalListener.php @@ -0,0 +1,45 @@ +<?php +declare(strict_types=1); +/** + * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl> + * + * @author Roeland Jago Douma <roeland@famdouma.nl> + * @author John Molakvoæ <skjnldsv@protonmail.com> + * + * @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_Versions\Listener; + +use OCA\Files_Versions\AppInfo\Application; +use OCA\Files\Event\LoadAdditionalScriptsEvent; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\Util; + +class LoadAdditionalListener implements IEventListener { + public function handle(Event $event): void { + if (!($event instanceof LoadAdditionalScriptsEvent)) { + return; + } + + // TODO: make sure to only include the sidebar script when + // we properly split it between files list and sidebar + Util::addScript(Application::APP_ID, 'files_versions'); + } + +} diff --git a/apps/files_versions/lib/Listener/LoadSidebarListener.php b/apps/files_versions/lib/Listener/LoadSidebarListener.php new file mode 100644 index 00000000000..37125064caf --- /dev/null +++ b/apps/files_versions/lib/Listener/LoadSidebarListener.php @@ -0,0 +1,45 @@ +<?php +declare(strict_types=1); +/** + * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl> + * + * @author Roeland Jago Douma <roeland@famdouma.nl> + * @author John Molakvoæ <skjnldsv@protonmail.com> + * + * @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_Versions\Listener; + +use OCA\Files_Versions\AppInfo\Application; +use OCA\Files\Event\LoadSidebar; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\Util; + +class LoadSidebarListener implements IEventListener { + public function handle(Event $event): void { + if (!($event instanceof LoadSidebar)) { + return; + } + + // TODO: make sure to only include the sidebar script when + // we properly split it between files list and sidebar + Util::addScript(Application::APP_ID, 'files_versions'); + } + +} |