move sync logic for apps to mod appman. this way we can re-use the functions without creating sync loops.

This commit is contained in:
Mario Vavti
2021-10-06 09:36:14 +02:00
parent 16281e0e7f
commit c33660a015
3 changed files with 35 additions and 77 deletions

View File

@@ -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]);
}
}
}

View File

@@ -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']);

View File

@@ -591,7 +591,6 @@ function import_sysapps($channel, $apps) {
function sync_sysapps($channel, $apps) {
$sysapps = Apps::get_system_apps(false, true);
if ($channel && $apps) {
$columns = db_columns('app');
@@ -608,30 +607,8 @@ function sync_sysapps($channel, $apps) {
foreach ($sysapps as $sysapp) {
if ($app['app_id'] === hash('whirlpool', $sysapp['name'])) {
if (array_key_exists('app_deleted',$app) && $app['app_deleted'] && $app['app_id']) {
if(Apps::can_delete($channel['channel_id'], ['guid' => $app['app_id']])) {
$local_app = q("select id from app where app_id = '%s' and app_channel = %d limit 1",
dbesc($app['app_id']),
intval($channel['channel_id'])
);
if ($local_app) {
q("delete from term where otype = %d and oid = %d",
intval(TERM_OBJ_APP),
intval($local_app[0]['id'])
);
q("delete from app where app_id = '%s' and app_channel = %d",
dbesc($app['app_id']),
intval($channel['channel_id'])
);
}
}
else {
q("update app set app_deleted = 1 where app_id = '%s' and app_channel = %d",
dbesc($app['app_id']),
intval($channel['channel_id'])
);
}
if (array_key_exists('app_deleted',$app) && $app['app_deleted'] == 1 && $app['app_id']) {
Apps::app_destroy($channel['channel_id'], ['guid' => $app['app_id']]);
}
else {
// install this app on this server