diff options
Diffstat (limited to 'Zotlabs/Daemon')
-rw-r--r-- | Zotlabs/Daemon/Cache_embeds.php | 15 | ||||
-rw-r--r-- | Zotlabs/Daemon/Channel_purge.php | 2 | ||||
-rw-r--r-- | Zotlabs/Daemon/Content_importer.php | 12 | ||||
-rw-r--r-- | Zotlabs/Daemon/Cron.php | 58 | ||||
-rw-r--r-- | Zotlabs/Daemon/Expire.php | 4 | ||||
-rw-r--r-- | Zotlabs/Daemon/File_importer.php | 8 | ||||
-rw-r--r-- | Zotlabs/Daemon/Importdoc.php | 21 | ||||
-rw-r--r-- | Zotlabs/Daemon/Notifier.php | 43 |
8 files changed, 89 insertions, 74 deletions
diff --git a/Zotlabs/Daemon/Cache_embeds.php b/Zotlabs/Daemon/Cache_embeds.php index d5adfcc59..99b1c7ac0 100644 --- a/Zotlabs/Daemon/Cache_embeds.php +++ b/Zotlabs/Daemon/Cache_embeds.php @@ -6,23 +6,28 @@ class Cache_embeds { static public function run($argc,$argv) { - if(! $argc == 2) + if(!$argc == 2) { return; + } - $c = q("select body from item where id = %d ", - dbesc(intval($argv[1])) + $c = q("select uid, aid, body, item_private from item where uuid = '%s'", + dbesc($argv[1]) ); - if(! $c) + if(!$c) { return; + } $item = $c[0]; // bbcode conversion by default processes embeds that aren't already cached. // Ignore the returned html output. - bbcode($item['body']); + // photocache addon hook to prefetch one copy of public item images for the sys channel + call_hooks('cache_prefetch_hook', $item); + return; } + } diff --git a/Zotlabs/Daemon/Channel_purge.php b/Zotlabs/Daemon/Channel_purge.php index 9fceb0fb9..7286a791a 100644 --- a/Zotlabs/Daemon/Channel_purge.php +++ b/Zotlabs/Daemon/Channel_purge.php @@ -24,7 +24,7 @@ class Channel_purge { ); if ($r) { foreach ($r as $rv) { - drop_item($rv['id'], false); + drop_item($rv['id'], uid: $channel_id); } } } while ($r); diff --git a/Zotlabs/Daemon/Content_importer.php b/Zotlabs/Daemon/Content_importer.php index 67f1c8e80..b98a1f10d 100644 --- a/Zotlabs/Daemon/Content_importer.php +++ b/Zotlabs/Daemon/Content_importer.php @@ -38,7 +38,13 @@ class Content_importer { $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 ]); + $redirects = 0; + $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)); @@ -47,9 +53,9 @@ class Content_importer { killme(); } - $j = json_decode($x['body'],true); + $j = json_decode($x['body'], true); - if(! is_array($j['item']) || ! count($j['item'])) { + if($j && empty($j['item'])) { PConfig::Set($channel['channel_id'], 'import', 'content_completed', 1); return; } diff --git a/Zotlabs/Daemon/Cron.php b/Zotlabs/Daemon/Cron.php index d2c863572..131abe2e1 100644 --- a/Zotlabs/Daemon/Cron.php +++ b/Zotlabs/Daemon/Cron.php @@ -69,18 +69,18 @@ class Cron { // expire any expired items - $r = q("select id,item_wall from item where expires > '2001-01-01 00:00:00' and expires < %s + $r = q("select id, uid, item_wall from item where expires > '2001-01-01 00:00:00' and expires < %s and item_deleted = 0 ", db_utcnow() ); + if ($r) { - require_once('include/items.php'); foreach ($r as $rr) { - drop_item($rr['id'], false, (($rr['item_wall']) ? DROPITEM_PHASE1 : DROPITEM_NORMAL)); + // pass uid of the message for permission check as we are running as a daemon process with no session. + drop_item($rr['id'], (($rr['item_wall']) ? DROPITEM_PHASE1 : DROPITEM_NORMAL), uid: intval($rr['uid'])); if ($rr['item_wall']) { // The notifier isn't normally invoked unless item_drop is interactive. Master::Summon(['Notifier', 'drop', $rr['id']]); - if ($interval) { usleep($interval); } @@ -125,14 +125,15 @@ class Cron { $r = q("SELECT DISTINCT xchan, content FROM photo WHERE photo_usage = %d AND expires < %s - INTERVAL %s", intval(PHOTO_CACHE), db_utcnow(), - db_quoteinterval(Config::Get('system', 'cache_expire_days', 7) . ' DAY') + db_quoteinterval(Config::Get('system', 'default_expire_days', 30) . ' DAY') ); if ($r) { q("DELETE FROM photo WHERE photo_usage = %d AND expires < %s - INTERVAL %s", intval(PHOTO_CACHE), db_utcnow(), - db_quoteinterval(Config::Get('system', 'cache_expire_days', 7) . ' DAY') + db_quoteinterval(Config::Get('system', 'default_expire_days', 30) . ' DAY') ); + foreach ($r as $rr) { $file = dbunescbin($rr['content']); if (is_file($file)) { @@ -147,40 +148,29 @@ class Cron { // (time travel posts). Restrict to items that have come of age in the last // couple of days to limit the query to something reasonable. - $r = q("select id from item where item_delayed = 1 and created <= %s and created > '%s' ", + $r = q("select * from item where item_delayed = 1 and created <= %s and created > '%s' ", db_utcnow(), dbesc(datetime_convert('UTC', 'UTC', 'now - 2 days')) ); - if ($r) { - foreach ($r as $rr) { - $x = q("update item set item_delayed = 0 where id = %d", - intval($rr['id']) - ); - if ($x) { - $z = q("select * from item where id = %d", - intval($rr['id']) - ); - if ($z) { - xchan_query($z); - $sync_item = fetch_post_tags($z); - Libsync::build_sync_packet($sync_item[0]['uid'], - [ - 'item' => [encode_item($sync_item[0], true)] - ] - ); - } - Master::Summon(array('Notifier', 'wall-new', $rr['id'])); - if ($interval) { - usleep($interval); + if ($r) { + xchan_query($r); + $items = fetch_post_tags($r); + foreach ($items as $item) { + $item['item_delayed'] = 0; + $post = item_store_update($item); + + if($post['success']) { + Master::Summon(['Notifier', 'wall-new', $post['item_id']]); + if (!empty($post['approval_id'])) { + Master::Summon(['Notifier', 'wall-new', $post['approval_id']]); } } - } - } - - require_once('include/attach.php'); - attach_upgrade(); - + if ($interval) { + usleep($interval); + } + } + } // once daily run birthday_updates and then expire in background // FIXME: add birthday updates, both locally and for xprof for use diff --git a/Zotlabs/Daemon/Expire.php b/Zotlabs/Daemon/Expire.php index ad52a6b71..dae585578 100644 --- a/Zotlabs/Daemon/Expire.php +++ b/Zotlabs/Daemon/Expire.php @@ -23,13 +23,13 @@ class Expire { // perform final cleanup on previously delete items - $r = q("select id from item where item_deleted = 1 and item_pending_remove = 0 and changed < %s - INTERVAL %s", + $r = q("select id, uid from item where item_deleted = 1 and item_pending_remove = 0 and changed < %s - INTERVAL %s", db_utcnow(), db_quoteinterval('10 DAY') ); if ($r) { foreach ($r as $rr) { - drop_item($rr['id'], false, DROPITEM_PHASE2); + drop_item($rr['id'], DROPITEM_PHASE2, uid: $rr['uid']); } } diff --git a/Zotlabs/Daemon/File_importer.php b/Zotlabs/Daemon/File_importer.php index 7067e152d..1ddab60f0 100644 --- a/Zotlabs/Daemon/File_importer.php +++ b/Zotlabs/Daemon/File_importer.php @@ -38,7 +38,13 @@ 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 ]); + $redirects = 0; + $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']) { diff --git a/Zotlabs/Daemon/Importdoc.php b/Zotlabs/Daemon/Importdoc.php index c5a81e50c..de571848e 100644 --- a/Zotlabs/Daemon/Importdoc.php +++ b/Zotlabs/Daemon/Importdoc.php @@ -11,6 +11,21 @@ class Importdoc { self::update_docs_dir('doc/*'); + $sys = get_sys_channel(); + + // remove old files that weren't updated (indicates they were most likely deleted). + $i = q("select id from item where uid = %d and item_type = 5 and edited < %s - INTERVAL %s", + intval($sys['channel_id']), + db_utcnow(), + db_quoteinterval('14 DAY') + ); + + if ($i) { + foreach ($i as $iv) { + drop_item($iv['id'], uid: $sys['channel_id']); + } + } + return; } @@ -18,9 +33,13 @@ class Importdoc { static public function update_docs_dir($s) { $f = basename($s); $d = dirname($s); - if ($s === 'doc/html') + + if ($s === 'doc/html') { return; + } + $files = glob("$d/$f"); + if ($files) { foreach ($files as $fi) { if ($fi === 'doc/html') { diff --git a/Zotlabs/Daemon/Notifier.php b/Zotlabs/Daemon/Notifier.php index 20134b8fe..9fdb1defb 100644 --- a/Zotlabs/Daemon/Notifier.php +++ b/Zotlabs/Daemon/Notifier.php @@ -241,11 +241,6 @@ class Notifier { $target_item = $r[0]; - if (in_array($target_item['author']['xchan_network'], ['rss', 'anon', 'token'])) { - logger('notifier: target item author is not a fetchable actor', LOGGER_DEBUG); - return; - } - if (intval($target_item['item_deleted'])) { logger('notifier: target item ITEM_DELETED', LOGGER_DEBUG); } @@ -268,22 +263,9 @@ class Notifier { } - // Check for non published items, but allow an exclusion for transmitting hidden file activities - - if (intval($target_item['item_unpublished']) || intval($target_item['item_delayed']) || - intval($target_item['item_blocked']) || intval($target_item['item_hidden'])) { - logger('notifier: target item not published, so not forwardable', LOGGER_DEBUG); - return; - } - - // follow/unfollow is for internal use only - if (in_array($target_item['verb'], ['Follow', 'Ignore', ACTIVITY_FOLLOW, ACTIVITY_UNFOLLOW])) { - logger('not fowarding follow/unfollow note activity'); - return; - } - - if (strpos($target_item['postopts'], 'nodeliver') !== false) { - logger('notifier: target item is undeliverable', LOGGER_DEBUG); + if (!item_forwardable($target_item)) { + //hz_syslog(print_r($target_item,true)); + logger('notifier: target item not forwardable', LOGGER_DEBUG); return; } @@ -299,7 +281,7 @@ class Notifier { return; } - if ($target_item['verb'] === ACTIVITY_SHARE) { + if (in_array($target_item['verb'], [ACTIVITY_SHARE])) { // Provide correct representation across the wire. Internally this is treated as a comment. $target_item['parent_mid'] = $target_item['thr_parent'] = $target_item['mid']; } @@ -341,7 +323,13 @@ class Notifier { self::$encoded_item = json_decode($m, true); } else { - self::$encoded_item = Activity::build_packet(Activity::encode_activity($target_item), self::$channel, false); + $activity = Activity::encode_activity($target_item); + + if (!$activity) { + return; + } + + self::$encoded_item = Activity::build_packet($activity, self::$channel, false); } logger('target_item: ' . print_r($target_item, true), LOGGER_DEBUG); @@ -358,6 +346,10 @@ class Notifier { $relay_to_owner = (!$top_level_post && intval($target_item['item_origin']) && comment_local_origin($target_item)); + if (self::$channel['channel_hash'] === $target_item['owner_xchan']) { + $relay_to_owner = false; + } + // $cmd === 'relay' indicates the owner is sending it to the original recipients // don't allow the item in the relay command to relay to owner under any circumstances, it will loop @@ -374,7 +366,6 @@ class Notifier { if (($relay_to_owner || $uplink) && ($cmd !== 'relay')) { logger('notifier: followup relay', LOGGER_DEBUG); - // If the Parent item is an Announce the real owner is the parent author $sendto = (($uplink) ? $parent_item['source_xchan'] : $parent_item['owner_xchan']); self::$recipients = [$sendto]; self::$private = true; @@ -389,7 +380,7 @@ class Notifier { logger('normal (downstream) distribution', LOGGER_DEBUG); } - if ($parent_item && $parent_item['item_private'] !== $target_item['item_private']) { + if (($parent_item && $parent_item['item_private'] !== $target_item['item_private']) || (intval($target_item['item_restrict']) & 1)) { logger('conversation privacy mismatch - downstream delivery prevented'); return; } @@ -589,8 +580,6 @@ class Notifier { foreach ($dhubs as $hub) { - logger('notifier_hub: ' . $hub['hubloc_url'], LOGGER_DEBUG); - if ($hub['hubloc_network'] !== 'zot6') { $narr = [ 'channel' => self::$channel, |