From c33660a015ff4a2ed387caa4064fc8c4d8655419 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 6 Oct 2021 09:36:14 +0200 Subject: move sync logic for apps to mod appman. this way we can re-use the functions without creating sync loops. --- Zotlabs/Lib/Apps.php | 79 +++++++++++++++++++------------------------------ Zotlabs/Lib/Libsync.php | 6 ++-- 2 files changed, 33 insertions(+), 52 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Apps.php b/Zotlabs/Lib/Apps.php index 99c8144a6..2c5b8a546 100644 --- a/Zotlabs/Lib/Apps.php +++ b/Zotlabs/Lib/Apps.php @@ -3,7 +3,6 @@ namespace Zotlabs\Lib; use App; -use Zotlabs\Lib\Libsync; require_once('include/plugin.php'); require_once('include/channel.php'); @@ -627,10 +626,12 @@ class Apps { $app['uid'] = $uid; - if(self::app_installed($uid,$app,true)) + if(self::app_installed($uid,$app,true)) { $x = self::app_update($app); - else + } + else { $x = self::app_store($app); + } if($x['success']) { $r = q("select * from app where app_id = '%s' and app_channel = %d limit 1", @@ -645,12 +646,6 @@ class Apps { intval($r[0]['id']) ); } - if (intval($r[0]['app_system'])) { - Libsync::build_sync_packet($uid, ['sysapp' => $r]); - } - else { - Libsync::build_sync_packet($uid, ['app' => $r]); - } } } return $x['app_id']; @@ -690,45 +685,35 @@ class Apps { dbesc($app['guid']), intval($uid) ); - if($x) { - if(! intval($x[0]['app_deleted'])) { - $x[0]['app_deleted'] = 1; - if(self::can_delete($uid,$app)) { - q("delete from app where app_id = '%s' and app_channel = %d", - dbesc($app['guid']), - intval($uid) - ); - q("delete from term where otype = %d and oid = %d", - intval(TERM_OBJ_APP), - intval($x[0]['id']) - ); - /** - * @hooks app_destroy - * Called after app entry got removed from database - * and provide app array from database. - */ - call_hooks('app_destroy', $x[0]); - } - else { - q("update app set app_deleted = 1 where app_id = '%s' and app_channel = %d", - dbesc($app['guid']), - intval($uid) - ); - } - // unset the id before sync - unset($x[0]['id']); + if($x && intval($x[0]['app_deleted'])) { + self::app_undestroy($uid, $app); + return; + } - if (intval($x[0]['app_system'])) { - Libsync::build_sync_packet($uid, ['sysapp' => $x]); - } - else { - Libsync::build_sync_packet($uid, ['app' => $x]); - } - } - else { - self::app_undestroy($uid,$app); - } + if(self::can_delete($uid,$app)) { + q("delete from app where app_id = '%s' and app_channel = %d", + dbesc($app['guid']), + intval($uid) + ); + + q("delete from term where otype = %d and oid = %d", + intval(TERM_OBJ_APP), + intval($x[0]['id']) + ); + + /** + * @hooks app_destroy + * Called after app entry got removed from database + * and provide app array from database. + */ + call_hooks('app_destroy', $x[0]); + } + else { + q("update app set app_deleted = 1 where app_id = '%s' and app_channel = %d", + dbesc($app['guid']), + intval($uid) + ); } } } @@ -750,8 +735,6 @@ class Apps { dbesc($app['guid']), intval($uid) ); - $x[0]['app_deleted'] = 0; - Libsync::build_sync_packet($uid, ['sysapp' => $x]); } } } diff --git a/Zotlabs/Lib/Libsync.php b/Zotlabs/Lib/Libsync.php index d4ed57c3a..c4f1b20ea 100644 --- a/Zotlabs/Lib/Libsync.php +++ b/Zotlabs/Lib/Libsync.php @@ -141,7 +141,6 @@ class Libsync { logger('Packet: ' . print_r($info, true), LOGGER_DATA, LOG_DEBUG); $total = count($synchubs); - foreach ($synchubs as $hub) { $hash = random_string(); $n = Libzot::build_packet($channel, 'sync', $env_recips, json_encode($info), 'hz', $hub['hubloc_sitekey'], $hub['site_crypto']); @@ -186,7 +185,6 @@ class Libsync { require_once('include/import.php'); $result = []; - $keychange = ((array_key_exists('keychange', $arr)) ? true : false); foreach ($deliveries as $d) { @@ -242,14 +240,14 @@ class Libsync { if (array_key_exists('likes', $arr) && $arr['likes']) import_likes($channel, $arr['likes']); -/* + if (array_key_exists('app', $arr) && $arr['app']) sync_apps($channel, $arr['app']); if (array_key_exists('sysapp',$arr) && $arr['sysapp']) { sync_sysapps($channel, $arr['sysapp']); } -*/ + if (array_key_exists('addressbook', $arr) && $arr['addressbook']) sync_addressbook($channel, $arr['addressbook']); -- cgit v1.2.3