From fb562fc25bf5693965a692358b0e1ce7bd7e551f Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Fri, 11 Oct 2019 07:36:41 +0200 Subject: [PATCH 01/13] removed mod/uexport file --- mod/uexport.php | 197 ------------------------------------------------ 1 file changed, 197 deletions(-) delete mode 100644 mod/uexport.php diff --git a/mod/uexport.php b/mod/uexport.php deleted file mode 100644 index dfeb25abd7..0000000000 --- a/mod/uexport.php +++ /dev/null @@ -1,197 +0,0 @@ -getBasePath()); -} - -function uexport_content(App $a) { - - if ($a->argc > 1) { - header("Content-type: application/json"); - header('Content-Disposition: attachment; filename="' . $a->user['nickname'] . '.' . $a->argv[1] . '"'); - switch ($a->argv[1]) { - case "backup": - uexport_all($a); - exit(); - break; - case "account": - uexport_account($a); - exit(); - break; - default: - exit(); - } - } - - /** - * options shown on "Export personal data" page - * list of array( 'link url', 'link text', 'help text' ) - */ - $options = [ - ['uexport/account', L10n::t('Export account'), L10n::t('Export your account info and contacts. Use this to make a backup of your account and/or to move it to another server.')], - ['uexport/backup', L10n::t('Export all'), L10n::t("Export your accout info, contacts and all your items as json. Could be a very big file, and could take a lot of time. Use this to make a full backup of your account \x28photos are not exported\x29")], - ]; - Hook::callAll('uexport_options', $options); - - $tpl = Renderer::getMarkupTemplate("uexport.tpl"); - return Renderer::replaceMacros($tpl, [ - '$title' => L10n::t('Export personal data'), - '$options' => $options - ]); -} - -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) { - switch ($dbStructure[$table]['fields'][$k]['type']) { - case 'datetime': - $p[$k] = $v ?? DBA::NULL_DATETIME; - break; - default: - $p[$k] = $v; - break; - } - } - $result[] = $p; - } - } - return $result; -} - -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) { - switch ($dbStructure[$table]['fields'][$k]['type']) { - case 'datetime': - $result[$k] = $v ?? DBA::NULL_DATETIME; - break; - default: - $result[$k] = $v; - break; - } - } - } - } - return $result; -} - -function uexport_account($a) { - - $user = _uexport_row( - sprintf("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval(local_user())) - ); - - $contact = _uexport_multirow( - sprintf("SELECT * FROM `contact` WHERE `uid` = %d ", intval(local_user())) - ); - - - $profile = _uexport_multirow( - sprintf("SELECT * FROM `profile` WHERE `uid` = %d ", intval(local_user())) - ); - - $photo = _uexport_multirow( - sprintf("SELECT * FROM `photo` WHERE uid = %d AND profile = 1", intval(local_user())) - ); - foreach ($photo as &$p) { - $p['data'] = bin2hex($p['data']); - } - - $pconfig = _uexport_multirow( - sprintf("SELECT * FROM `pconfig` WHERE uid = %d", intval(local_user())) - ); - - $group = _uexport_multirow( - sprintf("SELECT * FROM `group` WHERE uid = %d", intval(local_user())) - ); - - $group_member = _uexport_multirow( - sprintf("SELECT `group_member`.`gid`, `group_member`.`contact-id` FROM `group_member` INNER JOIN `group` ON `group`.`id` = `group_member`.`gid` WHERE `group`.`uid` = %d", intval(local_user())) - ); - - $output = [ - 'version' => FRIENDICA_VERSION, - 'schema' => DB_UPDATE_VERSION, - 'baseurl' => System::baseUrl(), - 'user' => $user, - 'contact' => $contact, - 'profile' => $profile, - 'photo' => $photo, - 'pconfig' => $pconfig, - 'group' => $group, - 'group_member' => $group_member, - ]; - - echo json_encode($output, JSON_PARTIAL_OUTPUT_ON_ERROR); -} - -/** - * echoes account data and items as separated json, one per line - * - * @param App $a - * @throws Exception - */ -function uexport_all(App $a) { - - uexport_account($a); - echo "\n"; - - $total = 0; - $r = q("SELECT count(*) as `total` FROM `item` WHERE `uid` = %d ", - intval(local_user()) - ); - if (DBA::isResult($r)) { - $total = $r[0]['total']; - } - // chunk the output to avoid exhausting memory - - for ($x = 0; $x < $total; $x += 500) { - $r = q("SELECT * FROM `item` WHERE `uid` = %d LIMIT %d, %d", - intval(local_user()), - intval($x), - intval(500) - ); - - $output = ['item' => $r]; - echo json_encode($output, JSON_PARTIAL_OUTPUT_ON_ERROR). "\n"; - } -} From 46172b641df8c1b1c3e5608e4dff6c3f1db6e6ef Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Fri, 11 Oct 2019 07:38:42 +0200 Subject: [PATCH 02/13] moved UExport to src/Module/Settings/Uexport --- mod/settings.php | 4 +- src/Module/BaseSettingsModule.php | 4 +- src/Module/Settings/Uexport.php | 204 ++++++++++++++++++++++++++++++ static/routes.config.php | 1 + 4 files changed, 209 insertions(+), 4 deletions(-) create mode 100644 src/Module/Settings/Uexport.php diff --git a/mod/settings.php b/mod/settings.php index 0d519e5a07..24cb2a8794 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -129,8 +129,8 @@ function settings_init(App $a) $tabs[] = [ 'label' => L10n::t('Export personal data'), - 'url' => 'uexport', - 'selected' => (($a->argc == 1) && ($a->argv[0] === 'uexport')?'active':''), + 'url' => 'settings/uexport', + 'selected' => (($a->argc > 1) && ($a->argv[1] === 'uexport')?'active':''), 'accesskey' => 'e', ]; diff --git a/src/Module/BaseSettingsModule.php b/src/Module/BaseSettingsModule.php index 4c9173db79..6945af8a5a 100644 --- a/src/Module/BaseSettingsModule.php +++ b/src/Module/BaseSettingsModule.php @@ -87,8 +87,8 @@ class BaseSettingsModule extends BaseModule $tabs[] = [ 'label' => L10n::t('Export personal data'), - 'url' => 'uexport', - 'selected' => (($a->argc == 1) && ($a->argv[0] === 'uexport') ? 'active' : ''), + 'url' => 'settings/uexport', + 'selected' => (($a->argc > 1) && ($a->argv[1] === 'uexport') ? 'active' : ''), 'accesskey' => 'e', ]; diff --git a/src/Module/Settings/Uexport.php b/src/Module/Settings/Uexport.php new file mode 100644 index 0000000000..c9cab9b21b --- /dev/null +++ b/src/Module/Settings/Uexport.php @@ -0,0 +1,204 @@ +get(2); + if ($args->getArgc() > 2) { + header("Content-type: application/json"); + header('Content-Disposition: attachment; filename="' . $a->user['nickname'] . '.' . $action . '"'); + switch ($action) { + case "backup": + SELF::uexport_all($a); + exit(); + break; + case "account": + SELF::uexport_account($a); + exit(); + break; + default: + exit(); + } + } + + /** + * options shown on "Export personal data" page + * list of array( 'link url', 'link text', 'help text' ) + */ + $options = [ + ['settings/uexport/account', L10n::t('Export account'), L10n::t('Export your account info and contacts. Use this to make a backup of your account and/or to move it to another server.')], + ['settings/uexport/backup', L10n::t('Export all'), L10n::t("Export your accout info, contacts and all your items as json. Could be a very big file, and could take a lot of time. Use this to make a full backup of your account \x28photos are not exported\x29")], + ]; + Hook::callAll('uexport_options', $options); + + $tpl = Renderer::getMarkupTemplate("uexport.tpl"); + return Renderer::replaceMacros($tpl, [ + '$title' => L10n::t('Export personal data'), + '$options' => $options + ]); + } + private 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) { + switch ($dbStructure[$table]['fields'][$k]['type']) { + case 'datetime': + $p[$k] = $v ?? DBA::NULL_DATETIME; + break; + default: + $p[$k] = $v; + break; + } + } + $result[] = $p; + } + } + return $result; + } + + private 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) { + switch ($dbStructure[$table]['fields'][$k]['type']) { + case 'datetime': + $result[$k] = $v ?? DBA::NULL_DATETIME; + break; + default: + $result[$k] = $v; + break; + } + } + } + } + return $result; + } + + private function uexport_account($a) { + + echo "

in uexport_account

"; + $user = SELF::uexport_row( + sprintf("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval(local_user())) + ); + + $contact = SELF::uexport_multirow( + sprintf("SELECT * FROM `contact` WHERE `uid` = %d ", intval(local_user())) + ); + + + $profile = SELF::uexport_multirow( + sprintf("SELECT * FROM `profile` WHERE `uid` = %d ", intval(local_user())) + ); + + $photo = SELF::uexport_multirow( + sprintf("SELECT * FROM `photo` WHERE uid = %d AND profile = 1", intval(local_user())) + ); + foreach ($photo as &$p) { + $p['data'] = bin2hex($p['data']); + } + + $pconfig = SELF::uexport_multirow( + sprintf("SELECT * FROM `pconfig` WHERE uid = %d", intval(local_user())) + ); + + $group = SELF::uexport_multirow( + sprintf("SELECT * FROM `group` WHERE uid = %d", intval(local_user())) + ); + + $group_member = SELF::uexport_multirow( + sprintf("SELECT `group_member`.`gid`, `group_member`.`contact-id` FROM `group_member` INNER JOIN `group` ON `group`.`id` = `group_member`.`gid` WHERE `group`.`uid` = %d", intval(local_user())) + ); + + $output = [ + 'version' => FRIENDICA_VERSION, + 'schema' => DB_UPDATE_VERSION, + 'baseurl' => System::baseUrl(), + 'user' => $user, + 'contact' => $contact, + 'profile' => $profile, + 'photo' => $photo, + 'pconfig' => $pconfig, + 'group' => $group, + 'group_member' => $group_member, + ]; + + echo json_encode($output, JSON_PARTIAL_OUTPUT_ON_ERROR); + } + + /** + * echoes account data and items as separated json, one per line + * + * @param App $a + * @throws Exception + */ + private function uexport_all(App $a) { + + SELF::uexport_account($a); + echo "\n"; + + $total = 0; + $r = q("SELECT count(*) as `total` FROM `item` WHERE `uid` = %d ", + intval(local_user()) + ); + if (DBA::isResult($r)) { + $total = $r[0]['total']; + } + // chunk the output to avoid exhausting memory + + for ($x = 0; $x < $total; $x += 500) { + $r = q("SELECT * FROM `item` WHERE `uid` = %d LIMIT %d, %d", + intval(local_user()), + intval($x), + intval(500) + ); + + $output = ['item' => $r]; + echo json_encode($output, JSON_PARTIAL_OUTPUT_ON_ERROR). "\n"; + } + } +} diff --git a/static/routes.config.php b/static/routes.config.php index 841fd68f99..479ba07c77 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -203,6 +203,7 @@ return [ '/verify' => [Module\Settings\TwoFactor\Verify::class, [R::GET, R::POST]], ], '/delegation[/{action}/{user_id}]' => [Module\Settings\Delegation::class, [R::GET, R::POST]], + '/uexport[/{action}]' => [Module\Settings\Uexport::class, [R::GET, R::POST]], ], '/randprof' => [Module\RandomProfile::class, [R::GET]], From 06a964c32f43f306a3322ebdc6359a33dfe344c2 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Fri, 11 Oct 2019 11:42:07 +0200 Subject: [PATCH 03/13] only take action, when there is something to do --- src/Module/Settings/Uexport.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Module/Settings/Uexport.php b/src/Module/Settings/Uexport.php index c9cab9b21b..8e0ee6758a 100644 --- a/src/Module/Settings/Uexport.php +++ b/src/Module/Settings/Uexport.php @@ -32,8 +32,8 @@ class Uexport extends BaseSettingsModule { parent::content(); $args = self::getClass(Arguments::class); - $action = $args->get(2); - if ($args->getArgc() > 2) { + if ($args->getArgc() == 3) { + $action = $args->get(2); header("Content-type: application/json"); header('Content-Disposition: attachment; filename="' . $a->user['nickname'] . '.' . $action . '"'); switch ($action) { From 882449266cc9301e0fd57d4ca432a9dab56e0600 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Fri, 11 Oct 2019 11:45:28 +0200 Subject: [PATCH 04/13] removed debugging leftover --- src/Module/Settings/Uexport.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Module/Settings/Uexport.php b/src/Module/Settings/Uexport.php index 8e0ee6758a..a0218c6b29 100644 --- a/src/Module/Settings/Uexport.php +++ b/src/Module/Settings/Uexport.php @@ -121,7 +121,6 @@ class Uexport extends BaseSettingsModule private function uexport_account($a) { - echo "

in uexport_account

"; $user = SELF::uexport_row( sprintf("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval(local_user())) ); From e3a947fb3da695f841d5fc110a9531888bd34c71 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Fri, 11 Oct 2019 11:48:05 +0200 Subject: [PATCH 05/13] keep the ToDo hint from delegations --- src/Module/Settings/Uexport.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Module/Settings/Uexport.php b/src/Module/Settings/Uexport.php index a0218c6b29..1331466298 100644 --- a/src/Module/Settings/Uexport.php +++ b/src/Module/Settings/Uexport.php @@ -33,6 +33,7 @@ class Uexport extends BaseSettingsModule parent::content(); $args = self::getClass(Arguments::class); if ($args->getArgc() == 3) { + // @TODO Replace with router-provided arguments $action = $args->get(2); header("Content-type: application/json"); header('Content-Disposition: attachment; filename="' . $a->user['nickname'] . '.' . $action . '"'); From 5ac5a67b6bb558740ce0cdbd4c3984e2c190ee26 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Fri, 11 Oct 2019 11:49:28 +0200 Subject: [PATCH 06/13] enhance description --- src/Module/Settings/Uexport.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Module/Settings/Uexport.php b/src/Module/Settings/Uexport.php index 1331466298..b19838941b 100644 --- a/src/Module/Settings/Uexport.php +++ b/src/Module/Settings/Uexport.php @@ -27,6 +27,9 @@ class Uexport extends BaseSettingsModule * 1. The profile data that can be used by uimport to resettle * to a different Friendica instance * 2. The entire data-set, profile plus postings + * + * If there is an action required through the URL / path, react + * accordingly and export the requested data. **/ public static function content() { From 9f3e68c2c536f6d865942b57598dcc370ebf9364 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Fri, 11 Oct 2019 11:55:57 +0200 Subject: [PATCH 07/13] correct the file name in the header --- src/Module/Settings/Uexport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Module/Settings/Uexport.php b/src/Module/Settings/Uexport.php index b19838941b..205abd01e0 100644 --- a/src/Module/Settings/Uexport.php +++ b/src/Module/Settings/Uexport.php @@ -1,6 +1,6 @@ Date: Fri, 11 Oct 2019 17:44:50 +0200 Subject: [PATCH 08/13] self should be lower case --- src/Module/Settings/Uexport.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Module/Settings/Uexport.php b/src/Module/Settings/Uexport.php index 205abd01e0..5ddd65612e 100644 --- a/src/Module/Settings/Uexport.php +++ b/src/Module/Settings/Uexport.php @@ -42,11 +42,11 @@ class Uexport extends BaseSettingsModule header('Content-Disposition: attachment; filename="' . $a->user['nickname'] . '.' . $action . '"'); switch ($action) { case "backup": - SELF::uexport_all($a); + self::uexport_all($a); exit(); break; case "account": - SELF::uexport_account($a); + self::uexport_account($a); exit(); break; default: @@ -125,35 +125,35 @@ class Uexport extends BaseSettingsModule private function uexport_account($a) { - $user = SELF::uexport_row( + $user = self::uexport_row( sprintf("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval(local_user())) ); - $contact = SELF::uexport_multirow( + $contact = self::uexport_multirow( sprintf("SELECT * FROM `contact` WHERE `uid` = %d ", intval(local_user())) ); - $profile = SELF::uexport_multirow( + $profile = self::uexport_multirow( sprintf("SELECT * FROM `profile` WHERE `uid` = %d ", intval(local_user())) ); - $photo = SELF::uexport_multirow( + $photo = self::uexport_multirow( sprintf("SELECT * FROM `photo` WHERE uid = %d AND profile = 1", intval(local_user())) ); foreach ($photo as &$p) { $p['data'] = bin2hex($p['data']); } - $pconfig = SELF::uexport_multirow( + $pconfig = self::uexport_multirow( sprintf("SELECT * FROM `pconfig` WHERE uid = %d", intval(local_user())) ); - $group = SELF::uexport_multirow( + $group = self::uexport_multirow( sprintf("SELECT * FROM `group` WHERE uid = %d", intval(local_user())) ); - $group_member = SELF::uexport_multirow( + $group_member = self::uexport_multirow( sprintf("SELECT `group_member`.`gid`, `group_member`.`contact-id` FROM `group_member` INNER JOIN `group` ON `group`.`id` = `group_member`.`gid` WHERE `group`.`uid` = %d", intval(local_user())) ); @@ -181,7 +181,7 @@ class Uexport extends BaseSettingsModule */ private function uexport_all(App $a) { - SELF::uexport_account($a); + self::uexport_account($a); echo "\n"; $total = 0; From 2ed61194d5cbebdac3d66f1e385a1f928213d632 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Thu, 17 Oct 2019 07:45:48 +0200 Subject: [PATCH 09/13] adopted some change requests --- src/Module/Settings/Uexport.php | 85 +++++++++++++++++---------------- 1 file changed, 45 insertions(+), 40 deletions(-) diff --git a/src/Module/Settings/Uexport.php b/src/Module/Settings/Uexport.php index 5ddd65612e..3939fff96f 100644 --- a/src/Module/Settings/Uexport.php +++ b/src/Module/Settings/Uexport.php @@ -34,25 +34,8 @@ class Uexport extends BaseSettingsModule public static function content() { parent::content(); - $args = self::getClass(Arguments::class); - if ($args->getArgc() == 3) { - // @TODO Replace with router-provided arguments - $action = $args->get(2); - header("Content-type: application/json"); - header('Content-Disposition: attachment; filename="' . $a->user['nickname'] . '.' . $action . '"'); - switch ($action) { - case "backup": - self::uexport_all($a); - exit(); - break; - case "account": - self::uexport_account($a); - exit(); - break; - default: - exit(); - } - } + + self::rawContent(); /** * options shown on "Export personal data" page @@ -70,8 +53,36 @@ class Uexport extends BaseSettingsModule '$options' => $options ]); } - private function uexport_multirow($query) { - global $dbStructure; + /** + * raw content generated for the different choices made + * by the user. At the moment this returns a JSON file + * to the browser which then offers a save / open dialog + * to the user. + **/ + public static function rawContent() { + $args = self::getClass(Arguments::class); + if ($args->getArgc() == 3) { + // @TODO Replace with router-provided arguments + $action = $args->get(2); + $user = self::getApp()->user; + header("Content-type: application/json"); + header('Content-Disposition: attachment; filename="' . $user['nickname'] . '.' . $action . '"'); + switch ($action) { + case "backup": + self::exportAll(self::getApp()); + exit(); + break; + case "account": + self::exportAccount(self::getApp()); + exit(); + break; + default: + exit(); + } + } + } + private static function exportMultiRow(string $query) { + $dbStructure = DBStructure::definition(self::getApp()->getBasePath(), false); preg_match("/\s+from\s+`?([a-z\d_]+)`?/i", $query, $match); $table = $match[1]; @@ -97,8 +108,8 @@ class Uexport extends BaseSettingsModule return $result; } - private function uexport_row($query) { - global $dbStructure; + private static function exportRow(string $query) { + $dbStructure = DBStructure::definition(self::getApp()->getBasePath(), false); preg_match("/\s+from\s+`?([a-z\d_]+)`?/i", $query, $match); $table = $match[1]; @@ -123,37 +134,37 @@ class Uexport extends BaseSettingsModule return $result; } - private function uexport_account($a) { + private static function exportAccount(App $a) { - $user = self::uexport_row( + $user = self::exportRow( sprintf("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval(local_user())) ); - $contact = self::uexport_multirow( + $contact = self::exportMultiRow( sprintf("SELECT * FROM `contact` WHERE `uid` = %d ", intval(local_user())) ); - $profile = self::uexport_multirow( + $profile = self::exportMultiRow( sprintf("SELECT * FROM `profile` WHERE `uid` = %d ", intval(local_user())) ); - $photo = self::uexport_multirow( + $photo = self::exportMultiRow( sprintf("SELECT * FROM `photo` WHERE uid = %d AND profile = 1", intval(local_user())) ); foreach ($photo as &$p) { $p['data'] = bin2hex($p['data']); } - $pconfig = self::uexport_multirow( + $pconfig = self::exportMultiRow( sprintf("SELECT * FROM `pconfig` WHERE uid = %d", intval(local_user())) ); - $group = self::uexport_multirow( + $group = self::exportMultiRow( sprintf("SELECT * FROM `group` WHERE uid = %d", intval(local_user())) ); - $group_member = self::uexport_multirow( + $group_member = self::exportMultiRow( sprintf("SELECT `group_member`.`gid`, `group_member`.`contact-id` FROM `group_member` INNER JOIN `group` ON `group`.`id` = `group_member`.`gid` WHERE `group`.`uid` = %d", intval(local_user())) ); @@ -179,18 +190,12 @@ class Uexport extends BaseSettingsModule * @param App $a * @throws Exception */ - private function uexport_all(App $a) { + private static function exportAll(App $a) { - self::uexport_account($a); + self::exportAccount($a); echo "\n"; - $total = 0; - $r = q("SELECT count(*) as `total` FROM `item` WHERE `uid` = %d ", - intval(local_user()) - ); - if (DBA::isResult($r)) { - $total = $r[0]['total']; - } + $total = DBA::count('item', ['uid' => local_user()]); // chunk the output to avoid exhausting memory for ($x = 0; $x < $total; $x += 500) { From 048b693fbfa6dcaf29e7dac48f9fd99902430a09 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Sat, 2 Nov 2019 11:24:46 +0100 Subject: [PATCH 10/13] some more change requests --- src/Module/Settings/Uexport.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Module/Settings/Uexport.php b/src/Module/Settings/Uexport.php index 3939fff96f..7d96139203 100644 --- a/src/Module/Settings/Uexport.php +++ b/src/Module/Settings/Uexport.php @@ -35,8 +35,6 @@ class Uexport extends BaseSettingsModule { parent::content(); - self::rawContent(); - /** * options shown on "Export personal data" page * list of array( 'link url', 'link text', 'help text' ) @@ -47,7 +45,7 @@ class Uexport extends BaseSettingsModule ]; Hook::callAll('uexport_options', $options); - $tpl = Renderer::getMarkupTemplate("uexport.tpl"); + $tpl = Renderer::getMarkupTemplate("settings/userexport.tpl"); return Renderer::replaceMacros($tpl, [ '$title' => L10n::t('Export personal data'), '$options' => $options @@ -59,7 +57,8 @@ class Uexport extends BaseSettingsModule * to the browser which then offers a save / open dialog * to the user. **/ - public static function rawContent() { + public static function rawContent() + { $args = self::getClass(Arguments::class); if ($args->getArgc() == 3) { // @TODO Replace with router-provided arguments @@ -81,7 +80,8 @@ class Uexport extends BaseSettingsModule } } } - private static function exportMultiRow(string $query) { + private static function exportMultiRow(string $query) + { $dbStructure = DBStructure::definition(self::getApp()->getBasePath(), false); preg_match("/\s+from\s+`?([a-z\d_]+)`?/i", $query, $match); @@ -108,7 +108,8 @@ class Uexport extends BaseSettingsModule return $result; } - private static function exportRow(string $query) { + private static function exportRow(string $query) + { $dbStructure = DBStructure::definition(self::getApp()->getBasePath(), false); preg_match("/\s+from\s+`?([a-z\d_]+)`?/i", $query, $match); @@ -134,8 +135,8 @@ class Uexport extends BaseSettingsModule return $result; } - private static function exportAccount(App $a) { - + private static function exportAccount(App $a) + { $user = self::exportRow( sprintf("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval(local_user())) ); @@ -190,8 +191,8 @@ class Uexport extends BaseSettingsModule * @param App $a * @throws Exception */ - private static function exportAll(App $a) { - + private static function exportAll(App $a) + { self::exportAccount($a); echo "\n"; From 15cdfdd414937554ecfefacabea0b8ff55628050 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Sat, 2 Nov 2019 11:36:31 +0100 Subject: [PATCH 11/13] mv Uexport to UserExport --- src/Module/Settings/{Uexport.php => UserExport.php} | 4 ++-- static/routes.config.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/Module/Settings/{Uexport.php => UserExport.php} (98%) diff --git a/src/Module/Settings/Uexport.php b/src/Module/Settings/UserExport.php similarity index 98% rename from src/Module/Settings/Uexport.php rename to src/Module/Settings/UserExport.php index 7d96139203..2a19d5f208 100644 --- a/src/Module/Settings/Uexport.php +++ b/src/Module/Settings/UserExport.php @@ -1,6 +1,6 @@ [Module\Settings\TwoFactor\Verify::class, [R::GET, R::POST]], ], '/delegation[/{action}/{user_id}]' => [Module\Settings\Delegation::class, [R::GET, R::POST]], - '/uexport[/{action}]' => [Module\Settings\Uexport::class, [R::GET, R::POST]], + '/uexport[/{action}]' => [Module\Settings\UserExport::class, [R::GET, R::POST]], ], '/randprof' => [Module\RandomProfile::class, [R::GET]], From 34932e12bf42878c86bb7df6b1cc978746d7f1b0 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Sat, 2 Nov 2019 12:12:29 +0100 Subject: [PATCH 12/13] mv q() to DBA::p() --- src/Module/Settings/UserExport.php | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/Module/Settings/UserExport.php b/src/Module/Settings/UserExport.php index 2a19d5f208..d6cd0aabf1 100644 --- a/src/Module/Settings/UserExport.php +++ b/src/Module/Settings/UserExport.php @@ -88,23 +88,22 @@ class UserExport extends BaseSettingsModule $table = $match[1]; $result = []; - $r = q($query); - if (DBA::isResult($r)) { - foreach ($r as $rr) { - $p = []; - foreach ($rr as $k => $v) { - switch ($dbStructure[$table]['fields'][$k]['type']) { - case 'datetime': - $p[$k] = $v ?? DBA::NULL_DATETIME; - break; - default: - $p[$k] = $v; - break; - } + $rows = DBA::p($query); + while ($row = DBA::fetch($rows)) { + $p = []; + foreach ($row as $k => $v) { + switch ($dbStructure[$table]['fields'][$k]['type']) { + case 'datetime': + $p[$k] = $v ?? DBA::NULL_DATETIME; + break; + default: + $p[$k] = $v; + break; } - $result[] = $p; } + $result[] = $p; } + DBA::close($rows); return $result; } From 8bea9e7523e3fc3bdab49ef256c20ab3ab329f20 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Sat, 2 Nov 2019 12:44:46 +0100 Subject: [PATCH 13/13] mv URL path uexport -> userexport --- mod/settings.php | 4 ++-- src/Module/BaseSettingsModule.php | 4 ++-- src/Module/Settings/UserExport.php | 4 ++-- src/Module/Tos.php | 4 ++-- static/routes.config.php | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mod/settings.php b/mod/settings.php index 24cb2a8794..497532561b 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -129,8 +129,8 @@ function settings_init(App $a) $tabs[] = [ 'label' => L10n::t('Export personal data'), - 'url' => 'settings/uexport', - 'selected' => (($a->argc > 1) && ($a->argv[1] === 'uexport')?'active':''), + 'url' => 'settings/userexport', + 'selected' => (($a->argc > 1) && ($a->argv[1] === 'userexport')?'active':''), 'accesskey' => 'e', ]; diff --git a/src/Module/BaseSettingsModule.php b/src/Module/BaseSettingsModule.php index 6945af8a5a..4b5e9bf915 100644 --- a/src/Module/BaseSettingsModule.php +++ b/src/Module/BaseSettingsModule.php @@ -87,8 +87,8 @@ class BaseSettingsModule extends BaseModule $tabs[] = [ 'label' => L10n::t('Export personal data'), - 'url' => 'settings/uexport', - 'selected' => (($a->argc > 1) && ($a->argv[1] === 'uexport') ? 'active' : ''), + 'url' => 'settings/userexport', + 'selected' => (($a->argc > 1) && ($a->argv[1] === 'userexport') ? 'active' : ''), 'accesskey' => 'e', ]; diff --git a/src/Module/Settings/UserExport.php b/src/Module/Settings/UserExport.php index d6cd0aabf1..41072d7ef5 100644 --- a/src/Module/Settings/UserExport.php +++ b/src/Module/Settings/UserExport.php @@ -40,8 +40,8 @@ class UserExport extends BaseSettingsModule * list of array( 'link url', 'link text', 'help text' ) */ $options = [ - ['settings/uexport/account', L10n::t('Export account'), L10n::t('Export your account info and contacts. Use this to make a backup of your account and/or to move it to another server.')], - ['settings/uexport/backup', L10n::t('Export all'), L10n::t("Export your accout info, contacts and all your items as json. Could be a very big file, and could take a lot of time. Use this to make a full backup of your account \x28photos are not exported\x29")], + ['settings/userexport/account', L10n::t('Export account'), L10n::t('Export your account info and contacts. Use this to make a backup of your account and/or to move it to another server.')], + ['settings/userexport/backup', L10n::t('Export all'), L10n::t("Export your accout info, contacts and all your items as json. Could be a very big file, and could take a lot of time. Use this to make a full backup of your account \x28photos are not exported\x29")], ]; Hook::callAll('uexport_options', $options); diff --git a/src/Module/Tos.php b/src/Module/Tos.php index 6dca554b25..c26085b48b 100644 --- a/src/Module/Tos.php +++ b/src/Module/Tos.php @@ -34,7 +34,7 @@ class Tos extends BaseModule { $this->privacy_operate = L10n::t('At the time of registration, and for providing communications between the user account and their contacts, the user has to provide a display name (pen name), an username (nickname) and a working email address. The names will be accessible on the profile page of the account by any visitor of the page, even if other profile details are not displayed. The email address will only be used to send the user notifications about interactions, but wont be visibly displayed. The listing of an account in the node\'s user directory or the global user directory is optional and can be controlled in the user settings, it is not necessary for communication.'); $this->privacy_distribute = L10n::t('This data is required for communication and is passed on to the nodes of the communication partners and is stored there. Users can enter additional private data that may be transmitted to the communication partners accounts.'); - $this->privacy_delete = L10n::t('At any point in time a logged in user can export their account data from the account settings. If the user wants to delete their account they can do so at %1$s/removeme. The deletion of the account will be permanent. Deletion of the data will also be requested from the nodes of the communication partners.', System::baseurl()); + $this->privacy_delete = L10n::t('At any point in time a logged in user can export their account data from the account settings. If the user wants to delete their account they can do so at %1$s/removeme. The deletion of the account will be permanent. Deletion of the data will also be requested from the nodes of the communication partners.', System::baseurl()); // In some cases we don't need every single one of the above separate, but all in one block. // So here is an array to look over $this->privacy_complete = [L10n::t('Privacy Statement'), $this->privacy_operate, $this->privacy_distribute, $this->privacy_delete]; @@ -76,7 +76,7 @@ class Tos extends BaseModule '$privstatementtitle' => L10n::t('Privacy Statement'), '$privacy_operate' => L10n::t('At the time of registration, and for providing communications between the user account and their contacts, the user has to provide a display name (pen name), an username (nickname) and a working email address. The names will be accessible on the profile page of the account by any visitor of the page, even if other profile details are not displayed. The email address will only be used to send the user notifications about interactions, but wont be visibly displayed. The listing of an account in the node\'s user directory or the global user directory is optional and can be controlled in the user settings, it is not necessary for communication.'), '$privacy_distribute' => L10n::t('This data is required for communication and is passed on to the nodes of the communication partners and is stored there. Users can enter additional private data that may be transmitted to the communication partners accounts.'), - '$privacy_delete' => L10n::t('At any point in time a logged in user can export their account data from the account settings. If the user wants to delete their account they can do so at %1$s/removeme. The deletion of the account will be permanent. Deletion of the data will also be requested from the nodes of the communication partners.', System::baseurl()) + '$privacy_delete' => L10n::t('At any point in time a logged in user can export their account data from the account settings. If the user wants to delete their account they can do so at %1$s/removeme. The deletion of the account will be permanent. Deletion of the data will also be requested from the nodes of the communication partners.', System::baseurl()) ]); } else { return; diff --git a/static/routes.config.php b/static/routes.config.php index e5b4614d85..fb0ec2f7e3 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -203,7 +203,7 @@ return [ '/verify' => [Module\Settings\TwoFactor\Verify::class, [R::GET, R::POST]], ], '/delegation[/{action}/{user_id}]' => [Module\Settings\Delegation::class, [R::GET, R::POST]], - '/uexport[/{action}]' => [Module\Settings\UserExport::class, [R::GET, R::POST]], + '/userexport[/{action}]' => [Module\Settings\UserExport::class, [R::GET, R::POST]], ], '/randprof' => [Module\RandomProfile::class, [R::GET]],