diff options
author | zottel <github@zottel.net> | 2015-09-08 08:39:37 +0200 |
---|---|---|
committer | zottel <github@zottel.net> | 2015-09-08 08:39:37 +0200 |
commit | 52cd8652bb4b2454bc2bd49d8ec39a5549c4ab68 (patch) | |
tree | 8e25e4395d8ef7f0dbbe0f12450ad4b9d7cb20c0 /include/import.php | |
parent | c5981cbc9afb88015fb59b4743484bb78a87188d (diff) | |
parent | c6bdf7e891f3c0b49a1e9c40622e05aef590e2b6 (diff) | |
download | volse-hubzilla-52cd8652bb4b2454bc2bd49d8ec39a5549c4ab68.tar.gz volse-hubzilla-52cd8652bb4b2454bc2bd49d8ec39a5549c4ab68.tar.bz2 volse-hubzilla-52cd8652bb4b2454bc2bd49d8ec39a5549c4ab68.zip |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'include/import.php')
-rw-r--r-- | include/import.php | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/include/import.php b/include/import.php index 261219ce0..616ee4987 100644 --- a/include/import.php +++ b/include/import.php @@ -473,3 +473,155 @@ 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']) + ); + } + } + } +} + +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)) + . "')" + ); + } + } + } +} + + + + + + + + + + + |