From 6d1b64065aa1f44e2b9d864ddba97891ca85d1e5 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Mon, 7 Sep 2015 18:14:30 -0700 Subject: consolidate import_items/sync_items --- include/import.php | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/photos.php | 3 --- include/zot.php | 6 +++++ 3 files changed, 83 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index 261219ce0..a81ade791 100644 --- a/include/import.php +++ b/include/import.php @@ -473,3 +473,80 @@ function sync_chatrooms($channel,$chatrooms) { } } } + + + +function import_items($channel,$items) { + + if($channel && $items) { + foreach($items as $i) { + $item = get_item_elements($i); + if(! $item) + continue; + + $r = q("select id, edited from item where mid = '%s' and uid = %d limit 1", + dbesc($item['mid']), + intval($channel['channel_id']) + ); + if($r) { + if($item['edited'] > $r[0]['edited']) { + $item['id'] = $r[0]['id']; + $item['uid'] = $channel['channel_id']; + item_store_update($item); + continue; + } + } + else { + $item['aid'] = $channel['channel_account_id']; + $item['uid'] = $channel['channel_id']; + $item_result = item_store($item); + } + + } + } +} + + +function sync_items($channel,$items) { + import_items($channel,$items); +} + + + +function import_item_ids($channel,$itemids) { + if($channel && $itemids) { + foreach($itemids as $i) { + $r = q("select id from item where mid = '%s' and uid = %d limit 1", + dbesc($i['mid']), + intval($channel['channel_id']) + ); + if(! $r) + continue; + $z = q("select * from item_id where service = '%s' and sid = '%s' and iid = %d and uid = %d limit 1", + dbesc($i['service']), + dbesc($i['sid']), + intval($r[0]['id']), + intval($channel['channel_id']) + ); + if(! $z) { + q("insert into item_id (iid,uid,sid,service) values(%d,%d,'%s','%s')", + intval($r[0]['id']), + intval($channel['channel_id']), + dbesc($i['sid']), + dbesc($i['service']) + ); + } + } + } +} + + + + + + + + + + + diff --git a/include/photos.php b/include/photos.php index 25818124a..49aab6865 100644 --- a/include/photos.php +++ b/include/photos.php @@ -226,11 +226,8 @@ function photo_upload($channel, $observer, $args) { $width_x_height = $ph->getWidth() . 'x' . $ph->getHeight(); - $mid = item_message_id(); - // Create item container - $item_hidden = (($visible) ? 0 : 1 ); $lat = $lon = null; diff --git a/include/zot.php b/include/zot.php index 9610df894..6f159b4f8 100644 --- a/include/zot.php +++ b/include/zot.php @@ -2884,6 +2884,12 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { if(array_key_exists('chatroom',$arr) && $arr['chatroom']) sync_apps($channel,$arr['chatroom']); + if(array_key_exists('item',$arr) && $arr['item']) + sync_items($channel,$arr['item']); + + if(array_key_exists('item_id',$arr) && $arr['item_id']) + sync_items($channel,$arr['item_id']); + 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'])) { $arr['channel']['channel_removed'] = (($arr['channel']['channel_pageflags'] & 0x8000) ? 1 : 0); -- cgit v1.2.3