1. provide automatic relocation of important links in items that are imported or synced to clones
2. provide framework for custom curl request bodies using custom/non-standard request methods. This was a real nightmare because curl doesn't actually let you specify a string to send as the request body (except when doing POST). You have to treat it as a file upload using a custom file handler function which provides the actual content in chunks as if it were buffered I/O. 3. item_store and item_store_update now return the item that was stored
This commit is contained in:
@@ -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;
|
||||
@@ -584,13 +584,6 @@ function import_items($channel,$items,$sync = false) {
|
||||
$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,19 +591,37 @@ 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']));
|
||||
}
|
||||
}
|
||||
if($relocate && $item_result['item_id']) {
|
||||
$item = $item_result['item'];
|
||||
if($item['mid'] === $item['parent_mid']) {
|
||||
item_url_replace($channel,$item,$relocate['url'],z_root(),$relocate['channel_address']);
|
||||
dbesc_array($item);
|
||||
$item_id = $item_result['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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function sync_items($channel,$items) {
|
||||
import_items($channel,$items,true);
|
||||
function sync_items($channel,$items,$relocate = null) {
|
||||
import_items($channel,$items,true,$relocate);
|
||||
}
|
||||
|
||||
|
||||
@@ -1200,31 +1211,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]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user