Merge pull request #10592 from annando/event

Simplify event storing
This commit is contained in:
Hypolite Petovan 2021-08-10 09:00:41 -04:00 committed by GitHub
commit 56ee1a211f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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
{
if (empty($event_id)) {
return [];
return $item;
}
$event = DBA::selectFirst('event', [], ['id' => $event_id]);
if ($event['type'] != 'event') {
return [];
return $item;
}
if ($event['cid']) {
@ -375,7 +375,7 @@ class Event
$item['allow_gid'] = $event['allow_gid'];
$item['deny_cid'] = $event['deny_cid'];
$item['deny_gid'] = $event['deny_gid'];
$item['private'] = intval($event['private'] ?? 0);;
$item['private'] = intval($event['private'] ?? 0);
$item['visible'] = 1;
$item['verb'] = Activity::POST;
$item['object-type'] = Activity\ObjectType::EVENT;
@ -391,6 +391,30 @@ class Event
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.
*

View file

@ -1039,7 +1039,7 @@ class Item
}
$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]);
}

View file

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

View file

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