diff --git a/src/Plugin/migrate/destination/SmsVerification.php b/src/Plugin/migrate/destination/SmsVerification.php index 8fa38d0..0ab0b64 100644 --- a/src/Plugin/migrate/destination/SmsVerification.php +++ b/src/Plugin/migrate/destination/SmsVerification.php @@ -9,6 +9,7 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\migrate\Plugin\migrate\destination\EntityContentBase; use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Row; +use Drupal\sms\Entity\PhoneNumberVerification; use Drupal\sms\Provider\PhoneNumberVerificationInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -83,16 +84,39 @@ class SmsVerification extends EntityContentBase implements ContainerFactoryPlugi // should be updated on the corresponding user entity. /** @var \Drupal\sms\Entity\PhoneNumberVerification $verification */ $verification = $this->storage->load(reset($return)); - $user_entity = $verification->getEntity(); - $phone_number_settings = $this->phoneNumberVerificationService - ->getPhoneNumberSettingsForEntity($user_entity); - if ($user_entity && $phone_number_settings) { - $phone_field_name = $phone_number_settings->getFieldName('phone_number'); - $user_entity->{$phone_field_name}[$row->getSourceProperty('delta')] = $row->getDestinationProperty('phone'); - $user_entity->save(); - } + $this->setVerifiedValue($verification, $row->getDestinationProperty('phone'), $row->getSourceProperty('delta')); } return $return; } + /** + * {@inheritdoc} + */ + public function rollback(array $destination_identifier) { + // Remove the verified user phone number. + parent::rollback($destination_identifier); + /** @var \Drupal\sms\Entity\PhoneNumberVerification $verification */ + $verification = $this->storage->load(reset($destination_identifier)); + $this->setVerifiedValue($verification, NULL); + } + + /** + * @param \Drupal\sms\Entity\PhoneNumberVerification $verification + * The phone number verification for a given user entity. + * @param string $value + * The verified value to set for the user entity. + * @param int $delta + * The specific item of the phone number field to set. + */ + protected function setVerifiedValue(PhoneNumberVerification $verification, $value, $delta = 0) { + $user_entity = $verification->getEntity(); + $phone_number_settings = $this->phoneNumberVerificationService + ->getPhoneNumberSettingsForEntity($user_entity); + if ($user_entity && $phone_number_settings) { + $phone_field_name = $phone_number_settings->getFieldName('phone_number'); + $user_entity->{$phone_field_name}[$delta] = $value; + $user_entity->save(); + } + } + }