mirror of
https://github.com/friendica/friendica
synced 2025-01-25 01:39:47 +00:00
Merge pull request #9295 from annando/issue-9281
Issue 9281: User export now exports data
This commit is contained in:
commit
c7ac1dc9c1
1 changed files with 13 additions and 11 deletions
|
@ -27,6 +27,7 @@ use Friendica\Core\Renderer;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\Database\DBStructure;
|
use Friendica\Database\DBStructure;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
|
use Friendica\Model\Item;
|
||||||
use Friendica\Module\BaseSettings;
|
use Friendica\Module\BaseSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -115,10 +116,13 @@ class UserExport extends BaseSettings
|
||||||
while ($row = DBA::fetch($rows)) {
|
while ($row = DBA::fetch($rows)) {
|
||||||
$p = [];
|
$p = [];
|
||||||
foreach ($dbStructure[$table]['fields'] as $column => $field) {
|
foreach ($dbStructure[$table]['fields'] as $column => $field) {
|
||||||
|
if (!isset($row[$column])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if ($field['type'] == 'datetime') {
|
if ($field['type'] == 'datetime') {
|
||||||
$p[$column] = $v ?? DBA::NULL_DATETIME;
|
$p[$column] = $row[$column] ?? DBA::NULL_DATETIME;
|
||||||
} else {
|
} else {
|
||||||
$p[$column] = $v;
|
$p[$column] = $row[$column];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$result[] = $p;
|
$result[] = $p;
|
||||||
|
@ -140,6 +144,9 @@ class UserExport extends BaseSettings
|
||||||
|
|
||||||
foreach ($r as $rr) {
|
foreach ($r as $rr) {
|
||||||
foreach ($rr as $k => $v) {
|
foreach ($rr as $k => $v) {
|
||||||
|
if (empty($dbStructure[$table]['fields'][$k])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
switch ($dbStructure[$table]['fields'][$k]['type']) {
|
switch ($dbStructure[$table]['fields'][$k]['type']) {
|
||||||
case 'datetime':
|
case 'datetime':
|
||||||
$result[$k] = $v ?? DBA::NULL_DATETIME;
|
$result[$k] = $v ?? DBA::NULL_DATETIME;
|
||||||
|
@ -162,9 +169,9 @@ class UserExport extends BaseSettings
|
||||||
// write the table header (like Mastodon)
|
// write the table header (like Mastodon)
|
||||||
echo "Account address, Show boosts\n";
|
echo "Account address, Show boosts\n";
|
||||||
// get all the contacts
|
// 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)) {
|
while ($contact = DBA::fetch($contacts)) {
|
||||||
echo $contact['addr'] . ", true\n";
|
echo ($contact['addr'] ? $contact['addr'] : $contact['url']) . ", true\n";
|
||||||
}
|
}
|
||||||
DBA::close($contacts);
|
DBA::close($contacts);
|
||||||
}
|
}
|
||||||
|
@ -238,13 +245,8 @@ class UserExport extends BaseSettings
|
||||||
// chunk the output to avoid exhausting memory
|
// chunk the output to avoid exhausting memory
|
||||||
|
|
||||||
for ($x = 0; $x < $total; $x += 500) {
|
for ($x = 0; $x < $total; $x += 500) {
|
||||||
$r = q("SELECT * FROM `item` WHERE `uid` = %d LIMIT %d, %d",
|
$items = Item::selectToArray(Item::ITEM_FIELDLIST, ['uid' => local_user()], ['limit' => [$x, 500]]);
|
||||||
intval(local_user()),
|
$output = ['item' => $items];
|
||||||
intval($x),
|
|
||||||
intval(500)
|
|
||||||
);
|
|
||||||
|
|
||||||
$output = ['item' => $r];
|
|
||||||
echo json_encode($output, JSON_PARTIAL_OUTPUT_ON_ERROR). "\n";
|
echo json_encode($output, JSON_PARTIAL_OUTPUT_ON_ERROR). "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue