@DI\Observe("merge_users")

@param MergeUsersEvent $event
357398
public function onMerge(MergeUsersEvent $event)
    {
        // Replace user of Comment nodes
        $commentCount = $this->commentManager->replaceCommentAuthor($event->getRemoved(), $event->getKept());
        $event->addMessage("[IcapBlogBundle] updated Comment count: $commentCount");

        // Replace user of Post nodes
        $postCount = $this->postManager->replacePostAuthor($event->getRemoved(), $event->getKept());
        $event->addMessage("[IcapBlogBundle] updated Post count: $postCount");

        // Replace user of Blog members
        $this->blogManager->replaceMemberAuthor($event->getRemoved(), $event->getKept());
    }
612881
public function onMerge(MergeUsersEvent $event)
    {
        // Replace user of Subject nodes
        $subjectCount = $this->manager->replaceSubjectUser($event->getRemoved(), $event->getKept());
        $event->addMessage("[ClarolineForumBundle] updated Subject count: $subjectCount");

        // Replace user of Message nodes
        $messageCount = $this->manager->replaceMessageUser($event->getRemoved(), $event->getKept());
        $event->addMessage("[ClarolineForumBundle] updated Message count: $messageCount");
    }
654665
public function index(): void
    {
        if (!userHasPermission('admin:auth:merge:users')) {
            unauthorised();
        }

        // --------------------------------------------------------------------------

        $this->data['page']->title = 'Merge Users';

        // --------------------------------------------------------------------------

        $oInput = Factory::service('Input');
        if ($oInput->post()) {
            try {

                $oFormValidation = Factory::service('FormValidation');

                $oFormValidation->set_rules('user_id', '', 'required');
                $oFormValidation->set_rules('merge_ids', '', 'required');

                $oFormValidation->set_message('required', lang('fv_required'));

                if (!$oFormValidation->run()) {
                    throw new ValidationException(lang('fv_there_were_errors'));
                }

                $iUserId   = (int) $oInput->post('user_id') ?: null;
                $aMergeIds = explode(',', $oInput->post('merge_ids'));
                $bPreview  = !((bool) $oInput->post('do_merge'));

                if (in_array(activeUser('id'), $aMergeIds)) {
                    throw new ValidationException('You cannot list yourself as a user to merge.');
                }

                $oUserModel   = Factory::model('User', 'nails/module-auth');
                $oMergeResult = $oUserModel->merge($iUserId, $aMergeIds, $bPreview);

                if (empty($oMergeResult)) {
                    throw new \RuntimeException('Failed to merge users. ' . $oUserModel->lastError());
                }

                if ($bPreview) {

                    $this->data['mergeResult'] = $oMergeResult;
                    Helper::loadView('preview');
                    return;

                } else {
                    $oSession = Factory::service('Session', 'nails/module-auth');
                    $oSession->setFlashData('success', 'Users were merged successfully.');
                    redirect('admin/auth/merge');
                }

            } catch (\Exception $e) {
                $this->data['error'] = $e->getMessage();
            }
        }

        // --------------------------------------------------------------------------

        //  Load views
        Helper::loadView('index');
    }
263878
public function onMerge(MergeUsersEvent $event)
    {
        // Replace user of CasUser nodes
        $casUserCount = $this->casManager->replaceCasUserUser($event->getRemoved(), $event->getKept());
        $event->addMessage("[ClarolineAuthenticationBundle] updated CasUser count: $casUserCount");
    }
488715
public function ModerationController_MergeDiscussions_Create($Sender) {
      $Session = Gdn::Session();
      $Sender->Form = new Gdn_Form();
      $Sender->Title(T('Merge Discussions'));

      $DiscussionModel = new DiscussionModel();
      $CheckedDiscussions = Gdn::UserModel()->GetAttribute($Session->User->UserID, 'CheckedDiscussions', array());
      if (!is_array($CheckedDiscussions))
         $CheckedDiscussions = array();
       
      $DiscussionIDs = $CheckedDiscussions;
      $Sender->SetData('DiscussionIDs', $DiscussionIDs);
      $CountCheckedDiscussions = count($DiscussionIDs);
      $Sender->SetData('CountCheckedDiscussions', $CountCheckedDiscussions);
      $Discussions = $DiscussionModel->SQL->WhereIn('DiscussionID', $DiscussionIDs)->Get('Discussion')->ResultArray();
      $Sender->SetData('Discussions', $Discussions);
      
      // Perform the merge
      if ($Sender->Form->AuthenticatedPostBack()) {
         // Create a new discussion record
         $MergeDiscussion = FALSE;
         $MergeDiscussionID = $Sender->Form->GetFormValue('MergeDiscussionID');
         foreach ($Discussions as $Discussion) {
            if ($Discussion['DiscussionID'] == $MergeDiscussionID) {
               $MergeDiscussion = $Discussion;
               break;
            }
         }
         if ($MergeDiscussion) {
            $ErrorCount = 0;
            
            // Verify that the user has permission to perform the merge.
            $Category = CategoryModel::Categories($MergeDiscussion['CategoryID']);
            if ($Category && !$Category['PermsDiscussionsEdit'])
               throw PermissionException('Vanilla.Discussions.Edit');
            
            // Assign the comments to the new discussion record
            $DiscussionModel->SQL
               ->Update('Comment')
               ->Set('DiscussionID', $MergeDiscussionID)
               ->WhereIn('DiscussionID', $DiscussionIDs)
               ->Put();
               
            $CommentModel = new CommentModel();
            foreach ($Discussions as $Discussion) {
               if ($Discussion['DiscussionID'] == $MergeDiscussionID)
                  continue;
               
               // Create a comment out of the discussion.
               $Comment = ArrayTranslate($Discussion, array('Body', 'Format', 'DateInserted', 'InsertUserID', 'InsertIPAddress', 'DateUpdated', 'UpdateUserID', 'UpdateIPAddress', 'Attributes', 'Spam', 'Likes', 'Abuse'));
               $Comment['DiscussionID'] = $MergeDiscussionID;
               
               $CommentModel->Validation->Results(TRUE);
               $CommentID = $CommentModel->Save($Comment);
               if ($CommentID) {
                  // Move any attachments (FileUpload plugin awareness)
                  if (class_exists('MediaModel')) {
                     $MediaModel = new MediaModel();
                     $MediaModel->Reassign($Discussion['DiscussionID'], 'discussion', $CommentID, 'comment');
                  }
                  
                  // Delete discussion that was merged
                  $DiscussionModel->Delete($Discussion['DiscussionID']);                  
               } else {
                  $Sender->InformMessage($CommentModel->Validation->ResultsText());
                  $ErrorCount++;
               }
            }
            // Update counts on all affected discussions.
            $CommentModel->UpdateCommentCount($MergeDiscussionID);
            $CommentModel->RemovePageCache($MergeDiscussionID);
   
            // Clear selections
            Gdn::UserModel()->SaveAttribute($Session->UserID, 'CheckedDiscussions', FALSE);
            ModerationController::InformCheckedDiscussions($Sender);
            if ($ErrorCount == 0)
               $Sender->RedirectUrl = Url("/discussion/$MergeDiscussionID/".Gdn_Format::Url($MergeDiscussion['Name']));
         }
      }
      
      $Sender->Render('MergeDiscussions', '', 'plugins/SplitMerge');
   }
1053455
public function onGetUser(GetUserForTokenEvent $event)
    {
        $userProvider = $event->getUserProvider();

        if (!$userProvider instanceof OAuthUserProviderInterface) {
            return;
        }

        $token = $event->getToken();

        if ($user = $userProvider->loadUserByOAuthCredentials($token)) {
            $token->setUser($user);
        }
    }
1316820
public function Merge($OldUserID, $NewUserID) {
      $OldUser = $this->GetID($OldUserID, DATASET_TYPE_ARRAY);
      $NewUser = $this->GetID($NewUserID, DATASET_TYPE_ARRAY);
      
      if (!$OldUser || !$NewUser) {
         throw new Gdn_UserException("Could not find one or both users to merge.");
      }
      
      $Map = array('UserID', 'Name', 'Email', 'CountVisits', 'CountDiscussions', 'CountComments');
      
      $Result = array('MergeID' => NULL, 'Before' => array(
         'OldUser' => ArrayTranslate($OldUser, $Map),
         'NewUser' => ArrayTranslate($NewUser, $Map)));
      
      // Start the merge.
      $MergeID = $this->MergeStart($OldUserID, $NewUserID);
      
      // Copy all discussions from the old user to the new user.
      $this->MergeCopy($MergeID, 'Discussion', 'InsertUserID', $OldUserID, $NewUserID);
      
      // Copy all the comments from the old user to the new user.
      $this->MergeCopy($MergeID, 'Comment', 'InsertUserID', $OldUserID, $NewUserID);
      
      // Copy all of the activities.
      $this->MergeCopy($MergeID, 'Activity', 'NotifyUserID', $OldUserID, $NewUserID);
      $this->MergeCopy($MergeID, 'Activity', 'InsertUserID', $OldUserID, $NewUserID);
      $this->MergeCopy($MergeID, 'Activity', 'ActivityUserID', $OldUserID, $NewUserID);
      
      // Copy all of the activity comments.
      $this->MergeCopy($MergeID, 'ActivityComment', 'InsertUserID', $OldUserID, $NewUserID);
      
      // Copy all conversations.
      $this->MergeCopy($MergeID, 'Conversation', 'InsertUserID', $OldUserID, $NewUserID);
      $this->MergeCopy($MergeID, 'ConversationMessage', 'InsertUserID', $OldUserID, $NewUserID, 'MessageID');
      $this->MergeCopy($MergeID, 'UserConversation', 'UserID', $OldUserID, $NewUserID, 'ConversationID');
      
      $this->MergeFinish($MergeID);
      
      $OldUser = $this->GetID($OldUserID, DATASET_TYPE_ARRAY);
      $NewUser = $this->GetID($NewUserID, DATASET_TYPE_ARRAY);
      
      $Result['MergeID'] = $MergeID;
      $Result['After'] = array(
         'OldUser' => ArrayTranslate($OldUser, $Map),
         'NewUser' => ArrayTranslate($NewUser, $Map));
      
      return $Result;
   }
194073
public static function onFlushContent(Event $event)
    {
        $content = $event->getTarget();
        $application = $event->getApplication();

        $token = $application->getSecurityContext()->getToken();
        if (!($token instanceof BBUserToken)) {
            return;
        }

        $em = $application->getEntityManager();
        $uow = $em->getUnitOfWork();

        if ($uow->isScheduledForInsert($content) && AbstractClassContent::STATE_NEW === $content->getState()) {
            if (null === $draft = $content->getDraft()) {
                $draft = $em->getRepository('BackBee\ClassContent\Revision')->checkout($content, $token);
            }

            $content->setDraft($draft);
            $em->persist($draft);
            $uow->computeChangeSet($em->getClassMetadata('BackBee\ClassContent\Revision'), $draft);
        } elseif ($uow->isScheduledForDelete($content)) {
            $revisions = $em->getRepository('BackBee\ClassContent\Revision')->getRevisions($content);
            foreach ($revisions as $revision) {
                $revision->setContent(null);
                $revision->setState(Revision::STATE_DELETED);
                $uow->computeChangeSet($em->getClassMetadata('BackBee\ClassContent\Revision'), $revision);
            }
        }
    }
544215
public function handle($event): void
    {
        $commentsService = app()->make('InetStudio\Comments\Contracts\Services\Back\CommentsServiceContract');

        $user = $event->user;

        $commentsService->getModel()::where([
            ['user_id', '=', 0],
            ['email', '=', $user->email],
        ])->update([
            'user_id' => $user->id,
            'name' => $user->name,
        ]);
    }
582804
public function postCreate(CreateEvent $event)
    {
        if (in_array(Options::USER_SELF_LOG, $event->getOptions())) {
            $this->userManager->logUser($event->getObject());
        }
    }
196483
public function onPart(Event $event)
    {
        $msg = $event->getMessage();

        if (!isset($msg['nick'])) {
            return;
        }

        $nick = $msg['nick'];
        $chan = $msg['params']['channels'];

        $this->storage->removeUser($nick, $chan);
    }
617643
public function notifyObservers($event){
		foreach(self::$observers as $observer){
			if($event & self::$observers->getInfo())
				$observer->updateStatus($this, $event);
		}
	}
845532
public function onModelAfterSave(Event $event)
    {
        /** @var User|bool $user */
        $user = $event->getData('user');

        if ($user instanceof EntityInterface) {
            if ($user->isNew() && Filter::bool($user->get('notify'))) {
                $this->_getMailer($user)->sendCreateMessage();
            }
        }
    }
343115
public function merge(EventsInterface $source = null)
    {
        if (null === $source) {
            return $this->events;
        }
        $this->events = array_merge($this->events, $source->merge());
    }
319381
public function onMerge(MergeUsersEvent $event)
    {
        // Replace user of Objective nodes
        $objectiveCount = $this->objectiveManager->replaceUser($event->getRemoved(), $event->getKept());
        $event->addMessage("[HeVinciCompetencyBundle] updated Objective count: $objectiveCount");

        // Replace user of UserProgress nodes
        $userProgressCount = $this->progressManager->replaceUserProgressUser($event->getRemoved(), $event->getKept());
        $event->addMessage("[HeVinciCompetencyBundle] updated UserProgress count: $userProgressCount");

        // Replace user of ObjectiveProgress nodes
        $objectiveProgressCount = $this->progressManager->replaceObjectiveProgressUser($event->getRemoved(), $event->getKept());
        $event->addMessage("[HeVinciCompetencyBundle] updated ObjectiveProgress count: $objectiveProgressCount");

        // Replace user of CompetencyProgress nodes
        $competencyProgress = $this->progressManager->replaceCompetencyProgressUser($event->getRemoved(), $event->getKept());
        $event->addMessage("[HeVinciCompetencyBundle] updated CompetencyProgress count: $competencyProgress");

        // Replace user of AbilityProgress nodes
        $abilityProgress = $this->progressManager->replaceAbilityProgressUser($event->getRemoved(), $event->getKept());
        $event->addMessage("[HeVinciCompetencyBundle] updated AbilityProgress count: $abilityProgress");
    }
429342
public function beforeSave(Event $event, User $user)
    {
        if (!$user->isNew() && $user->has('password') && empty($user->password)) {
            $user->unsetProperty('password');
            $user->dirty('password', false);
        }
    }
1181534
public function onUserEntityPreSave(StorageEvent $event)
    {
        /** @var Entity\Users $entityRecord */
        $entityRecord = $event->getContent();

        if ($entityRecord instanceof Entity\Users) {
            $this->passwordHash($entityRecord);
        }
    }