public function PropertyFlag::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/ PropertyFlag.php, line 72
Class
- PropertyFlag
- Class PropertyFlag.
Namespace
Drupal\usermerge\Plugin\UserMerge\PropertyCode
public function process(UserInterface $retired, UserInterface $retained, array $settings = []) : void {
try {
$flagging_storage = $this->entityTypeManager
->getStorage('flagging');
} catch (PluginNotFoundException|InvalidPluginDefinitionException $e) {
throw new UserMergeException('Storage for flagging entity has not been found.');
}
$flaggings_ids = $flagging_storage
->getQuery()
->condition('uid', $retired
->id())
->sort('flag_id')
->execute();
/** @var \Drupal\flag\FlaggingInterface[] $flaggings */
$flaggings = $flagging_storage
->loadMultiple($flaggings_ids);
try {
foreach ($flaggings as $flagging) {
$flag = $flagging
->getFlag();
$entity = $flagging
->getFlaggable();
if (!$flag
->isFlagged($entity, $retained)) {
$flagging
->setOwner($retained);
$flagging
->save();
}
}
} catch (EntityStorageException $e) {
throw new UserMergeException('An error occurred during flag reassignment.');
}
}