aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Daemon
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs/Daemon')
-rw-r--r--Zotlabs/Daemon/Channel_purge.php34
-rw-r--r--Zotlabs/Daemon/Content_importer.php18
-rw-r--r--Zotlabs/Daemon/File_importer.php16
3 files changed, 62 insertions, 6 deletions
diff --git a/Zotlabs/Daemon/Channel_purge.php b/Zotlabs/Daemon/Channel_purge.php
new file mode 100644
index 000000000..416126896
--- /dev/null
+++ b/Zotlabs/Daemon/Channel_purge.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace Zotlabs\Daemon;
+
+class Channel_purge {
+
+ static public function run($argc,$argv) {
+
+ cli_startup();
+
+ $channel_id = intval($argv[1]);
+
+ $channel = q("select * from channel where channel_id = %d and channel_removed = 1",
+ intval($channel_id)
+ );
+
+ if (! $channel) {
+ return;
+ }
+
+ do {
+ $r = q("select id from item where uid = %d and item_deleted = 0 limit 100",
+ intval($channel_id)
+ );
+ if ($r) {
+ foreach ($r as $rv) {
+ drop_item($rv['id'],false);
+ }
+ }
+ } while ($r);
+
+ return;
+ }
+}
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..28fb172a7 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,10 +48,18 @@ class File_importer {
$j = json_decode($x['body'],true);
- if(! is_array($j[0]['attach']) || ! count($j[0]['attach']))
+ if(! is_array($j['results'][0]['attach']) || ! count($j['results'][0]['attach'])) {
return;
+ }
+
+ $r = sync_files($channel, $j['results']);
- $r = sync_files($channel,$j);
+ 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++;