You are here

class PropertyComment in User Merge 2.x

Class PropertyComment.

@UserMergeProperty( id = "property_comment", name = @Translation("Comment data"), description = @Translation("Reassign comments associated with the retired user."), review = "", provider = "comment" ) @package Drupal\usermerge\Plugin\UserMerge\Property

Hierarchy

Expanded class hierarchy of PropertyComment

File

src/Plugin/UserMerge/Property/PropertyComment.php, line 23

Namespace

Drupal\usermerge\Plugin\UserMerge\Property
View source
class PropertyComment extends UserMergePropertyBase {

  /**
   * {@inheritDoc}
   */
  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.');
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 2
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PropertyComment::process public function Process merge on selected property. Overrides UserMergePropertyPluginInterface::process
UserMergePropertyBase::$entityTypeManager protected property Entity type manager.
UserMergePropertyBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 3
UserMergePropertyBase::getName public function Return the name of the property plugin. Overrides UserMergePropertyPluginInterface::getName
UserMergePropertyBase::getReviewForm public function Get the review form if it is provided by the plugin. Overrides UserMergePropertyPluginInterface::getReviewForm
UserMergePropertyBase::__construct public function PropertyComment constructor. Overrides PluginBase::__construct 3