]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/UserImport.php
Merge pull request #4243 from MrPetovan/task/switch-to-array-new-style
[friendica.git] / src / Core / UserImport.php
index 8b259b2dbe51fa705e15e51e72c92e64b290428d..f3170c71519520ccf5bf017d536e611d974f36ca 100644 (file)
@@ -15,19 +15,19 @@ use dba;
 
 require_once "include/dba.php";
 
-define("IMPORT_DEBUG", false);
-
 /**
  * @brief UserImport class
  */
 class UserImport
 {
+       const IMPORT_DEBUG = false;
+
        private static function lastInsertId()
        {
-               if (IMPORT_DEBUG) {
+               if (self::IMPORT_DEBUG) {
                        return 1;
                }
-       
+
                return dba::lastInsertId();
        }
 
@@ -42,7 +42,7 @@ class UserImport
                $query = sprintf("SHOW COLUMNS IN `%s`", dbesc($table));
                logger("uimport: $query", LOGGER_DEBUG);
                $r = q($query);
-               $tcols = array();
+               $tcols = [];
                // get a plain array of column names
                foreach ($r as $tcol) {
                        $tcols[] = $tcol['Field'];
@@ -73,7 +73,7 @@ class UserImport
                $query = "INSERT INTO `$table` (`$cols`) VALUES ('$vals')";
                logger("uimport: $query", LOGGER_TRACE);
 
-               if (IMPORT_DEBUG) {
+               if (self::IMPORT_DEBUG) {
                        return true;
                }
 
@@ -155,11 +155,11 @@ class UserImport
                unset($account['user']['account_expires_on']);
                unset($account['user']['expire_notification_sent']);
 
-               $callback = function ($key, $value) use ($oldbaseurl, $oldaddr, $newbaseurl, $newaddr) {
-                       return str_replace(array($oldbaseurl, $oldaddr), array($newbaseurl, $newaddr), $value);
+               $callback = function (&$value) use ($oldbaseurl, $oldaddr, $newbaseurl, $newaddr) {
+                       $value =  str_replace([$oldbaseurl, $oldaddr], [$newbaseurl, $newaddr], $value);
                };
 
-               $v = array_map($account['user'], $callback);
+               array_walk($account['user'], $callback);
 
                // import user
                $r = self::dbImportAssoc('user', $account['user']);
@@ -177,8 +177,8 @@ class UserImport
 
                foreach ($account['profile'] as &$profile) {
                        foreach ($profile as $k => &$v) {
-                               $v = str_replace(array($oldbaseurl, $oldaddr), array($newbaseurl, $newaddr), $v);
-                               foreach (array("profile", "avatar") as $k) {
+                               $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);
                                }
                        }
@@ -187,7 +187,7 @@ class UserImport
                        if ($r === false) {
                                logger("uimport:insert profile " . $profile['profile-name'] . " : ERROR : " . dba::errorMessage(), LOGGER_NORMAL);
                                info(t("User profile creation error"));
-                               dba::delete('user', array('uid' => $newuid));
+                               dba::delete('user', ['uid' => $newuid]);
                                return;
                        }
                }
@@ -196,8 +196,8 @@ class UserImport
                foreach ($account['contact'] as &$contact) {
                        if ($contact['uid'] == $olduid && $contact['self'] == '1') {
                                foreach ($contact as $k => &$v) {
-                                       $v = str_replace(array($oldbaseurl, $oldaddr), array($newbaseurl, $newaddr), $v);
-                                       foreach (array("profile", "avatar", "micro") as $k) {
+                                       $v = str_replace([$oldbaseurl, $oldaddr], [$newbaseurl, $newaddr], $v);
+                                       foreach (["profile", "avatar", "micro"] as $k) {
                                                $v = str_replace($oldbaseurl . "/photo/" . $k . "/" . $olduid . ".jpg", $newbaseurl . "/photo/" . $k . "/" . $newuid . ".jpg", $v);
                                        }
                                }