]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/UserImport.php
Remove duplicate profile_uid key in App->profile array
[friendica.git] / src / Core / UserImport.php
index 8d02fb420e2143f34d88672dc0f0ab548e1e66f2..c77674127af5b55e5f161f77f512b5a64b81be1d 100644 (file)
@@ -7,12 +7,14 @@ namespace Friendica\Core;
 use Friendica\App;
 use Friendica\Database\DBA;
 use Friendica\Database\DBStructure;
+use Friendica\DI;
 use Friendica\Model\Photo;
 use Friendica\Object\Image;
 use Friendica\Util\Strings;
+use Friendica\Worker\Delivery;
 
 /**
- * @brief UserImport class
+ * UserImport class
  */
 class UserImport
 {
@@ -53,7 +55,7 @@ class UserImport
                        }
 
                        if ($ttype[$icol] === 'datetime') {
-                               $arr[$icol] = !empty($ival) ? $ival : DBA::NULL_DATETIME;
+                               $arr[$icol] = $ival ?? DBA::NULL_DATETIME;
                        }
                }
        }
@@ -82,14 +84,13 @@ class UserImport
        }
 
        /**
-        * @brief Import account file exported from mod/uexport
+        * Import account file exported from mod/uexport
         *
-        * @param App   $a    Friendica App Class
         * @param array $file array from $_FILES
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public static function importAccount(App $a, $file)
+       public static function importAccount($file)
        {
                Logger::log("Start user import from " . $file['tmp_name']);
                /*
@@ -103,13 +104,13 @@ class UserImport
 
                $account = json_decode(file_get_contents($file['tmp_name']), true);
                if ($account === null) {
-                       notice(L10n::t("Error decoding account file"));
+                       notice(DI::l10n()->t("Error decoding account file"));
                        return;
                }
 
 
                if (empty($account['version'])) {
-                       notice(L10n::t("Error! No version data in file! This is not a Friendica account file?"));
+                       notice(DI::l10n()->t("Error! No version data in file! This is not a Friendica account file?"));
                        return;
                }
 
@@ -117,12 +118,12 @@ class UserImport
                // check if username matches deleted account
                if (DBA::exists('user', ['nickname' => $account['user']['nickname']])
                        || DBA::exists('userd', ['username' => $account['user']['nickname']])) {
-                       notice(L10n::t("User '%s' already exists on this server!", $account['user']['nickname']));
+                       notice(DI::l10n()->t("User '%s' already exists on this server!", $account['user']['nickname']));
                        return;
                }
 
                $oldbaseurl = $account['baseurl'];
-               $newbaseurl = System::baseUrl();
+               $newbaseurl = DI::baseUrl();
 
                $oldaddr = str_replace('http://', '@', Strings::normaliseLink($oldbaseurl));
                $newaddr = str_replace('http://', '@', Strings::normaliseLink($newbaseurl));
@@ -153,12 +154,12 @@ class UserImport
                $r = self::dbImportAssoc('user', $account['user']);
                if ($r === false) {
                        Logger::log("uimport:insert user : ERROR : " . DBA::errorMessage(), Logger::INFO);
-                       notice(L10n::t("User creation error"));
+                       notice(DI::l10n()->t("User creation error"));
                        return;
                }
                $newuid = self::lastInsertId();
 
-               PConfig::set($newuid, 'system', 'previous_addr', $old_handle);
+               DI::pConfig()->set($newuid, 'system', 'previous_addr', $old_handle);
 
                foreach ($account['profile'] as &$profile) {
                        foreach ($profile as $k => &$v) {
@@ -171,7 +172,7 @@ class UserImport
                        $r = self::dbImportAssoc('profile', $profile);
                        if ($r === false) {
                                Logger::log("uimport:insert profile " . $profile['profile-name'] . " : ERROR : " . DBA::errorMessage(), Logger::INFO);
-                               info(L10n::t("User profile creation error"));
+                               info(DI::l10n()->t("User profile creation error"));
                                DBA::delete('user', ['uid' => $newuid]);
                                return;
                        }
@@ -215,7 +216,7 @@ class UserImport
                        }
                }
                if ($errorcount > 0) {
-                       notice(L10n::tt("%d contact not imported", "%d contacts not imported", $errorcount));
+                       notice(DI::l10n()->tt("%d contact not imported", "%d contacts not imported", $errorcount));
                }
 
                foreach ($account['group'] as &$group) {
@@ -278,9 +279,9 @@ class UserImport
                }
 
                // send relocate messages
-               Worker::add(PRIORITY_HIGH, 'Notifier', 'relocate', $newuid);
+               Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::RELOCATION, $newuid);
 
-               info(L10n::t("Done. You can now login with your username and password"));
-               $a->internalRedirect('login');
+               info(DI::l10n()->t("Done. You can now login with your username and password"));
+               DI::baseUrl()->redirect('login');
        }
 }