Skip to content

[WIP] Migrate from old hooks to symfony events #608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
use OCA\Activity\Controller\Settings;
use OCA\Activity\Data;
use OCA\Activity\DataHelper;
use OCA\Activity\FilesHooksStatic;
use OCA\Activity\GroupHelper;
use OCA\Activity\FilesHooks;
use OCA\Activity\Hooks;
use OCA\Activity\MailQueueHandler;
use OCA\Activity\Navigation;
use OCA\Activity\Parameter\Factory;
Expand Down Expand Up @@ -287,7 +289,8 @@ public function registerHooksAndEvents() {
$eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
$eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', ['OCA\Activity\FilesHooksStatic', 'onLoadFilesAppScripts']);

Util::connectHook('OC_User', 'post_deleteUser', 'OCA\Activity\Hooks', 'deleteUser');
$activityHook = new Hooks();
$eventDispatcher->addListener('user.afterdelete', [$activityHook, 'deleteUser']);

$this->registerFilesActivity();
}
Expand All @@ -296,13 +299,16 @@ public function registerHooksAndEvents() {
* Register the hooks for filesystem operations
*/
public function registerFilesActivity() {
$filesHooksStatic = new FilesHooksStatic();
$eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();

// All other events from other apps have to be send via the Consumer
Util::connectHook('OC_Filesystem', 'post_create', 'OCA\Activity\FilesHooksStatic', 'fileCreate');
Util::connectHook('OC_Filesystem', 'post_update', 'OCA\Activity\FilesHooksStatic', 'fileUpdate');
Util::connectHook('OC_Filesystem', 'delete', 'OCA\Activity\FilesHooksStatic', 'fileDelete');
Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', 'OCA\Activity\FilesHooksStatic', 'fileRestore');
Util::connectHook('OCP\Share', 'post_shared', 'OCA\Activity\FilesHooksStatic', 'share');
Util::connectHook('OCP\Share', 'pre_unshare', 'OCA\Activity\FilesHooksStatic', 'unShare');
$eventDispatcher->addListener('file.aftercreateshare', [$filesHooksStatic, 'share']);
$eventDispatcher->addListener('file.beforeunshare', [$filesHooksStatic, 'unshare']);
}

}
55 changes: 39 additions & 16 deletions lib/FilesHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\Share;
use Symfony\Component\EventDispatcher\GenericEvent;

/**
* The class to handle the filesystem hooks
Expand Down Expand Up @@ -224,32 +225,54 @@ protected function getSourcePathAndOwner($path) {

/**
* Manage sharing events
* @param array $params The hook params
* @param GenericEvent $params The hook params
*/
public function share($params) {
if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
if ((int) $params['shareType'] === Share::SHARE_TYPE_USER) {
$this->shareFileOrFolderWithUser($params['shareWith'], (int) $params['fileSource'], $params['itemType'], $params['fileTarget'], true);
} else if ((int) $params['shareType'] === Share::SHARE_TYPE_GROUP) {
$this->shareFileOrFolderWithGroup($params['shareWith'], (int) $params['fileSource'], $params['itemType'], $params['fileTarget'], (int) $params['id'], true);
public function share(GenericEvent $params) {
\OC::$server->getLogger()->warning(__METHOD__ . " LOOPING . First take the count = " . count($params->getArguments()));
foreach ($params->getArguments() as $argument) {
\OC::$server->getLogger()->warning(__METHOD__ . " val = $argument");
}
if ($params->getArgument('itemType') === 'file' || $params->getArgument('itemType') === 'folder') {
if ((int) $params->getArgument('shareType') === Share::SHARE_TYPE_USER) {
$this->shareFileOrFolderWithUser($params->getArgument('shareWith'),
(int) $params->getArgument('fileSource'),
$params->getArgument('itemType'),
$params->getArgument('fileTarget'), true);
} else if ((int) $params->getArgument('shareType') === Share::SHARE_TYPE_GROUP) {
$this->shareFileOrFolderWithGroup($params->getArgument('shareWith'),
(int) $params->getArgument('fileSource'),
$params->getArgument('itemType'),
$params->getArgument('fileTarget'),
(int) $params->getArgument('id'), true);
} else if ((int) $params['shareType'] === Share::SHARE_TYPE_LINK) {
$this->shareFileOrFolderByLink((int) $params['fileSource'], $params['itemType'], $params['uidOwner'], true);
$this->shareFileOrFolderByLink((int) $params->getArgument('fileSource'),
$params->getArgument('itemType'),
$params->getArgument('uidOwner'), true);
}
}
}

/**
* Manage sharing events
* @param array $params The hook params
* @param GenericEvent $params The hook params
*/
public function unShare($params) {
if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
if ((int) $params['shareType'] === Share::SHARE_TYPE_USER) {
$this->shareFileOrFolderWithUser($params['shareWith'], (int) $params['fileSource'], $params['itemType'], $params['fileTarget'], false);
} else if ((int) $params['shareType'] === Share::SHARE_TYPE_GROUP) {
$this->shareFileOrFolderWithGroup($params['shareWith'], (int) $params['fileSource'], $params['itemType'], $params['fileTarget'], (int) $params['id'], false);
public function unShare(GenericEvent $params) {
if ($params->getArgument('itemType') === 'file' || $params->getArgument('itemType') === 'folder') {
if ((int) $params->getArgument('shareType') === Share::SHARE_TYPE_USER) {
$this->shareFileOrFolderWithUser($params->getArgument('shareWith'),
(int) $params->getArgument('fileSource'),
$params->getArgument('itemType'),
$params->getArgument('fileTarget'), false);
} else if ((int) $params->getArgument('shareType') === Share::SHARE_TYPE_GROUP) {
$this->shareFileOrFolderWithGroup($params->getArgument('shareWith'),
(int) $params->getArgument('fileSource'),
$params->getArgument('itemType'),
$params->getArgument('fileTarget'),
(int) $params->getArgument('id'), false);
} else if ((int) $params['shareType'] === Share::SHARE_TYPE_LINK) {
$this->shareFileOrFolderByLink((int) $params['fileSource'], $params['itemType'], $params['uidOwner'], false);
$this->shareFileOrFolderByLink((int) $params->getArgument('fileSource'),
$params->getArgument('itemType'),
$params->getArgument('uidOwner'), false);
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions lib/FilesHooksStatic.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
namespace OCA\Activity;

use OCP\Util;
use Symfony\Component\EventDispatcher\GenericEvent;

/**
* The class to handle the filesystem hooks
Expand Down Expand Up @@ -71,17 +72,17 @@ public static function fileRestore($params) {

/**
* Manage sharing events
* @param array $params The hook params
* @param GenericEvent $params The hook params
*/
public static function share($params) {
public static function share(GenericEvent $params) {
self::getHooks()->share($params);
}

/**
* Manage sharing events
* @param array $params The hook params
* @param GenericEvent $params The hook params
*/
public static function unShare($params) {
public static function unShare(GenericEvent $params) {
self::getHooks()->unShare($params);
}

Expand Down
7 changes: 4 additions & 3 deletions lib/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

use OCA\Activity\AppInfo\Application;
use OCP\IDBConnection;
use Symfony\Component\EventDispatcher\GenericEvent;

/**
* Handles the stream and mail queue of a user when he is being deleted
Expand All @@ -33,10 +34,10 @@ class Hooks {
*
* @param array $params The hook params
*/
static public function deleteUser($params) {
static public function deleteUser(GenericEvent $params) {
$connection = \OC::$server->getDatabaseConnection();
self::deleteUserStream($params['uid']);
self::deleteUserMailQueue($connection, $params['uid']);
self::deleteUserStream($params->getArgument('uid'));
self::deleteUserMailQueue($connection, $params->getArgument('uid'));
}

/**
Expand Down