Fix files_versions app LoadSidebar event

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2019-11-06 10:11:23 +01:00
parent 6ba2a608d0
commit 866c513871
No known key found for this signature in database
GPG Key ID: 60C25B8C072916CF
7 changed files with 149 additions and 30 deletions

View File

@ -22,4 +22,5 @@
*
*/
\OCA\Files_Versions\Hooks::connectHooks();
\OC::$server->query(\OCA\Files_Versions\AppInfo\Application::class);

View File

@ -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',

View File

@ -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',

View File

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

View File

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

View File

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

View File

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