1
0
Fork 0

Simplify event storing

This commit is contained in:
Michael 2021-08-10 10:24:14 +00:00
parent 536fbe5af1
commit 8e074a5fe4
4 changed files with 30 additions and 6 deletions

View file

@ -337,12 +337,12 @@ class Event
public static function getItemArrayForId(int $event_id, array $item = []):array public static function getItemArrayForId(int $event_id, array $item = []):array
{ {
if (empty($event_id)) { if (empty($event_id)) {
return []; return $item;
} }
$event = DBA::selectFirst('event', [], ['id' => $event_id]); $event = DBA::selectFirst('event', [], ['id' => $event_id]);
if ($event['type'] != 'event') { if ($event['type'] != 'event') {
return []; return $item;
} }
if ($event['cid']) { if ($event['cid']) {
@ -375,7 +375,7 @@ class Event
$item['allow_gid'] = $event['allow_gid']; $item['allow_gid'] = $event['allow_gid'];
$item['deny_cid'] = $event['deny_cid']; $item['deny_cid'] = $event['deny_cid'];
$item['deny_gid'] = $event['deny_gid']; $item['deny_gid'] = $event['deny_gid'];
$item['private'] = intval($event['private'] ?? 0);; $item['private'] = intval($event['private'] ?? 0);
$item['visible'] = 1; $item['visible'] = 1;
$item['verb'] = Activity::POST; $item['verb'] = Activity::POST;
$item['object-type'] = Activity\ObjectType::EVENT; $item['object-type'] = Activity\ObjectType::EVENT;
@ -391,6 +391,30 @@ class Event
return $item; return $item;
} }
public static function getItemArrayForImportedId(int $event_id, array $item = []):array
{
if (empty($event_id)) {
return $item;
}
$event = DBA::selectFirst('event', [], ['id' => $event_id]);
if ($event['type'] != 'event') {
return $item;
}
$item['post-type'] = Item::PT_EVENT;
$item['title'] = '';
$item['object-type'] = Activity\ObjectType::EVENT;
$item['body'] = self::getBBCode($event);
$item['event-id'] = $event_id;
$item['object'] = '<object><type>' . XML::escape(Activity\ObjectType::EVENT) . '</type><title></title><id>' . XML::escape($event['uri']) . '</id>';
$item['object'] .= '<content>' . XML::escape(self::getBBCode($event)) . '</content>';
$item['object'] .= '</object>' . "\n";
return $item;
}
/** /**
* Create an array with translation strings used for events. * Create an array with translation strings used for events.
* *

View file

@ -1039,7 +1039,7 @@ class Item
} }
$event_id = Event::store($ev); $event_id = Event::store($ev);
$item = Event::getItemArrayForId($event_id, $item); $item = Event::getItemArrayForImportedId($event_id, $item);
Logger::info('Event was stored', ['id' => $event_id]); Logger::info('Event was stored', ['id' => $event_id]);
} }

View file

@ -631,7 +631,7 @@ class Processor
if (($item['gravity'] != GRAVITY_ACTIVITY) && ($activity['object_type'] == 'as:Event')) { if (($item['gravity'] != GRAVITY_ACTIVITY) && ($activity['object_type'] == 'as:Event')) {
$event_id = self::createEvent($activity, $item); $event_id = self::createEvent($activity, $item);
$item = Event::getItemArrayForId($event_id, $item); $item = Event::getItemArrayForImportedId($event_id, $item);
} }
$item_id = Item::insert($item); $item_id = Item::insert($item);

View file

@ -1978,7 +1978,7 @@ class DFRN
$event_id = Event::store($ev); $event_id = Event::store($ev);
Logger::info('Event was stored', ['id' => $event_id]); Logger::info('Event was stored', ['id' => $event_id]);
$item = Event::getItemArrayForId($event_id, $item); $item = Event::getItemArrayForImportedId($event_id, $item);
} }
} }
} }