aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorredmatrix <redmatrix@redmatrix.me>2015-09-02 23:09:51 -0700
committerredmatrix <redmatrix@redmatrix.me>2015-09-02 23:09:51 -0700
commitf3cb17ac3b007afd2dc5bf7cdad8a054b4d7fcd8 (patch)
tree92dd58c4e5a1881b01acb414ea1d218d77ef4721 /include
parentfb2d2c55851ce14fd0bd04b15be0518a86809b41 (diff)
downloadvolse-hubzilla-f3cb17ac3b007afd2dc5bf7cdad8a054b4d7fcd8.tar.gz
volse-hubzilla-f3cb17ac3b007afd2dc5bf7cdad8a054b4d7fcd8.tar.bz2
volse-hubzilla-f3cb17ac3b007afd2dc5bf7cdad8a054b4d7fcd8.zip
app sync
Diffstat (limited to 'include')
-rw-r--r--include/apps.php23
-rw-r--r--include/import.php68
-rw-r--r--include/zot.php2
3 files changed, 91 insertions, 2 deletions
diff --git a/include/apps.php b/include/apps.php
index 3d480d901..661fc2163 100644
--- a/include/apps.php
+++ b/include/apps.php
@@ -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));
}
}
diff --git a/include/import.php b/include/import.php
index cee0d14fd..6ce572ea2 100644
--- a/include/import.php
+++ b/include/import.php
@@ -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))
+ . "')"
+ );
+ }
+ }
+ }
} \ No newline at end of file
diff --git a/include/zot.php b/include/zot.php
index cb70f38a2..fecaa7ad2 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -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'])) {