]> git.mxchange.org Git - friendica.git/commitdiff
friendica-6950 uimport doesn't support `"pwdreset_time":null`
authorPhilipp Holzer <admin+github@philipp.info>
Sun, 26 May 2019 13:49:44 +0000 (15:49 +0200)
committerPhilipp Holzer <admin+github@philipp.info>
Sun, 26 May 2019 13:49:44 +0000 (15:49 +0200)
mod/uexport.php
src/Core/UserImport.php

index c91309e74c37fec9eb4077a25dda78defc6da4ca..2580a4ac6e410d4710101dcd33696d2c1bfd86df 100644 (file)
@@ -2,20 +2,26 @@
 /**
  * @file mod/uexport.php
  */
+
 use Friendica\App;
 use Friendica\Core\Hook;
 use Friendica\Core\L10n;
 use Friendica\Core\Renderer;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
+use Friendica\Database\DBStructure;
 
 function uexport_init(App $a) {
+       global $dbStructure;
+
        if (!local_user()) {
                exit();
        }
 
        require_once("mod/settings.php");
        settings_init($a);
+
+       $dbStructure = DBStructure::definition($a->getBasePath());
 }
 
 function uexport_content(App $a) {
@@ -55,13 +61,25 @@ function uexport_content(App $a) {
 }
 
 function _uexport_multirow($query) {
+       global $dbStructure;
+
+       preg_match("/\s+from\s+`?([a-z\d_]+)`?/i", $query, $match);
+       $table = $match[1];
+
        $result = [];
        $r = q($query);
        if (DBA::isResult($r)) {
                foreach ($r as $rr) {
                        $p = [];
                        foreach ($rr as $k => $v) {
-                               $p[$k] = $v;
+                               switch ($dbStructure[$table]['fields'][$k]['type']) {
+                                       case 'datetime':
+                                               $p[$k] = !empty($v) ? $v : DBA::NULL_DATETIME;
+                                               break;
+                                       default:
+                                               $p[$k] = $v;
+                                               break;
+                               }
                        }
                        $result[] = $p;
                }
@@ -70,12 +88,25 @@ function _uexport_multirow($query) {
 }
 
 function _uexport_row($query) {
+       global $dbStructure;
+
+       preg_match("/\s+from\s+`?([a-z\d_]+)`?/i", $query, $match);
+       $table = $match[1];
+
        $result = [];
        $r = q($query);
        if (DBA::isResult($r)) {
+
                foreach ($r as $rr) {
                        foreach ($rr as $k => $v) {
-                               $result[$k] = $v;
+                               switch ($dbStructure[$table]['fields'][$k]['type']) {
+                                       case 'datetime':
+                                               $result[$k] = !empty($v) ? $v : DBA::NULL_DATETIME;
+                                               break;
+                                       default:
+                                               $result[$k] = $v;
+                                               break;
+                               }
                        }
                }
        }
index 0a4223fecdf5f45241051631dcb23a0c5d10aab2..8d02fb420e2143f34d88672dc0f0ab548e1e66f2 100644 (file)
@@ -39,14 +39,21 @@ class UserImport
                $tableColumns = DBStructure::getColumns($table);
 
                $tcols = [];
+               $ttype = [];
                // get a plain array of column names
                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] = !empty($ival) ? $ival : DBA::NULL_DATETIME;
                        }
                }
        }