Merge pull request #9295 from annando/issue-9281

Issue 9281: User export now exports data
This commit is contained in:
Tobias Diekershoff 2020-09-27 14:20:48 +02:00 committed by GitHub
commit c7ac1dc9c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -27,6 +27,7 @@ use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\Database\DBStructure;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Module\BaseSettings;
/**
@ -115,10 +116,13 @@ class UserExport extends BaseSettings
while ($row = DBA::fetch($rows)) {
$p = [];
foreach ($dbStructure[$table]['fields'] as $column => $field) {
if (!isset($row[$column])) {
continue;
}
if ($field['type'] == 'datetime') {
$p[$column] = $v ?? DBA::NULL_DATETIME;
$p[$column] = $row[$column] ?? DBA::NULL_DATETIME;
} else {
$p[$column] = $v;
$p[$column] = $row[$column];
}
}
$result[] = $p;
@ -140,6 +144,9 @@ class UserExport extends BaseSettings
foreach ($r as $rr) {
foreach ($rr as $k => $v) {
if (empty($dbStructure[$table]['fields'][$k])) {
continue;
}
switch ($dbStructure[$table]['fields'][$k]['type']) {
case 'datetime':
$result[$k] = $v ?? DBA::NULL_DATETIME;
@ -162,9 +169,9 @@ class UserExport extends BaseSettings
// write the table header (like Mastodon)
echo "Account address, Show boosts\n";
// get all the contacts
$contacts = DBA::select('contact', ['addr'], ['uid' => $_SESSION['uid'], 'self' => false, 'rel' => [1,3], 'deleted' => false]);
$contacts = DBA::select('contact', ['addr', 'url'], ['uid' => $_SESSION['uid'], 'self' => false, 'rel' => [1,3], 'deleted' => false]);
while ($contact = DBA::fetch($contacts)) {
echo $contact['addr'] . ", true\n";
echo ($contact['addr'] ? $contact['addr'] : $contact['url']) . ", true\n";
}
DBA::close($contacts);
}
@ -238,13 +245,8 @@ class UserExport extends BaseSettings
// 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];
$items = Item::selectToArray(Item::ITEM_FIELDLIST, ['uid' => local_user()], ['limit' => [$x, 500]]);
$output = ['item' => $items];
echo json_encode($output, JSON_PARTIAL_OUTPUT_ON_ERROR). "\n";
}
}