diff options
Diffstat (limited to 'include/import.php')
-rw-r--r-- | include/import.php | 69 |
1 files changed, 22 insertions, 47 deletions
diff --git a/include/import.php b/include/import.php index be456bfa9..889b50eb1 100644 --- a/include/import.php +++ b/include/import.php @@ -553,7 +553,7 @@ function sync_chatrooms($channel,$chatrooms) { -function import_items($channel,$items,$sync = false) { +function import_items($channel,$items,$sync = false,$relocate = null) { if($channel && $items) { $allow_code = false; @@ -575,22 +575,23 @@ function import_items($channel,$items,$sync = false) { if(! $item) continue; + if($relocate && $item['mid'] === $item['parent_mid']) { + item_url_replace($channel,$item,$relocate['url'],z_root(),$relocate['channel_address']); + } + $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']) { + + // flags may have changed and we are probably relocating the post, + // so force an update even if we have the same timestamp + + if($item['edited'] >= $r[0]['edited']) { $item['id'] = $r[0]['id']; $item['uid'] = $channel['channel_id']; $item_result = item_store_update($item,$allow_code,$deliver); - if($sync && $item['item_wall']) { - // deliver singletons if we have any - if($item_result && $item_result['success']) { - Zotlabs\Daemon\Master::Summon(array('Notifier','single_activity',$item_result['item_id'])); - } - } - continue; } } else { @@ -598,10 +599,11 @@ function import_items($channel,$items,$sync = false) { $item['uid'] = $channel['channel_id']; $item_result = item_store($item,$allow_code,$deliver); } + if($sync && $item['item_wall']) { // deliver singletons if we have any if($item_result && $item_result['success']) { - Zotlabs\Daemon\Master::Summon(array('Notifier','single_activity',$item_result['item_id'])); + Zotlabs\Daemon\Master::Summon( [ 'Notifier','single_activity',$item_result['item_id'] ]); } } } @@ -609,8 +611,8 @@ function import_items($channel,$items,$sync = false) { } -function sync_items($channel,$items) { - import_items($channel,$items,true); +function sync_items($channel,$items,$relocate = null) { + import_items($channel,$items,true,$relocate); } @@ -624,19 +626,14 @@ function import_item_ids($channel,$itemids) { ); if(! $r) continue; - $z = q("select * from item_id where service = '%s' and sid = '%s' and iid = %d and uid = %d limit 1", + $z = q("select * from iconfig where iconfig.cat = 'system' and iconfig.k = '%s' + and iconfig.v = '%s' and iid = %d limit 1", dbesc($i['service']), dbesc($i['sid']), - intval($r[0]['id']), - intval($channel['channel_id']) + intval($r[0]['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']) - ); + \Zotlabs\Lib\IConfig::Set($r[0]['id'],'system',$i['service'],$i['sid'],true); } } } @@ -1007,7 +1004,7 @@ function sync_files($channel,$files) { $attach_id = $x[0]['id']; } - $newfname = 'store/' . $channel['channel_address'] . '/' . get_attach_binname($att['data']); + $newfname = 'store/' . $channel['channel_address'] . '/' . get_attach_binname($att['content']); unset($att['id']); $att['aid'] = $channel['channel_account_id']; @@ -1205,31 +1202,9 @@ function sync_files($channel,$files) { } } if($f['item']) { - sync_items($channel,$f['item']); - foreach($f['item'] as $i) { - if($i['message_id'] !== $i['message_parent']) - continue; - $r = q("select * from item where mid = '%s' and uid = %d limit 1", - dbesc($i['message_id']), - intval($channel['channel_id']) - ); - if($r) { - $item = $r[0]; - item_url_replace($channel,$item,$oldbase,z_root(),$original_channel); - - dbesc_array($item); - $item_id = $item['id']; - unset($item['id']); - $str = ''; - foreach($item as $k => $v) { - if($str) - $str .= ","; - $str .= " `" . $k . "` = '" . $v . "' "; - } - - $r = dbq("update `item` set " . $str . " where id = " . $item_id ); - } - } + sync_items($channel,$f['item'], + ['channel_address' => $original_channel,'url' => $oldbase] + ); } } } |