X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FUserImport.php;h=f0d8f762e214cbaac022b311bb4c752451d27d7e;hb=1701ea2034feb1cb8b7cce8455ff8e3c1f8875c6;hp=c77674127af5b55e5f161f77f512b5a64b81be1d;hpb=1bc4b2e0788ac11d3b377013b410f2250fff68aa;p=friendica.git diff --git a/src/Core/UserImport.php b/src/Core/UserImport.php index c77674127a..f0d8f762e2 100644 --- a/src/Core/UserImport.php +++ b/src/Core/UserImport.php @@ -1,15 +1,34 @@ . + * */ + namespace Friendica\Core; use Friendica\App; use Friendica\Database\DBA; use Friendica\Database\DBStructure; use Friendica\DI; +use Friendica\Model\Contact; use Friendica\Model\Photo; use Friendica\Object\Image; +use Friendica\Repository\PermissionSet; use Friendica\Util\Strings; use Friendica\Worker\Delivery; @@ -161,23 +180,6 @@ class UserImport DI::pConfig()->set($newuid, 'system', 'previous_addr', $old_handle); - foreach ($account['profile'] as &$profile) { - 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); - } - } - $profile['uid'] = $newuid; - $r = self::dbImportAssoc('profile', $profile); - if ($r === false) { - Logger::log("uimport:insert profile " . $profile['profile-name'] . " : ERROR : " . DBA::errorMessage(), Logger::INFO); - info(DI::l10n()->t("User profile creation error")); - DBA::delete('user', ['uid' => $newuid]); - return; - } - } - $errorcount = 0; foreach ($account['contact'] as &$contact) { if ($contact['uid'] == $olduid && $contact['self'] == '1') { @@ -253,6 +255,50 @@ class UserImport } } + 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::log("uimport:insert profile: ERROR : " . DBA::errorMessage(), Logger::INFO); + notice(DI::l10n()->t("User profile creation error")); + DBA::delete('user', ['uid' => $newuid]); + DBA::delete('profile_field', ['uid' => $newuid]); + return; + } + + $profile['id'] = DBA::lastInsertId(); + } + + DI::profileField()->migrateFromLegacyProfile($profile); + } + + ///@TODO Replace with permissionset import + $self_contact = Contact::selectFirst(['id'], ['uid' => $newuid, 'self' => true]); + $allow_cid = DI::aclFormatter()->toString($self_contact['id']); + $self_psid = DI::permissionSet()->getIdFromACL($newuid, $allow_cid); + + foreach ($account['profile_fields'] ?? [] as $profile_field) { + $profile_field['uid'] = $newuid; + + ///@TODO Replace with permissionset import + $profile_field['psid'] = $profile_field['psid'] ? $self_psid : PermissionSet::PUBLIC; + + if (self::dbImportAssoc('profile_field', $profile_field) === false) { + Logger::info("uimport:insert profile field " . $profile_field['id'] . " : ERROR : " . DBA::errorMessage()); + } + } + foreach ($account['photo'] as &$photo) { $photo['uid'] = $newuid; $photo['data'] = hex2bin($photo['data']);