more work on new event code

This commit is contained in:
friendica 2014-05-29 19:48:54 -07:00
parent dac7f68914
commit 6e0cc25a90

View File

@ -129,6 +129,12 @@ function ev_compare($a,$b) {
function event_store_event($arr) { function event_store_event($arr) {
$arr['created'] = (($arr['created']) ? $arr['created'] : datetime_convert());
$arr['edited'] = (($arr['edited']) ? $arr['edited'] : datetime_convert());
$arr['type'] = (($arr['type']) ? $arr['type'] : 'event' );
$arr['event_xchan'] = (($arr['event_xchan']) ? $arr['event_xchan'] : '');
// Existing event being modified // Existing event being modified
if($arr['id'] || $arr['event_hash']) { if($arr['id'] || $arr['event_hash']) {
@ -297,11 +303,6 @@ function event_store_item($arr,$event) {
$a = get_app(); $a = get_app();
$arr['created'] = (($arr['created']) ? $arr['created'] : datetime_convert());
$arr['edited'] = (($arr['edited']) ? $arr['edited'] : datetime_convert());
$arr['type'] = (($arr['type']) ? $arr['type'] : 'event' );
$arr['event_xchan'] = (($arr['event_xchan']) ? $arr['event_xchan'] : '');
$item = null; $item = null;
if($arr['mid'] && $arr['uid']) { if($arr['mid'] && $arr['uid']) {
@ -316,12 +317,11 @@ function event_store_item($arr,$event) {
} }
$r = q("SELECT * FROM item left join xchan on author_xchan = xchan_hash WHERE resource_id = '%s' AND resource_type = 'event' and uid = %d LIMIT 1", $r = q("SELECT * FROM item left join xchan on author_xchan = xchan_hash WHERE resource_id = '%s' AND resource_type = 'event' and uid = %d LIMIT 1",
dbesc($event_hash), dbesc($event['hash']),
intval($arr['uid']) intval($arr['uid'])
); );
if($r) { if($r) {
$obj = json_encode(array( $obj = json_encode(array(
'type' => ACTIVITY_OBJ_EVENT, 'type' => ACTIVITY_OBJ_EVENT,
'id' => z_root() . '/event/' . $r[0]['resource_id'], 'id' => z_root() . '/event/' . $r[0]['resource_id'],
@ -357,19 +357,13 @@ function event_store_item($arr,$event) {
); );
$item_id = $r[0]['id']; $item_id = $r[0]['id'];
} call_hooks('event_updated', $event['id']);
else
$item_id = 0;
call_hooks('event_updated', $arr['id']);
dbg(0);
return $item_id; return $item_id;
} }
else { else {
$z = q("select * from channel where channel_hash = '%s' and channel_id = %d limit 1", $z = q("select * from channel where channel_hash = '%s' and channel_id = %d limit 1",
dbesc($arr['event_xchan']), dbesc($event['event_xchan']),
intval($arr['uid']) intval($arr['uid'])
); );
@ -378,8 +372,6 @@ dbg(0);
$item_arr = array(); $item_arr = array();
if($item) { if($item) {
$item_arr['id'] = $item['id']; $item_arr['id'] = $item['id'];
} }
@ -440,16 +432,12 @@ dbg(0);
)); ));
} }
if($item)
$res = item_store_update($item_arr);
else
$res = item_store($item_arr); $res = item_store($item_arr);
$item_id = $res['item_id']; $item_id = $res['item_id'];
call_hooks("event_created", $event['id']); call_hooks("event_created", $event['id']);
dbg(0);
return $item_id; return $item_id;
} }
} }