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\UserRemovedEvent;
use OCP\ILogger;
class UpdateGroups extends \OC\BackgroundJob\TimedJob {
* @param string[] $groups
*/
private static function handleKnownGroups($groups) {
+ $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`
$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);
*
*/
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Group\Events\UserRemovedEvent;
use OCP\ILogger;
use OCP\Share;
public static function registerShareHooks() {
if (\OC::$server->getSystemConfig()->getValue('installed')) {
OC_Hook::connect('OC_User', 'post_deleteUser', Hooks::class, 'post_deleteUser');
- OC_Hook::connect('OC_User', 'post_removeFromGroup', Hooks::class, 'post_removeFromGroupLDAP');
OC_Hook::connect('OC_User', 'post_deleteGroup', Hooks::class, 'post_deleteGroup');
- /** @var \OCP\EventDispatcher\IEventDispatcher $dispatcher */
- $dispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class);
+ /** @var IEventDispatcher $dispatcher */
+ $dispatcher = \OC::$server->get(IEventDispatcher::class);
$dispatcher->addServiceListener(UserRemovedEvent::class, \OC\Share20\UserRemovedListener::class);
}
}
public static function post_deleteGroup($arguments) {
\OC::$server->getShareManager()->groupDeleted($arguments['gid']);
}
-
- public static function post_removeFromGroupLDAP($arguments) {
- \OC::$server->getShareManager()->userDeletedFromGroup($arguments['uid'], $arguments['gid']);
- }
}
use OC\Files\Cache\Storage;
use OC\Hooks\Emitter;
use OC_Helper;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Group\Events\BeforeUserRemovedEvent;
+use OCP\Group\Events\UserRemovedEvent;
use OCP\IAvatarManager;
use OCP\IConfig;
use OCP\IImage;
/** @var EventDispatcherInterface */
private $dispatcher;
+ /** @var IEventDispatcher */
+ private $newDispatcher;
+
/** @var bool */
private $enabled;
if (is_null($this->urlGenerator)) {
$this->urlGenerator = \OC::$server->getURLGenerator();
}
+ // TODO: inject
+ $this->newDispatcher = \OC::$server->query(IEventDispatcher::class);
}
/**
foreach ($groupManager->getUserGroupIds($this) as $groupId) {
$group = $groupManager->get($groupId);
if ($group) {
- \OC_Hook::emit("OC_Group", "pre_removeFromGroup", ["run" => true, "uid" => $this->uid, "gid" => $groupId]);
+ $this->newDispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $this));
$group->removeUser($this);
- \OC_Hook::emit("OC_User", "post_removeFromGroup", ["uid" => $this->uid, "gid" => $groupId]);
+ $this->newDispatcher->dispatchTyped(new UserRemovedEvent($group, $this));
}
}
// Delete the user's keys in preferences