diff --git a/src/Importer.php b/src/Importer.php index 62f3c36..664d348 100644 --- a/src/Importer.php +++ b/src/Importer.php @@ -128,10 +128,10 @@ class Importer implements ImporterInterface { $this->linkDomain = $link_domain; $this->accountSwitcher = $account_switcher; - $this->coreUsersUuids = [ - 0 => \Drupal::entityTypeManager()->getStorage('user')->load(0)->uuid(), - 1 => \Drupal::entityTypeManager()->getStorage('user')->load(1)->uuid(), - ]; + $coreUserUids = [0, 1]; + $this->coreUsersUuids = array_map(function ($uid) { + return $this->entityTypeManager()->getStorage('user')->load($uid)->uuid(); + }, $coreUserUids); } /** @@ -142,18 +142,20 @@ class Importer implements ImporterInterface { * @param array $item * Item to extract core user Uuids from. */ - private function overrideCoreUsersUuids(&$item) { + protected function overrideCoreUsersUuids(&$item) { // If the content is from a system user, override its UUID to match the // one of the current site. $userPatternTemplate = "/user/%d?_format=hal_json"; if ($item['_links']['type']['href'] === "http://drupal.org/rest/type/user/user") { foreach ($this->coreUsersUuids as $uid => $uuid) { $userPattern = sprintf($userPatternTemplate, $uid); - // Match the end of the string. + // Check against the pattern. if (strpos($item['_links']['self']['href'], $userPattern) !== FALSE) { + // Add the found UUID to the collection of import UUIDs, override the + // UUID in the import data with the UUID from the actual user. $overriddenUuid = $item['uuid'][0]['value']; $item['uuid'][0]['value'] = $uuid; - if (!is_array($this->coreUsersImportUuids[$uid])) { + if (!isset($this->coreUsersImportUuids[$uid])) { $this->coreUsersImportUuids[$uid] = []; } if (!in_array($overriddenUuid, $this->coreUsersImportUuids[$uid])) { @@ -170,7 +172,7 @@ class Importer implements ImporterInterface { * @param string $contents * Serialized content to manipulate. */ - private function replaceCoreUserUuidsInString(&$contents) { + protected function replaceCoreUserUuidsInString(&$contents) { foreach ($this->coreUsersUuids as $uid => $uuid) { $contents = str_replace($this->coreUsersUuids[$uid], $uuid, $contents); }