+ foreach ($account['profile'] as &$profile) {
+ unset($profile['id']);
+ $profile['uid'] = $newuid;
+
+ foreach ($profile as $k => &$v) {
+ $v = str_replace([$oldbaseurl, $oldaddr], [$newbaseurl, $newaddr], $v);
+ foreach (["profile", "avatar"] as $k) {
+ $v = str_replace($oldbaseurl . "/photo/" . $k . "/" . $olduid . ".jpg", $newbaseurl . "/photo/" . $k . "/" . $newuid . ".jpg", $v);
+ }
+ }
+
+ if (count($account['profile']) === 1 || $profile['is-default']) {
+ $r = self::dbImportAssoc('profile', $profile);
+
+ if ($r === false) {
+ Logger::warning("uimport:insert profile: ERROR : " . DBA::errorMessage());
+ notice(DI::l10n()->t("User profile creation error"));
+ DBA::delete('user', ['uid' => $newuid]);
+ DBA::delete('profile_field', ['uid' => $newuid]);
+ return;
+ }
+
+ $profile['id'] = DBA::lastInsertId();
+ }
+
+ Profile::migrate($profile);
+ }
+
+ $permissionSet = DI::permissionSet()->selectDefaultForUser($newuid);
+
+ foreach ($account['profile_fields'] ?? [] as $profile_field) {
+ $profile_field['uid'] = $newuid;
+
+ ///@TODO Replace with permissionset import
+ $profile_field['psid'] = $profile_field['psid'] ? $permissionSet->uid : PermissionSet::PUBLIC;
+
+ if (self::dbImportAssoc('profile_field', $profile_field) === false) {
+ Logger::info("uimport:insert profile field " . $profile_field['id'] . " : ERROR : " . DBA::errorMessage());
+ }
+ }
+