aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2021-09-30 17:34:30 +0200
committerMario Vavti <mario@mariovavti.com>2021-09-30 17:34:30 +0200
commit6236869ebed317aa06078f606156edcec9f9b55b (patch)
tree19be979d3200ba90aa77cda4edbf6157755f300a
parentb9b4e71f7d81cca23a08c55fc12db5f62ece2b56 (diff)
downloadvolse-hubzilla-6236869ebed317aa06078f606156edcec9f9b55b.tar.gz
volse-hubzilla-6236869ebed317aa06078f606156edcec9f9b55b.tar.bz2
volse-hubzilla-6236869ebed317aa06078f606156edcec9f9b55b.zip
implement file totals and add mod import_progress
-rw-r--r--Zotlabs/Daemon/File_importer.php12
-rw-r--r--Zotlabs/Module/Import_progress.php66
-rw-r--r--include/api_zot.php17
3 files changed, 88 insertions, 7 deletions
diff --git a/Zotlabs/Daemon/File_importer.php b/Zotlabs/Daemon/File_importer.php
index bb12cdf70..28fb172a7 100644
--- a/Zotlabs/Daemon/File_importer.php
+++ b/Zotlabs/Daemon/File_importer.php
@@ -48,12 +48,18 @@ class File_importer {
$j = json_decode($x['body'],true);
- if(! is_array($j[0]['attach']) || ! count($j[0]['attach'])) {
- PConfig::Set($channel['channel_id'], 'import', 'files', 1);
+ if(! is_array($j['results'][0]['attach']) || ! count($j['results'][0]['attach'])) {
return;
}
- $r = sync_files($channel,$j);
+ $r = sync_files($channel, $j['results']);
+
+ PConfig::Set($channel['channel_id'], 'import', 'files_progress', [
+ 'files_total' => $j['total'],
+ 'files_page' => 1, // export page atm returns just one file
+ 'last_page' => $page,
+ 'next_cmd' => ['File_importer',sprintf('%d',$page + 1), $channel['channel_address'], urlencode($hz_server)]
+ ]);
$page++;
diff --git a/Zotlabs/Module/Import_progress.php b/Zotlabs/Module/Import_progress.php
new file mode 100644
index 000000000..3bae94bbb
--- /dev/null
+++ b/Zotlabs/Module/Import_progress.php
@@ -0,0 +1,66 @@
+<?php
+namespace Zotlabs\Module;
+
+use Zotlabs\Lib\PConfig;
+
+class Import_progress extends \Zotlabs\Web\Controller {
+
+ function post() {
+
+ if(! local_channel())
+ return;
+
+ }
+
+ function get() {
+
+ if(! local_channel()) {
+ return;
+ }
+
+ // items
+ $c = PConfig::Get(local_channel(), 'import', 'content_progress');
+
+ if (!$c) {
+ $co = 'Status items: waiting to start...';
+ }
+ else {
+ $total_cpages = floor(intval($c['items_total']) / intval($c['items_page']));
+ if(!$total_cpages)
+ $total_cpages = 1; // because of floor
+
+ $cpage = $c['last_page'] + 1; // because page count start at 0
+
+ $co = 'Status items: ' . floor((intval($cpage) * 100) / $total_cpages) . '%';
+ }
+
+ // files
+ $f = PConfig::Get(local_channel(), 'import', 'files_progress');
+
+ if (!$f) {
+ $fo = 'Status files: waiting to start...';
+ }
+ else {
+ $total_fpages = floor(intval($f['files_total']) / intval($f['files_page']));
+ if(!$total_fpages)
+ $total_fpages = 1;
+
+ $fpage = $f['last_page'] + 1;
+
+ $fo = 'Status files: ' . floor((intval($fpage) * 100) / $total_fpages) . '%';
+ }
+
+ $o .= '<h3>' . $co . '</h3>';
+ if (is_array($c))
+ $o .= '<pre>' . htmlspecialchars(print_array($c)) . '</pre>';
+
+ $o .= '<h3>' . $fo . '</h3>';
+ if (is_array($f))
+ $o .= '<pre>' . htmlspecialchars(print_array($f)) . '</pre>';
+
+ $o .= '<h3> Refresh page for updates!</h3>';
+
+ return $o;
+ }
+
+}
diff --git a/include/api_zot.php b/include/api_zot.php
index 93b99c0c8..dda726787 100644
--- a/include/api_zot.php
+++ b/include/api_zot.php
@@ -305,24 +305,33 @@
if(api_user() === false)
return false;
- $ret = [];
$codebase = ((isset($_REQUEST['zap_compat']) && $_REQUEST['zap_compat']) ? true : false);
$channel = channelx_by_n(api_user());
$page = ((array_key_exists('page',$_REQUEST)) ? intval($_REQUEST['page']) : 0);
+ $ret['success'] = false;
+ $ret['total'] = attach_count_files($channel['channel_id'], get_observer_hash());
+ $ret['results'] = [];
+
+ if (!$ret['total']) {
+ json_return_and_die($ret);
+ }
+
$files = attach_list_files($channel['channel_id'], get_observer_hash(), '', '', '', 'created asc' ,$page, 1);
if (!$files['success']) {
- return false;
+ json_return_and_die($ret);
}
foreach($files['results'] as $file) {
- $ret[] = attach_export_data($channel, $file['hash'], false, $codebase);
+ $ret['results'] = attach_export_data($channel, $file['hash'], false, $codebase);
}
- if($ret) {
+ if($ret['results']) {
+ $ret['success'] = true;
json_return_and_die($ret);
}
+
killme();
}