X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FUserImport.php;h=97a6e6028e3b4905e341506a5f4d540ccbbd219d;hb=dc0978141c444f452071f076c2309fcf67546b57;hp=7ccb6f80cbd7aa5d98ab7646b3a71bcf9f87bd16;hpb=50da89d861dce3b648c8f9e5c1e4c480ee320a43;p=friendica.git diff --git a/src/Core/UserImport.php b/src/Core/UserImport.php index 7ccb6f80cb..97a6e6028e 100644 --- a/src/Core/UserImport.php +++ b/src/Core/UserImport.php @@ -5,13 +5,11 @@ namespace Friendica\Core; use Friendica\App; -use Friendica\Core\Logger; -use Friendica\Core\Protocol; use Friendica\Database\DBA; +use Friendica\Database\DBStructure; use Friendica\Model\Photo; use Friendica\Object\Image; - -require_once "include/dba.php"; +use Friendica\Util\Strings; /** * @brief UserImport class @@ -33,22 +31,29 @@ class UserImport * Remove columns from array $arr that aren't in table $table * * @param string $table Table name - * @param array &$arr Column=>Value array from json (by ref) + * @param array &$arr Column=>Value array from json (by ref) + * @throws \Exception */ private static function checkCols($table, &$arr) { - $query = sprintf("SHOW COLUMNS IN `%s`", DBA::escape($table)); - Logger::log("uimport: $query", Logger::DEBUG); - $r = q($query); + $tableColumns = DBStructure::getColumns($table); + $tcols = []; + $ttype = []; // get a plain array of column names - foreach ($r as $tcol) { + foreach ($tableColumns as $tcol) { $tcols[] = $tcol['Field']; + $ttype[$tcol['Field']] = $tcol['Type']; } // remove inexistent columns foreach ($arr as $icol => $ival) { if (!in_array($icol, $tcols)) { unset($arr[$icol]); + continue; + } + + if ($ttype[$icol] === 'datetime') { + $arr[$icol] = $ival ?? DBA::NULL_DATETIME; } } } @@ -57,7 +62,9 @@ class UserImport * Import data into table $table * * @param string $table Table name - * @param array $arr Column=>Value array from json + * @param array $arr Column=>Value array from json + * @return array|bool + * @throws \Exception */ private static function dbImportAssoc($table, $arr) { @@ -66,23 +73,21 @@ class UserImport } self::checkCols($table, $arr); - $cols = implode("`,`", array_map(['Friendica\Database\DBA', 'escape'], array_keys($arr))); - $vals = implode("','", array_map(['Friendica\Database\DBA', 'escape'], array_values($arr))); - $query = "INSERT INTO `$table` (`$cols`) VALUES ('$vals')"; - Logger::log("uimport: $query", Logger::TRACE); if (self::IMPORT_DEBUG) { return true; } - return q($query); + return DBA::insert($table, $arr); } /** * @brief Import account file exported from mod/uexport * - * @param App $a Friendica App Class + * @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) { @@ -103,7 +108,7 @@ class UserImport } - if (!x($account, 'version')) { + if (empty($account['version'])) { notice(L10n::t("Error! No version data in file! This is not a Friendica account file?")); return; } @@ -119,8 +124,8 @@ class UserImport $oldbaseurl = $account['baseurl']; $newbaseurl = System::baseUrl(); - $oldaddr = str_replace('http://', '@', normalise_link($oldbaseurl)); - $newaddr = str_replace('http://', '@', normalise_link($newbaseurl)); + $oldaddr = str_replace('http://', '@', Strings::normaliseLink($oldbaseurl)); + $newaddr = str_replace('http://', '@', Strings::normaliseLink($newbaseurl)); if (!empty($account['profile']['addr'])) { $old_handle = $account['profile']['addr']; @@ -128,6 +133,9 @@ class UserImport $old_handle = $account['user']['nickname'].$oldaddr; } + // Creating a new guid to avoid problems with Diaspora + $account['user']['guid'] = System::createUUID(); + $olduid = $account['user']['uid']; unset($account['user']['uid']);