work on event sync

This commit is contained in:
redmatrix 2015-09-07 21:01:49 -07:00
parent 508969a183
commit 650e98b2a9
3 changed files with 89 additions and 1 deletions

View File

@ -540,6 +540,81 @@ function import_item_ids($channel,$itemids) {
}
}
function import_events($channel,$events) {
if($channel && $events) {
foreach($events as $event) {
unset($event['id']);
$event['aid'] = $channel['channel_account_id'];
$event['uid'] = $channel['channel_id'];
dbesc_array($event);
$r = dbq("INSERT INTO event (`"
. implode("`, `", array_keys($event))
. "`) VALUES ('"
. implode("', '", array_values($event))
. "')"
);
}
}
}
function sync_events($channel,$events) {
if($channel && $events) {
foreach($events as $event) {
if((! $event['event_hash']) || (! $event['start']))
continue;
if($event['event_deleted']) {
$r = q("delete from event where event_hash = '%s' and uid = %d limit 1",
dbesc($event['event_hash']),
intval($channel['channel_id'])
);
continue;
}
unset($event['id']);
$event['aid'] = $channel['channel_account_id'];
$event['uid'] = $channel['channel_id'];
$exists = false;
$x = q("select * from event where event_hash = '%s' and uid = %d limit 1",
dbesc($event['event_hash']),
intval($channel['channel_id'])
);
if($x) {
if($x[0]['edited'] >= $event['edited'])
continue;
$exists = true;
}
if($exists) {
foreach($event as $k => $v) {
$r = q("UPDATE event SET `%s` = '%s' WHERE event_hash = '%s' AND uid = %d",
dbesc($k),
dbesc($v),
dbesc($event['event_hash']),
intval($channel['channel_id'])
);
}
}
else {
dbesc_array($event);
$r = dbq("INSERT INTO event (`"
. implode("`, `", array_keys($event))
. "`) VALUES ('"
. implode("', '", array_values($event))
. "')"
);
}
}
}
}

View File

@ -2882,7 +2882,13 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
sync_apps($channel,$arr['app']);
if(array_key_exists('chatroom',$arr) && $arr['chatroom'])
sync_apps($channel,$arr['chatroom']);
sync_chatrooms($channel,$arr['chatroom']);
if(array_key_exists('event',$arr) && $arr['event'])
sync_events($channel,$arr['event']);
if(array_key_exists('event_item',$arr) && $arr['event_item'])
sync_items($channel,$arr['event_item']);
if(array_key_exists('item',$arr) && $arr['item'])
sync_items($channel,$arr['item']);

View File

@ -438,6 +438,13 @@ function import_post(&$a) {
if(is_array($data['chatroom']))
import_chatrooms($channel,$data['chatroom']);
if(is_array($data['event']))
import_events($channel,$data['event']);
if(is_array($data['event_item']))
import_items($channel,$data['event_item']);
$saved_notification_flags = notifications_off($channel['channel_id']);
if($import_posts && array_key_exists('item',$data) && $data['item'])