aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Daemon/Content_importer.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2021-11-09 09:10:19 +0000
committerMario <mario@mariovavti.com>2021-11-09 09:10:19 +0000
commitfe7ecede700fe04631d23f36473e697ce2b364dc (patch)
treee713fc39dba500a25cb2acf8561e286fb8b41ff0 /Zotlabs/Daemon/Content_importer.php
parent42de18d96d201d74e5df3ed1b8f6132cb00357b6 (diff)
parent089708ab9f90309a0c27ae633cf8f2604fce1170 (diff)
downloadvolse-hubzilla-fe7ecede700fe04631d23f36473e697ce2b364dc.tar.gz
volse-hubzilla-fe7ecede700fe04631d23f36473e697ce2b364dc.tar.bz2
volse-hubzilla-fe7ecede700fe04631d23f36473e697ce2b364dc.zip
Merge branch '6.4RC'6.4
Diffstat (limited to 'Zotlabs/Daemon/Content_importer.php')
-rw-r--r--Zotlabs/Daemon/Content_importer.php77
1 files changed, 77 insertions, 0 deletions
diff --git a/Zotlabs/Daemon/Content_importer.php b/Zotlabs/Daemon/Content_importer.php
new file mode 100644
index 000000000..67f1c8e80
--- /dev/null
+++ b/Zotlabs/Daemon/Content_importer.php
@@ -0,0 +1,77 @@
+<?php
+
+namespace Zotlabs\Daemon;
+
+use Zotlabs\Web\HTTPSig;
+use Zotlabs\Lib\PConfig;
+
+
+require_once('include/cli_startup.php');
+require_once('include/attach.php');
+require_once('include/import.php');
+
+class Content_importer {
+
+ static public function run($argc,$argv) {
+ cli_startup();
+
+ $page = $argv[1];
+ $since = $argv[2];
+ $until = $argv[3];
+ $channel_address = $argv[4];
+ $hz_server = urldecode($argv[5]);
+
+ $m = parse_url($hz_server);
+
+ $channel = channelx_by_nick($channel_address);
+ if(! $channel) {
+ logger('channel not found');
+ return;
+ }
+
+ $headers = [
+ 'X-API-Token' => random_string(),
+ 'X-API-Request' => $hz_server . '/api/z/1.0/item/export_page?f=&since=' . urlencode($since) . '&until=' . urlencode($until) . '&page=' . $page ,
+ 'Host' => $m['host'],
+ '(request-target)' => 'get /api/z/1.0/item/export_page?f=&since=' . urlencode($since) . '&until=' . urlencode($until) . '&page=' . $page ,
+ ];
+
+ $headers = HTTPSig::create_sig($headers,$channel['channel_prvkey'], channel_url($channel),true,'sha512');
+
+ $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();
+ }
+
+ $j = json_decode($x['body'],true);
+
+ if(! is_array($j['item']) || ! count($j['item'])) {
+ PConfig::Set($channel['channel_id'], 'import', 'content_completed', 1);
+ return;
+ }
+
+ $saved_notification_flags = notifications_off($channel['channel_id']);
+
+ import_items($channel,$j['item'],false,((array_key_exists('relocate',$j)) ? $j['relocate'] : null));
+
+ 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) ]);
+
+ return;
+ }
+}