X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FUserImport.php;h=fbc89ccf580ce0deed66a66dc9421c33bce321aa;hb=06284e60073f374c1bd411e0bba6474a13c14f10;hp=c77674127af5b55e5f161f77f512b5a64b81be1d;hpb=a9a36fb3029c9a5d595aa28a9f0a79f441d1b121;p=friendica.git diff --git a/src/Core/UserImport.php b/src/Core/UserImport.php index c77674127a..fbc89ccf58 100644 --- a/src/Core/UserImport.php +++ b/src/Core/UserImport.php @@ -1,15 +1,33 @@ . + * */ + namespace Friendica\Core; -use Friendica\App; use Friendica\Database\DBA; use Friendica\Database\DBStructure; use Friendica\DI; use Friendica\Model\Photo; +use Friendica\Model\Profile; use Friendica\Object\Image; +use Friendica\Security\PermissionSet\Repository\PermissionSet; use Friendica\Util\Strings; use Friendica\Worker\Delivery; @@ -92,7 +110,7 @@ class UserImport */ public static function importAccount($file) { - Logger::log("Start user import from " . $file['tmp_name']); + Logger::notice("Start user import from " . $file['tmp_name']); /* STEPS 1. checks @@ -153,7 +171,7 @@ class UserImport // import user $r = self::dbImportAssoc('user', $account['user']); if ($r === false) { - Logger::log("uimport:insert user : ERROR : " . DBA::errorMessage(), Logger::INFO); + Logger::warning("uimport:insert user : ERROR : " . DBA::errorMessage()); notice(DI::l10n()->t("User creation error")); return; } @@ -161,23 +179,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') { @@ -209,7 +210,7 @@ class UserImport $contact['uid'] = $newuid; $r = self::dbImportAssoc('contact', $contact); if ($r === false) { - Logger::log("uimport:insert contact " . $contact['nick'] . "," . $contact['network'] . " : ERROR : " . DBA::errorMessage(), Logger::INFO); + Logger::warning("uimport:insert contact " . $contact['nick'] . "," . $contact['network'] . " : ERROR : " . DBA::errorMessage()); $errorcount++; } else { $contact['newid'] = self::lastInsertId(); @@ -223,7 +224,7 @@ class UserImport $group['uid'] = $newuid; $r = self::dbImportAssoc('group', $group); if ($r === false) { - Logger::log("uimport:insert group " . $group['name'] . " : ERROR : " . DBA::errorMessage(), Logger::INFO); + Logger::warning("uimport:insert group " . $group['name'] . " : ERROR : " . DBA::errorMessage()); } else { $group['newid'] = self::lastInsertId(); } @@ -248,11 +249,52 @@ class UserImport if ($import == 2) { $r = self::dbImportAssoc('group_member', $group_member); if ($r === false) { - Logger::log("uimport:insert group member " . $group_member['id'] . " : ERROR : " . DBA::errorMessage(), Logger::INFO); + Logger::warning("uimport:insert group member " . $group_member['id'] . " : ERROR : " . DBA::errorMessage()); } } } + 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()); + } + } + foreach ($account['photo'] as &$photo) { $photo['uid'] = $newuid; $photo['data'] = hex2bin($photo['data']); @@ -266,7 +308,7 @@ class UserImport ); if ($r === false) { - Logger::log("uimport:insert photo " . $photo['resource-id'] . "," . $photo['scale'] . " : ERROR : " . DBA::errorMessage(), Logger::INFO); + Logger::warning("uimport:insert photo " . $photo['resource-id'] . "," . $photo['scale'] . " : ERROR : " . DBA::errorMessage()); } } @@ -274,7 +316,7 @@ class UserImport $pconfig['uid'] = $newuid; $r = self::dbImportAssoc('pconfig', $pconfig); if ($r === false) { - Logger::log("uimport:insert pconfig " . $pconfig['id'] . " : ERROR : " . DBA::errorMessage(), Logger::INFO); + Logger::warning("uimport:insert pconfig " . $pconfig['id'] . " : ERROR : " . DBA::errorMessage()); } }