]> git.mxchange.org Git - friendica.git/blobdiff - include/uimport.php
Merge pull request #2185 from tobiasd/20151214-translations
[friendica.git] / include / uimport.php
index 4fd91f80a7400ce396134f472aadb8633825480f..78471af1514461d33cdef9a13f7b1e5bd31503e8 100644 (file)
@@ -28,7 +28,7 @@ function last_error() {
 \r
 /**\r
  * Remove columns from array $arr that aren't in table $table\r
- * \r
+ *\r
  * @param string $table Table name\r
  * @param array &$arr Column=>Value array from json (by ref)\r
  */\r
@@ -51,7 +51,7 @@ function check_cols($table, &$arr) {
 \r
 /**\r
  * Import data into table $table\r
- * \r
+ *\r
  * @param string $table Table name\r
  * @param array $arr Column=>Value array from json\r
  */\r
@@ -120,12 +120,26 @@ function import_account(&$a, $file) {
                notice(sprintf(t("User '%s' already exists on this server!"), $account['user']['nickname']));\r
                return;\r
        }\r
+       // check if username matches deleted account\r
+       $r = q("SELECT id FROM userd WHERE username='%s'", $account['user']['nickname']);\r
+       if ($r === false) {\r
+               logger("uimport:check nickname : ERROR : " . last_error(), LOGGER_NORMAL);\r
+               notice(t('Error! Cannot check nickname'));\r
+               return;\r
+       }\r
+       if (count($r) > 0) {\r
+               notice(sprintf(t("User '%s' already exists on this server!"), $account['user']['nickname']));\r
+               return;\r
+       }\r
 \r
        $oldbaseurl = $account['baseurl'];\r
        $newbaseurl = $a->get_baseurl();\r
        $olduid = $account['user']['uid'];\r
 \r
-       unset($account['user']['uid']);\r
+        unset($account['user']['uid']);\r
+        unset($account['user']['account_expired']);\r
+        unset($account['user']['account_expires_on']);\r
+        unset($account['user']['expire_notification_sent']);\r
        foreach ($account['user'] as $k => &$v) {\r
                $v = str_replace($oldbaseurl, $newbaseurl, $v);\r
        }\r
@@ -142,13 +156,15 @@ function import_account(&$a, $file) {
        $newuid = last_insert_id();\r
        //~ $newuid = 1;\r
 \r
-\r
+       // Generate a new guid for the account. Otherwise there will be problems with diaspora\r
+       q("UPDATE `user` SET `guid` = '%s' WHERE `uid` = %d",\r
+               dbesc(generate_user_guid()), intval($newuid));\r
 \r
        foreach ($account['profile'] as &$profile) {\r
                foreach ($profile as $k => &$v) {\r
                        $v = str_replace($oldbaseurl, $newbaseurl, $v);\r
                        foreach (array("profile", "avatar") as $k)\r
-                               $v = str_replace($newbaseurl . "/photo/" . $k . "/" . $olduid . ".jpg", $newbaseurl . "/photo/" . $k . "/" . $newuid . ".jpg", $v);\r
+                               $v = str_replace($oldbaseurl . "/photo/" . $k . "/" . $olduid . ".jpg", $newbaseurl . "/photo/" . $k . "/" . $newuid . ".jpg", $v);\r
                }\r
                $profile['uid'] = $newuid;\r
                $r = db_import_assoc('profile', $profile);\r
@@ -166,10 +182,14 @@ function import_account(&$a, $file) {
                        foreach ($contact as $k => &$v) {\r
                                $v = str_replace($oldbaseurl, $newbaseurl, $v);\r
                                foreach (array("profile", "avatar", "micro") as $k)\r
-                                       $v = str_replace($newbaseurl . "/photo/" . $k . "/" . $olduid . ".jpg", $newbaseurl . "/photo/" . $k . "/" . $newuid . ".jpg", $v);\r
+                                       $v = str_replace($oldbaseurl . "/photo/" . $k . "/" . $olduid . ".jpg", $newbaseurl . "/photo/" . $k . "/" . $newuid . ".jpg", $v);\r
                        }\r
                }\r
                if ($contact['uid'] == $olduid && $contact['self'] == '0') {\r
+                       // set contacts 'avatar-date' to "0000-00-00 00:00:00" to let poller to update urls\r
+                       $contact["avatar-date"] = "0000-00-00 00:00:00" ;\r
+\r
+\r
                        switch ($contact['network']) {\r
                                case NETWORK_DFRN:\r
                                        //  send relocate message (below)\r