You are here

public function PropertyMessage::process in User Merge 2.x

Process merge on selected property.

Parameters

\Drupal\user\UserInterface $retired: Retired account.

\Drupal\user\UserInterface $retained: Retained account.

array $settings: Review settings.

Throws

\Drupal\usermerge\Exception\UserMergeException

Overrides UserMergePropertyPluginInterface::process

File

src/Plugin/UserMerge/Property/PropertyMessage.php, line 28

Class

PropertyMessage
Class PropertyMessage.

Namespace

Drupal\usermerge\Plugin\UserMerge\Property

Code

public function process(UserInterface $retired, UserInterface $retained, array $settings = []) : void {
  try {
    $message_storage = $this->entityTypeManager
      ->getStorage('message');
  } catch (PluginNotFoundException|InvalidPluginDefinitionException $e) {
    throw new UserMergeException('Storage for message entity has not been found.');
  }
  $message_ids = $message_storage
    ->getQuery()
    ->condition('uid', $retired
    ->id())
    ->execute();
  $messages = $message_storage
    ->loadMultiple($message_ids);
  try {

    /** @var \Drupal\message\MessageInterface $message */
    foreach ($messages as $message) {
      $message
        ->setOwnerId($retained
        ->id());
      $message
        ->save();
    }
  } catch (EntityStorageException $e) {
    throw new UserMergeException('An error occurred during message reassignment.');
  }
}