mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-19 21:55:15 +00:00
app sync
This commit is contained in:
parent
fb2d2c5585
commit
f3cb17ac3b
3 changed files with 91 additions and 2 deletions
|
@ -264,18 +264,37 @@ function app_install($uid,$app) {
|
|||
else
|
||||
$x = app_store($app);
|
||||
|
||||
if($x['success'])
|
||||
return $x['app_id'];
|
||||
if($x['success']) {
|
||||
$r = q("select * from app where app_id = '%s' and app_channel = %d limit 1",
|
||||
dbesc($x['app_id']),
|
||||
intval($uid)
|
||||
);
|
||||
if($r)
|
||||
build_sync_packet($uid,array('app' => $r[0]));
|
||||
|
||||
return $x['app_id'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function app_destroy($uid,$app) {
|
||||
|
||||
|
||||
if($uid && $app['guid']) {
|
||||
|
||||
$x = q("select * from app where app_id = '%s' and app_channel = %d limit 1",
|
||||
dbesc($app['guid']),
|
||||
intval($uid)
|
||||
);
|
||||
$x[0]['app_deleted'] = 1;
|
||||
|
||||
|
||||
$r = q("delete from app where app_id = '%s' and app_channel = %d",
|
||||
dbesc($app['guid']),
|
||||
intval($uid)
|
||||
);
|
||||
|
||||
build_sync_packet($uid,array('app' => $x));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -257,6 +257,7 @@ function sync_objs($channel,$objs) {
|
|||
$hash = $obj['obj_obj'];
|
||||
|
||||
if($exists) {
|
||||
unset($obj['obj_obj']);
|
||||
foreach($obj as $k => $v) {
|
||||
$r = q("UPDATE obj SET `%s` = '%s' WHERE obj_obj = '%s' AND obj_channel = %d",
|
||||
dbesc($k),
|
||||
|
@ -309,4 +310,71 @@ function import_apps($channel,$apps) {
|
|||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function sync_apps($channel,$apps) {
|
||||
|
||||
if($channel && $apps) {
|
||||
foreach($apps as $app) {
|
||||
|
||||
if(array_key_exists('app_deleted',$app) && $app['app_deleted'] && $app['app_id']) {
|
||||
q("delete from app where app_id = '%s' and app_channel = %d limit 1",
|
||||
dbesc($app['app_id']),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
unset($app['id']);
|
||||
unset($app['app_channel']);
|
||||
|
||||
if(! $app['app_created'] || $app['app_created'] === NULL_DATE)
|
||||
$app['app_created'] = datetime_convert();
|
||||
if(! $app['app_edited'] || $app['app_edited'] === NULL_DATE)
|
||||
$app['app_edited'] = datetime_convert();
|
||||
|
||||
$app['app_channel'] = $channel['channel_id'];
|
||||
|
||||
if($app['app_photo']) {
|
||||
$x = import_xchan_photo($app['app_photo'],$channel['channel_hash'],true);
|
||||
$app['app_photo'] = $x[0];
|
||||
}
|
||||
|
||||
$exists = false;
|
||||
|
||||
$x = q("select * from app where app_id = '%s' and app_channel = %d limit 1",
|
||||
dbesc($app['app_id']),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
if($x) {
|
||||
if($x[0]['app_edited'] >= $obj['app_edited'])
|
||||
continue;
|
||||
$exists = true;
|
||||
}
|
||||
$hash = $app['app_id'];
|
||||
|
||||
if($exists) {
|
||||
unset($app['app_id']);
|
||||
foreach($app as $k => $v) {
|
||||
$r = q("UPDATE app SET `%s` = '%s' WHERE app_id = '%s' AND app_channel = %d",
|
||||
dbesc($k),
|
||||
dbesc($v),
|
||||
dbesc($hash),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
dbesc_array($app);
|
||||
$r = dbq("INSERT INTO app (`"
|
||||
. implode("`, `", array_keys($app))
|
||||
. "`) VALUES ('"
|
||||
. implode("', '", array_values($app))
|
||||
. "')"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2878,6 +2878,8 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
|
|||
if(array_key_exists('obj',$arr) && $arr['obj'])
|
||||
sync_objs($channel,$arr['obj']);
|
||||
|
||||
if(array_key_exists('app',$arr) && $arr['app'])
|
||||
sync_apps($channel,$arr['app']);
|
||||
|
||||
if(array_key_exists('channel',$arr) && is_array($arr['channel']) && count($arr['channel'])) {
|
||||
if(array_key_exists('channel_page_flags',$arr['channel']) && intval($arr['channel']['channel_pageflags'])) {
|
||||
|
|
Loading…
Reference in a new issue