friendica-6950 uimport doesn't support "pwdreset_time":null

This commit is contained in:
Philipp Holzer 2019-05-26 15:49:44 +02:00
parent ea218438d2
commit 220f8f0862
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
2 changed files with 40 additions and 2 deletions

View file

@ -2,20 +2,26 @@
/** /**
* @file mod/uexport.php * @file mod/uexport.php
*/ */
use Friendica\App; use Friendica\App;
use Friendica\Core\Hook; use Friendica\Core\Hook;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Database\DBStructure;
function uexport_init(App $a) { function uexport_init(App $a) {
global $dbStructure;
if (!local_user()) { if (!local_user()) {
exit(); exit();
} }
require_once("mod/settings.php"); require_once("mod/settings.php");
settings_init($a); settings_init($a);
$dbStructure = DBStructure::definition($a->getBasePath());
} }
function uexport_content(App $a) { function uexport_content(App $a) {
@ -55,13 +61,25 @@ function uexport_content(App $a) {
} }
function _uexport_multirow($query) { function _uexport_multirow($query) {
global $dbStructure;
preg_match("/\s+from\s+`?([a-z\d_]+)`?/i", $query, $match);
$table = $match[1];
$result = []; $result = [];
$r = q($query); $r = q($query);
if (DBA::isResult($r)) { if (DBA::isResult($r)) {
foreach ($r as $rr) { foreach ($r as $rr) {
$p = []; $p = [];
foreach ($rr as $k => $v) { foreach ($rr as $k => $v) {
switch ($dbStructure[$table]['fields'][$k]['type']) {
case 'datetime':
$p[$k] = !empty($v) ? $v : DBA::NULL_DATETIME;
break;
default:
$p[$k] = $v; $p[$k] = $v;
break;
}
} }
$result[] = $p; $result[] = $p;
} }
@ -70,12 +88,25 @@ function _uexport_multirow($query) {
} }
function _uexport_row($query) { function _uexport_row($query) {
global $dbStructure;
preg_match("/\s+from\s+`?([a-z\d_]+)`?/i", $query, $match);
$table = $match[1];
$result = []; $result = [];
$r = q($query); $r = q($query);
if (DBA::isResult($r)) { if (DBA::isResult($r)) {
foreach ($r as $rr) { foreach ($r as $rr) {
foreach ($rr as $k => $v) { foreach ($rr as $k => $v) {
switch ($dbStructure[$table]['fields'][$k]['type']) {
case 'datetime':
$result[$k] = !empty($v) ? $v : DBA::NULL_DATETIME;
break;
default:
$result[$k] = $v; $result[$k] = $v;
break;
}
} }
} }
} }

View file

@ -39,14 +39,21 @@ class UserImport
$tableColumns = DBStructure::getColumns($table); $tableColumns = DBStructure::getColumns($table);
$tcols = []; $tcols = [];
$ttype = [];
// get a plain array of column names // get a plain array of column names
foreach ($tableColumns as $tcol) { foreach ($tableColumns as $tcol) {
$tcols[] = $tcol['Field']; $tcols[] = $tcol['Field'];
$ttype[$tcol['Field']] = $tcol['Type'];
} }
// remove inexistent columns // remove inexistent columns
foreach ($arr as $icol => $ival) { foreach ($arr as $icol => $ival) {
if (!in_array($icol, $tcols)) { if (!in_array($icol, $tcols)) {
unset($arr[$icol]); unset($arr[$icol]);
continue;
}
if ($ttype[$icol] === 'datetime') {
$arr[$icol] = !empty($ival) ? $ival : DBA::NULL_DATETIME;
} }
} }
} }