aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzottel <github@zottel.net>2015-09-08 08:39:37 +0200
committerzottel <github@zottel.net>2015-09-08 08:39:37 +0200
commit52cd8652bb4b2454bc2bd49d8ec39a5549c4ab68 (patch)
tree8e25e4395d8ef7f0dbbe0f12450ad4b9d7cb20c0
parentc5981cbc9afb88015fb59b4743484bb78a87188d (diff)
parentc6bdf7e891f3c0b49a1e9c40622e05aef590e2b6 (diff)
downloadvolse-hubzilla-52cd8652bb4b2454bc2bd49d8ec39a5549c4ab68.tar.gz
volse-hubzilla-52cd8652bb4b2454bc2bd49d8ec39a5549c4ab68.tar.bz2
volse-hubzilla-52cd8652bb4b2454bc2bd49d8ec39a5549c4ab68.zip
Merge remote-tracking branch 'upstream/master'
-rw-r--r--include/event.php16
-rw-r--r--include/identity.php19
-rw-r--r--include/import.php152
-rwxr-xr-xinclude/items.php10
-rw-r--r--include/photos.php3
-rw-r--r--include/zot.php14
-rwxr-xr-xmod/events.php23
-rw-r--r--mod/import.php59
-rw-r--r--mod/import_items.php49
-rw-r--r--mod/item.php38
10 files changed, 276 insertions, 107 deletions
diff --git a/include/event.php b/include/event.php
index 6670bc53b..44c172e98 100644
--- a/include/event.php
+++ b/include/event.php
@@ -446,6 +446,20 @@ function event_addtocal($item_id, $uid) {
intval($channel['channel_id'])
);
+ $item['resource_id'] = $event['event_hash'];
+ $item['resource_type'] = 'event';
+
+ $i = array($item);
+ xchan_query($i);
+ $sync_item = fetch_post_tags($i);
+ $z = q("select * from event where event_hash = '%s' and uid = %d limit 1",
+ dbesc($event['event_hash']),
+ intval($channel['channel_id'])
+ );
+ if($z) {
+ build_sync_packet($channel['channel_id'],array('event_item' => array(encode_item($sync_item[0],true)),'event' => $z));
+ }
+
return true;
}
}
@@ -959,4 +973,4 @@ function tasks_fetch($arr) {
return $ret;
-} \ No newline at end of file
+}
diff --git a/include/identity.php b/include/identity.php
index 393378cc4..211832d51 100644
--- a/include/identity.php
+++ b/include/identity.php
@@ -578,6 +578,25 @@ function identity_basic_export($channel_id, $items = false) {
if($r)
$ret['chatroom'] = $r;
+
+ $r = q("select * from event where uid = %d",
+ intval($channel_id)
+ );
+ if($r)
+ $ret['event'] = $r;
+
+ $r = q("select * from item where resource_type = 'event' and uid = %d",
+ intval($channel_id)
+ );
+ if($r) {
+ $ret['event_item'] = array();
+ xchan_query($r);
+ $r = fetch_post_tags($r,true);
+ foreach($r as $rr)
+ $ret['event_item'][] = encode_item($rr,true);
+ }
+
+
if(! $items)
return $ret;
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))
+ . "')"
+ );
+ }
+ }
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/include/items.php b/include/items.php
index 91afad0e6..5d38b0982 100755
--- a/include/items.php
+++ b/include/items.php
@@ -4632,10 +4632,12 @@ function zot_feed($uid,$observer_hash,$arr) {
$items = array();
- /** @FIXME fix this part for PostgreSQL */
+ /** @FIXME re-unite these SQL statements. There is no need for them to be separate. The mySQL is convoluted with misuse of group by. As it stands, there is a slight difference where the postgres version doesn't remove the duplicate parents up to 100. In practice this doesn't matter. It could be made to match behavior by adding "distinct on (parent) " to the front of the selection list, at a not-worth-it performance penalty (page temp results to disk). duplicates are still ignored in the in() clause, you just get less than 100 parents if there are many children. */
if(ACTIVE_DBTYPE == DBTYPE_POSTGRES) {
- return array();
+ $groupby = '';
+ } else {
+ $groupby = 'GROUP BY parent';
}
$item_normal = item_normal();
@@ -4645,7 +4647,7 @@ function zot_feed($uid,$observer_hash,$arr) {
WHERE uid != %d
$item_normal
AND item_wall = 1
- and item_private = 0 $sql_extra GROUP BY parent ORDER BY created ASC $limit",
+ and item_private = 0 $sql_extra $groupby ORDER BY created ASC $limit",
intval($uid)
);
}
@@ -4653,7 +4655,7 @@ function zot_feed($uid,$observer_hash,$arr) {
$r = q("SELECT parent, created, postopts from item
WHERE uid = %d $item_normal
AND item_wall = 1
- $sql_extra GROUP BY parent ORDER BY created ASC $limit",
+ $sql_extra $groupby ORDER BY created ASC $limit",
intval($uid)
);
}
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..285668209 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -2882,7 +2882,19 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
sync_apps($channel,$arr['app']);
if(array_key_exists('chatroom',$arr) && $arr['chatroom'])
- sync_apps($channel,$arr['chatroom']);
+ sync_chatrooms($channel,$arr['chatroom']);
+
+ if(array_key_exists('event',$arr) && $arr['event'])
+ sync_events($channel,$arr['event']);
+
+ if(array_key_exists('event_item',$arr) && $arr['event_item'])
+ sync_items($channel,$arr['event_item']);
+
+ 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'])) {
diff --git a/mod/events.php b/mod/events.php
index 9120f8713..d76602a33 100755
--- a/mod/events.php
+++ b/mod/events.php
@@ -205,6 +205,23 @@ function events_post(&$a) {
$item_id = event_store_item($datarray,$event);
+ if($item_id) {
+ $r = q("select * from item where id = %d",
+ intval($item_id)
+ );
+ if($r) {
+ xchan_query($r);
+ $sync_item = fetch_post_tags($r);
+ $z = q("select * from event where event_hash = '%s' and uid = %d limit 1",
+ dbesc($r[0]['resource_id']),
+ intval($channel['channel_id'])
+ );
+ if($z) {
+ build_sync_packet($channel['channel_id'],array('event_item' => array(encode_item($sync_item[0],true)),'event' => $z));
+ }
+ }
+ }
+
if($share)
proc_run('php',"include/notifier.php","event","$item_id");
@@ -528,6 +545,9 @@ function events_content(&$a) {
dbesc($event_id),
intval(local_channel())
);
+
+ $sync_event = $r[0];
+
if($r) {
$r = q("delete from event where event_hash = '%s' and uid = %d limit 1",
dbesc($event_id),
@@ -538,6 +558,9 @@ function events_content(&$a) {
dbesc($event_id),
intval(local_channel())
);
+ $sync_event['event_deleted'] = 1;
+ build_sync_packet(0,array('event' => array($sync_event)));
+
info( t('Event removed') . EOL);
}
else {
diff --git a/mod/import.php b/mod/import.php
index 1d1799e00..27c2094c3 100644
--- a/mod/import.php
+++ b/mod/import.php
@@ -438,62 +438,23 @@ function import_post(&$a) {
if(is_array($data['chatroom']))
import_chatrooms($channel,$data['chatroom']);
- $saved_notification_flags = notifications_off($channel['channel_id']);
-
- if($import_posts && array_key_exists('item',$data) && $data['item']) {
-
- foreach($data['item'] as $i) {
- $item = get_item_elements($i);
+ if(is_array($data['event']))
+ import_events($channel,$data['event']);
- $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);
- }
+ if(is_array($data['event_item']))
+ import_items($channel,$data['event_item']);
+
- }
+ $saved_notification_flags = notifications_off($channel['channel_id']);
- }
+ if($import_posts && array_key_exists('item',$data) && $data['item'])
+ import_items($channel,$data['item']);
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
diff --git a/mod/import_items.php b/mod/import_items.php
index 1e54c0deb..6b97939c9 100644
--- a/mod/import_items.php
+++ b/mod/import_items.php
@@ -1,5 +1,6 @@
<?php
+require_once('include/import.php');
function import_items_post(&$a) {
@@ -88,57 +89,13 @@ function import_items_post(&$a) {
$saved_notification_flags = notifications_off($channel['channel_id']);
if(array_key_exists('item',$data) && $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);
- }
-
- }
-
+ import_items($channel,$data['item']);
}
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'])
- );
- }
- }
+ import_item_ids($channel,$data['item_id']);
}
info( t('Import completed') . EOL);
diff --git a/mod/item.php b/mod/item.php
index c93560771..d0cf59091 100644
--- a/mod/item.php
+++ b/mod/item.php
@@ -805,6 +805,19 @@ function item_post(&$a) {
update_remote_id($channel,$post_id,$webpage,$pagetitle,$namespace,$remote_id,$mid);
+ if(! $parent) {
+ $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));
+ }
+ }
if(! $nopush)
proc_run('php', "include/notifier.php", 'edit_post', $post_id);
@@ -884,14 +897,28 @@ function item_post(&$a) {
// 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
$ditem = $datarray;
$ditem['author'] = $observer;
store_diaspora_comment_sig($ditem,$channel,$parent_item, $post_id, (($walltowall_comment) ? 1 : 0));
}
-
- update_remote_id($channel,$post_id,$webpage,$pagetitle,$namespace,$remote_id,$mid);
+ else {
+ $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['llink'] = $a->get_baseurl() . '/display/' . $channel['channel_address'] . '/' . $post_id;
@@ -903,6 +930,11 @@ function item_post(&$a) {
logger('post_complete');
+
+
+
+
+
// figure out how to return, depending on from whence we came
if($api_source)