Find every Event for a given user and the replace him by another.

@param User $from
@param User $to

@return int
964558
public function replaceEventUser(User $from, User $to)
    {
        $events = $this->om->getRepository('ClarolineAgendaBundle:Event')->findBy(['user' => $from]);

        if (count($events) > 0) {
            foreach ($events as $event) {
                $event->setUser($to);
            }

            $this->om->flush();
        }

        return count($events);
    }
804822
public function renameTable(string $from, string $to): bool
    {
        $from = $this->quoter->quoteName($from);
        $to = $this->quoter->quoteName($to);
        $this->db->exec(sprintf('RENAME TABLE %s TO %s;', $from, $to));

        return true;
    }
504400
public function replaceAbilityProgressUser(User $from, User $to)
    {
        $abilityyProgresses = $this->abilityProgressRepo->findByUser($from);

        if (count($abilityyProgresses) > 0) {
            foreach ($abilityyProgresses as $abilityyProgress) {
                $abilityyProgress->setUser($to);
            }

            $this->om->flush();
        }

        return count($abilityyProgresses);
    }
170592
public function replaceObjectiveProgressUser(User $from, User $to)
    {
        $objectiveProgresses = $this->objectiveProgressRepo->findByUser($from);

        if (count($objectiveProgresses) > 0) {
            foreach ($objectiveProgresses as $objectiveProgress) {
                $objectiveProgress->setUser($to);
            }

            $this->om->flush();
        }

        return count($objectiveProgresses);
    }
72196
public function setTimeRange($from, $to)
    {
        $fromDate = date('Y-m-d H:i:s', (int) $from);
        $toDate = date('Y-m-d H:i:s', (int) $to);

        $this->where(array("time > '$fromDate'", "time < '$toDate'"));

        return $this;
    }
667323
public function replacePostAuthor(User $from, User $to)
    {
        $posts = $this->repo->findByAuthor($from);

        if (count($posts) > 0) {
            foreach ($posts as $post) {
                $post->setAuthor($to);
            }

            $this->om->flush();
        }

        return count($posts);
    }
815510
private function _replace($from, $to) : array
    {
        $values = $this->getValues();
        foreach($values as $key => $value)
        {
            if ($value === $from)
            {
                $values[$key] = $to;
            }
        }
        return $values;
    }
58720
protected function executeAction($from = null, $to = null)
    {
        $context = $this->getRequest()->getParam('id', 'gems');
        $from    = $this->getRequest()->getParam('from', $from);
        $to      = $this->getRequest()->getParam('to', $to);

        $batch = $this->loader->getTaskRunnerBatch('upgrade' . $context);
        $batch->minimalStepDurationMs = 3000; // 3 seconds max before sending feedback

        if (!$batch->isLoaded()) {
            $this->_upgrades->setBatch($batch);
            $this->_upgrades->execute($context, $to, $from);
        }

        $title = sprintf($this->_('Upgrading %s'), $context);
        $this->_helper->BatchRunner($batch, $title, $this->accesslog);

        $this->html->br();
        $this->compatibilityReportAction();
    }
282801
private function getReplacementString($from, $to)
    {
        if (is_array($from) && is_array($to)) {
            if (count($from) == count($to)) {
                $sedStrings = [];
                $fromSize = count($from);
                for ($i = 0; $i < $fromSize; $i++) {
                    $sedStrings[] = $this->getReplacementCommand($from[$i], $to[$i]);
                }
                return implode(';', $sedStrings);
            } else {
                throw new InvalidArgumentException("Number of items in 'fromText' (" . count($from) . ") is different to 'toText' (" . count($to) . ")");
            }
        } elseif (is_array($from) || is_array($to)) {
            throw new InvalidArgumentException("Only one of fromText or toText is an array, both should be arrays or string");
        } else {
            return $this->getReplacementCommand($from, $to);
        }
    }
1149175
public function replaceDocumentUser(User $from, User $to)
    {
        $documents = $this->documentRepo->findByUser($from);

        if (count($documents) > 0) {
            foreach ($documents as $document) {
                $document->setUser($to);
            }

            $this->om->flush();
        }

        return count($documents);
    }
1201894
public function replaceSubjectUser(User $from, User $to)
    {
        $subjects = $this->subjectRepo->findByCreator($from);
        if (count($subjects) > 0) {
            foreach ($subjects as $subject) {
                $subject->setCreator($to);
            }
            $this->om->flush();
        }

        return count($subjects);
    }
1321292
public function set(UserInterface $fromUser, UserInterface $toUser)
    {
        $event = new ApplySuccessorEvent($fromUser, $toUser);
        $this->dispatcher->dispatch(UserEvents::APPLY_SUCCESSOR, $event);

        $message = UsersMessage::create(
            sprintf('Set "%s" as successor for "%s".', $toUser->getUsername(), $fromUser->getUsername())
        );
        $this->messageService->post($message);
    }
599618
public function replaceUser(User $from, User $to)
    {
        $remoteUserTokens = $this->remoteUserTokenRepo->findByUser($from);

        if (count($remoteUserTokens) > 0) {
            foreach ($remoteUserTokens as $remoteUserToken) {
                $remoteUserToken->setUser($to);
            }

            $this->om->flush();
        }

        return count($remoteUserTokens);
    }
292167
public function replaceUser(User $from, User $to)
    {
        $drops = $this->em->getRepository('IcapDropzoneBundle:Drop')->findByUser($from);

        if (count($drops) > 0) {
            foreach ($drops as $drop) {
                $drop->setUser($to);
            }

            $this->em->flush();
        }

        return count($drops);
    }
1248235
public function rename($from, $to): bool
    {
        $key = $this->search($from);

        if (\is_null($key)) {
            return false;
        }

        $this->items[$key] = $this->getKeyword($to)->getSlug();

        return true;
    }
1150240
public function replace($from, $to)
    {
        $values = $this->_replace($from, $to);
        return new Collection($values);
    }
168144
public function rename($from, $to)
    {
        $from = trim($from, '.');
        $to = trim($to, '.');
        if ($this->has($from)) {
            $value = $this->get($from);
            $this->remove($from);
            $this->set($to, $value);
            return true;
        }
        return false;
    }