consolidate import_items/sync_items
This commit is contained in:
parent
2f52b6c164
commit
6d1b64065a
@ -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'])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -226,11 +226,8 @@ function photo_upload($channel, $observer, $args) {
|
|||||||
|
|
||||||
$width_x_height = $ph->getWidth() . 'x' . $ph->getHeight();
|
$width_x_height = $ph->getWidth() . 'x' . $ph->getHeight();
|
||||||
|
|
||||||
$mid = item_message_id();
|
|
||||||
|
|
||||||
// Create item container
|
// Create item container
|
||||||
|
|
||||||
|
|
||||||
$item_hidden = (($visible) ? 0 : 1 );
|
$item_hidden = (($visible) ? 0 : 1 );
|
||||||
|
|
||||||
$lat = $lon = null;
|
$lat = $lon = null;
|
||||||
|
@ -2884,6 +2884,12 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
|
|||||||
if(array_key_exists('chatroom',$arr) && $arr['chatroom'])
|
if(array_key_exists('chatroom',$arr) && $arr['chatroom'])
|
||||||
sync_apps($channel,$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',$arr) && is_array($arr['channel']) && count($arr['channel'])) {
|
||||||
if(array_key_exists('channel_page_flags',$arr['channel']) && intval($arr['channel']['channel_pageflags'])) {
|
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);
|
$arr['channel']['channel_removed'] = (($arr['channel']['channel_pageflags'] & 0x8000) ? 1 : 0);
|
||||||
|
@ -440,60 +440,14 @@ function import_post(&$a) {
|
|||||||
|
|
||||||
$saved_notification_flags = notifications_off($channel['channel_id']);
|
$saved_notification_flags = notifications_off($channel['channel_id']);
|
||||||
|
|
||||||
if($import_posts && array_key_exists('item',$data) && $data['item']) {
|
if($import_posts && array_key_exists('item',$data) && $data['item'])
|
||||||
|
import_items($channel,$data['item']);
|
||||||
foreach($data['item'] as $i) {
|
|
||||||
$item = get_item_elements($i);
|
|
||||||
|
|
||||||
$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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
notifications_on($channel['channel_id'],$saved_notification_flags);
|
notifications_on($channel['channel_id'],$saved_notification_flags);
|
||||||
|
|
||||||
if(array_key_exists('item_id',$data) && $data['item_id']) {
|
|
||||||
foreach($data['item_id'] 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'])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if(array_key_exists('item_id',$data) && $data['item_id'])
|
||||||
|
import_item_ids($channel,$data['item_id']);
|
||||||
|
|
||||||
|
|
||||||
// FIXME - ensure we have a self entry if somebody is trying to pull a fast one
|
// FIXME - ensure we have a self entry if somebody is trying to pull a fast one
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
require_once('include/import.php');
|
||||||
|
|
||||||
function import_items_post(&$a) {
|
function import_items_post(&$a) {
|
||||||
|
|
||||||
@ -88,57 +89,13 @@ function import_items_post(&$a) {
|
|||||||
$saved_notification_flags = notifications_off($channel['channel_id']);
|
$saved_notification_flags = notifications_off($channel['channel_id']);
|
||||||
|
|
||||||
if(array_key_exists('item',$data) && $data['item']) {
|
if(array_key_exists('item',$data) && $data['item']) {
|
||||||
|
import_items($channel,$data['item']);
|
||||||
foreach($data['item'] as $i) {
|
|
||||||
$item = get_item_elements($i);
|
|
||||||
|
|
||||||
$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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
notifications_on($channel['channel_id'],$saved_notification_flags);
|
notifications_on($channel['channel_id'],$saved_notification_flags);
|
||||||
|
|
||||||
if(array_key_exists('item_id',$data) && $data['item_id']) {
|
if(array_key_exists('item_id',$data) && $data['item_id']) {
|
||||||
foreach($data['item_id'] as $i) {
|
import_item_ids($channel,$data['item_id']);
|
||||||
$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'])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
info( t('Import completed') . EOL);
|
info( t('Import completed') . EOL);
|
||||||
|
25
mod/item.php
25
mod/item.php
@ -884,14 +884,28 @@ function item_post(&$a) {
|
|||||||
// NOTREACHED
|
// NOTREACHED
|
||||||
}
|
}
|
||||||
|
|
||||||
if($parent) {
|
|
||||||
|
update_remote_id($channel,$post_id,$webpage,$pagetitle,$namespace,$remote_id,$mid);
|
||||||
|
|
||||||
|
if(($parent) && ($parent != $post_id)) {
|
||||||
// Store the comment signature information in case we need to relay to Diaspora
|
// Store the comment signature information in case we need to relay to Diaspora
|
||||||
$ditem = $datarray;
|
$ditem = $datarray;
|
||||||
$ditem['author'] = $observer;
|
$ditem['author'] = $observer;
|
||||||
store_diaspora_comment_sig($ditem,$channel,$parent_item, $post_id, (($walltowall_comment) ? 1 : 0));
|
store_diaspora_comment_sig($ditem,$channel,$parent_item, $post_id, (($walltowall_comment) ? 1 : 0));
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
update_remote_id($channel,$post_id,$webpage,$pagetitle,$namespace,$remote_id,$mid);
|
$r = q("select * from item where id = %d",
|
||||||
|
intval($post_id)
|
||||||
|
);
|
||||||
|
if($r) {
|
||||||
|
xchan_query($r);
|
||||||
|
$sync_item = fetch_post_tags($r);
|
||||||
|
$rid = q("select * from item_id where iid = %d",
|
||||||
|
intval($post_id)
|
||||||
|
);
|
||||||
|
build_sync_packet($uid,array('item' => array(encode_item($sync_item[0],true)),'item_id' => $rid));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$datarray['id'] = $post_id;
|
$datarray['id'] = $post_id;
|
||||||
$datarray['llink'] = $a->get_baseurl() . '/display/' . $channel['channel_address'] . '/' . $post_id;
|
$datarray['llink'] = $a->get_baseurl() . '/display/' . $channel['channel_address'] . '/' . $post_id;
|
||||||
@ -903,6 +917,11 @@ function item_post(&$a) {
|
|||||||
|
|
||||||
logger('post_complete');
|
logger('post_complete');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// figure out how to return, depending on from whence we came
|
// figure out how to return, depending on from whence we came
|
||||||
|
|
||||||
if($api_source)
|
if($api_source)
|
||||||
|
Reference in New Issue
Block a user