public function PropertyComment::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/ PropertyComment.php, line 28
Class
- PropertyComment
- Class PropertyComment.
Namespace
Drupal\usermerge\Plugin\UserMerge\PropertyCode
public function process(UserInterface $retired, UserInterface $retained, array $settings = []) : void {
try {
$comment_storage = $this->entityTypeManager
->getStorage('comment');
} catch (PluginNotFoundException|InvalidPluginDefinitionException $e) {
throw new UserMergeException('Storage for comment entity has not been found.');
}
$comment_ids = $comment_storage
->getQuery()
->condition('uid', $retired
->id())
->execute();
$comments = $comment_storage
->loadMultiple($comment_ids);
try {
/** @var \Drupal\comment\CommentInterface $comment */
foreach ($comments as $comment) {
$comment
->setOwnerId($retained
->id());
$comment
->save();
}
} catch (EntityStorageException $e) {
throw new UserMergeException('An error occurred during comment reassignment.');
}
}