summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2020-09-11 08:45:49 +0200
committerGitHub <noreply@github.com>2020-09-11 08:45:49 +0200
commit9e88559e94f7c5c049f1eb156dbe387355c743aa (patch)
tree5643de7c8638cb7cff5c931dccd0c11e62563b53 /apps
parentd43eeab39daa4c19eef0334a7fe50cd049fd54ce (diff)
parent51fa743c7a4a28fe4323a4a4f608e4ea2534cc09 (diff)
downloadnextcloud-server-9e88559e94f7c5c049f1eb156dbe387355c743aa.tar.gz
nextcloud-server-9e88559e94f7c5c049f1eb156dbe387355c743aa.zip
Merge pull request #22775 from nextcloud/fix/noid/stable19-ldap-group-update-events
[stable19] makes LDAP's group updater dispatch type events
Diffstat (limited to 'apps')
-rw-r--r--apps/user_ldap/lib/Jobs/UpdateGroups.php16
1 files changed, 14 insertions, 2 deletions
diff --git a/apps/user_ldap/lib/Jobs/UpdateGroups.php b/apps/user_ldap/lib/Jobs/UpdateGroups.php
index 6241483cb92..334b63f8363 100644
--- a/apps/user_ldap/lib/Jobs/UpdateGroups.php
+++ b/apps/user_ldap/lib/Jobs/UpdateGroups.php
@@ -43,6 +43,9 @@ use OCA\User_LDAP\LogWrapper;
use OCA\User_LDAP\Mapping\GroupMapping;
use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\User\Manager;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Group\Events\UserAddedEvent;
+use OCP\Group\Events\UserRemovedEvent;
use OCP\ILogger;
class UpdateGroups extends \OC\BackgroundJob\TimedJob {
@@ -93,6 +96,11 @@ class UpdateGroups extends \OC\BackgroundJob\TimedJob {
* @param string[] $groups
*/
private static function handleKnownGroups($groups) {
+ /** @var IEventDispatcher $dispatcher */
+ $dispatcher = \OC::$server->query(IEventDispatcher::class);
+ $groupManager = \OC::$server->getGroupManager();
+ $userManager = \OC::$server->getUserManager();
+
\OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – Dealing with known Groups.', ILogger::DEBUG);
$query = \OC_DB::prepare('
UPDATE `*PREFIX*ldap_group_members`
@@ -104,15 +112,19 @@ class UpdateGroups extends \OC\BackgroundJob\TimedJob {
$knownUsers = unserialize(self::$groupsFromDB[$group]['owncloudusers']);
$actualUsers = self::getGroupBE()->usersInGroup($group);
$hasChanged = false;
+
+ $groupObject = $groupManager->get($group);
foreach (array_diff($knownUsers, $actualUsers) as $removedUser) {
- \OCP\Util::emitHook('OC_User', 'post_removeFromGroup', ['uid' => $removedUser, 'gid' => $group]);
+ $userObject = $userManager->get($removedUser);
+ $dispatcher->dispatchTyped(new UserRemovedEvent($groupObject, $userObject));
\OCP\Util::writeLog('user_ldap',
'bgJ "updateGroups" – "'.$removedUser.'" removed from "'.$group.'".',
ILogger::INFO);
$hasChanged = true;
}
foreach (array_diff($actualUsers, $knownUsers) as $addedUser) {
- \OCP\Util::emitHook('OC_User', 'post_addToGroup', ['uid' => $addedUser, 'gid' => $group]);
+ $userObject = $userManager->get($addedUser);
+ $dispatcher->dispatchTyped(new UserAddedEvent($groupObject, $userObject));
\OCP\Util::writeLog('user_ldap',
'bgJ "updateGroups" – "'.$addedUser.'" added to "'.$group.'".',
ILogger::INFO);