aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2021-09-30 12:25:03 +0200
committerMario Vavti <mario@mariovavti.com>2021-09-30 12:25:03 +0200
commitb9b4e71f7d81cca23a08c55fc12db5f62ece2b56 (patch)
tree60e5f7680c111089b07346618b97e7f1abe3b035
parentb0bf646d71b6ee393c9b00b608cf6ee28ca342cc (diff)
downloadvolse-hubzilla-b9b4e71f7d81cca23a08c55fc12db5f62ece2b56.tar.gz
volse-hubzilla-b9b4e71f7d81cca23a08c55fc12db5f62ece2b56.tar.bz2
volse-hubzilla-b9b4e71f7d81cca23a08c55fc12db5f62ece2b56.zip
provide a very simple status page for content import
-rw-r--r--Zotlabs/Daemon/Content_importer.php18
-rw-r--r--Zotlabs/Daemon/File_importer.php8
-rw-r--r--Zotlabs/Module/Import.php23
3 files changed, 37 insertions, 12 deletions
diff --git a/Zotlabs/Daemon/Content_importer.php b/Zotlabs/Daemon/Content_importer.php
index ff6956051..4a07b4cf4 100644
--- a/Zotlabs/Daemon/Content_importer.php
+++ b/Zotlabs/Daemon/Content_importer.php
@@ -3,6 +3,8 @@
namespace Zotlabs\Daemon;
use Zotlabs\Web\HTTPSig;
+use Zotlabs\Lib\PConfig;
+
require_once('include/cli_startup.php');
require_once('include/attach.php');
@@ -38,6 +40,8 @@ class Content_importer {
$x = z_fetch_url($hz_server . '/api/z/1.0/item/export_page?f=&since=' . urlencode($since) . '&until=' . urlencode($until) . '&page=' . $page,false,$redirects,[ 'headers' => $headers ]);
+ // logger('item fetch: ' . print_r($x,true));
+
if(! $x['success']) {
logger('no API response',LOGGER_DEBUG);
killme();
@@ -48,11 +52,9 @@ class Content_importer {
return;
}
- if(! is_array($j['item']) || ! count($j['item']))
+ if(! is_array($j['item']) || ! count($j['item'])) {
return;
-
- //$total_pages = floor(intval($j['items_total']) / intval($j['items_page']));
- //logger('importing items: ' . floor((intval($page) * 100) / $total_pages) . '%');
+ }
$saved_notification_flags = notifications_off($channel['channel_id']);
@@ -60,6 +62,14 @@ class Content_importer {
notifications_on($channel['channel_id'], $saved_notification_flags);
+ PConfig::Set($channel['channel_id'], 'import', 'content_progress', [
+ 'items_total' => $j['items_total'],
+ 'items_page' => $j['items_page'],
+ 'items_current_page' => count($j['item']),
+ 'last_page' => $page,
+ 'next_cmd' => ['Content_importer', sprintf('%d',$page + 1), $since, $until, $channel['channel_address'], urlencode($hz_server)]
+ ]);
+
$page++;
Master::Summon([ 'Content_importer', sprintf('%d',$page), $since, $until, $channel['channel_address'], urlencode($hz_server) ]);
diff --git a/Zotlabs/Daemon/File_importer.php b/Zotlabs/Daemon/File_importer.php
index 2be946fc3..bb12cdf70 100644
--- a/Zotlabs/Daemon/File_importer.php
+++ b/Zotlabs/Daemon/File_importer.php
@@ -3,6 +3,8 @@
namespace Zotlabs\Daemon;
use Zotlabs\Web\HTTPSig;
+use Zotlabs\Lib\PConfig;
+
require_once('include/cli_startup.php');
require_once('include/attach.php');
@@ -35,7 +37,9 @@ class File_importer {
$headers = HTTPSig::create_sig($headers,$channel['channel_prvkey'],channel_url($channel),true,'sha512');
+ // TODO: implement total count
$x = z_fetch_url($hz_server . '/api/z/1.0/file/export_page?f=records=1&page=' . $page, false, $redirects, [ 'headers' => $headers ]);
+ // logger('file fetch: ' . print_r($x,true));
if(! $x['success']) {
logger('no API response',LOGGER_DEBUG);
@@ -44,8 +48,10 @@ class File_importer {
$j = json_decode($x['body'],true);
- if(! is_array($j[0]['attach']) || ! count($j[0]['attach']))
+ if(! is_array($j[0]['attach']) || ! count($j[0]['attach'])) {
+ PConfig::Set($channel['channel_id'], 'import', 'files', 1);
return;
+ }
$r = sync_files($channel,$j);
diff --git a/Zotlabs/Module/Import.php b/Zotlabs/Module/Import.php
index a4697a426..38b64dd3c 100644
--- a/Zotlabs/Module/Import.php
+++ b/Zotlabs/Module/Import.php
@@ -12,6 +12,7 @@ use Zotlabs\Daemon\Master;
use Zotlabs\Lib\Libzot;
use Zotlabs\Web\Controller;
use Zotlabs\Web\HTTPSig;
+use Zotlabs\Lib\PConfig;
/**
@@ -435,6 +436,7 @@ class Import extends Controller {
logger('import step 8');
}
+
// import groups
$groups = $data['group'];
if ($groups) {
@@ -476,6 +478,7 @@ class Import extends Controller {
logger('import step 9');
+
if (is_array($data['obj']))
import_objs($channel, $data['obj']);
@@ -509,8 +512,15 @@ class Import extends Controller {
$addon = array('channel' => $channel, 'data' => $data);
call_hooks('import_channel', $addon);
- if ($import_posts && array_key_exists('item', $data) && $data['item'])
+ if ($import_posts && array_key_exists('item', $data) && $data['item']) {
import_items($channel, $data['item'], false, $relocate);
+ }
+
+ // Immediately notify old server about the new clone
+ Master::Summon( [ 'Notifier', 'refresh_all', $channel['channel_id'] ] );
+
+ // This will indirectly perform a refresh_all *and* update the directory
+ Master::Summon(array('Directory', $channel['channel_id']));
if ($api_path && $import_posts) { // we are importing from a server and not a file
@@ -533,16 +543,15 @@ class Import extends Controller {
//if (array_key_exists('item_id', $data) && $data['item_id'])
// import_item_ids($channel, $data['item_id']);
- // This will indirectly perform a refresh_all *and* update the directory
-
- Master::Summon(array('Directory', $channel['channel_id']));
-
change_channel($channel['channel_id']);
- notice(t('Import of items and files in progress') . EOL);
+ notice(t('Content import in progress...') . EOL);
+
+ if ($api_path && $import_posts)
+ goaway(z_root() . '/import_progress');
- // TODO: go away to a import progress page
goaway(z_root());
+
}
/**