Events are now saved but not displayed properly again

This commit is contained in:
Mikael Nordfeldth 2016-01-18 20:57:44 +01:00
parent 6c46a93a81
commit cae344b67b
4 changed files with 89 additions and 137 deletions

View File

@ -182,17 +182,6 @@ abstract class ActivityHandlerPlugin extends Plugin
return true; return true;
} }
$object = $this->saveObjectFromActivity($act, $stored, $options); $object = $this->saveObjectFromActivity($act, $stored, $options);
try {
// In the future we probably want to use something like ActivityVerb_DataObject for the kind
// of objects which are returned from saveObjectFromActivity.
if ($object instanceof Managed_DataObject) {
// If the verb handling plugin figured out some more attention URIs, add them here to the
// original activity. This is only done if a separate object is actually needed to be saved.
$act->context->attention = array_merge($act->context->attention, $object->getAttentionArray());
}
} catch (Exception $e) {
common_debug('WARNING: Could not get attention list from object '.get_class($object).'!');
}
return false; return false;
} }

View File

@ -40,11 +40,8 @@ if (!defined('GNUSOCIAL')) { exit(1); }
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/ * @link http://status.net/
*/ */
class EventPlugin extends MicroAppPlugin class EventPlugin extends ActivityVerbHandlerPlugin
{ {
var $oldSaveNew = true;
/** /**
* Set up our tables (event and rsvp) * Set up our tables (event and rsvp)
* *
@ -131,22 +128,64 @@ class EventPlugin extends MicroAppPlugin
RSVP::POSSIBLE); RSVP::POSSIBLE);
} }
protected function saveObjectFromActivity(Activity $activity, Notice $stored, array $options=array()) public function newFormAction() {
// such as 'newbookmark' or 'newevent' route
return 'new'.$this->tag();
}
function onStartShowEntryForms(&$tabs)
{
$tabs[$this->tag()] = array('title' => $this->appTitle(),
'href' => common_local_url($this->newFormAction()),
);
return true;
}
function onStartMakeEntryForm($tag, $out, &$form)
{
if ($tag == $this->tag()) {
$form = $this->entryForm($out);
return false;
}
return true;
}
protected function getActionTitle(ManagedAction $action, $verb, Notice $target, Profile $scoped)
{
return $verb;
}
protected function doActionPreparation(ManagedAction $action, $verb, Notice $target, Profile $scoped)
{
return true;
}
protected function doActionPost(ManagedAction $action, $verb, Notice $target, Profile $scoped)
{
throw new ServerException('Event does not handle doActionPost yet', 501);
}
protected function getActivityForm(ManagedAction $action, $verb, Notice $target, Profile $scoped)
{
return new RSVPForm(Happening::fromNotice($target), $action);
}
protected function saveObjectFromActivity(Activity $act, Notice $stored, array $options=array())
{ {
if (count($act->objects) !== 1) { if (count($act->objects) !== 1) {
// TRANS: Exception thrown when there are too many activity objects. // TRANS: Exception thrown when there are too many activity objects.
throw new Exception(_m('Too many activity objects.')); throw new Exception(_m('Too many activity objects.'));
} }
$actobj = $activity->objects[0]; $actobj = $act->objects[0];
switch ($activity->verb) { switch ($act->verb) {
case ActivityVerb::POST: case ActivityVerb::POST:
$actobj = $activity->objects[0];
if (!ActivityUtils::compareTypes($actobj->type, array(Happening::OBJECT_TYPE))) { if (!ActivityUtils::compareTypes($actobj->type, array(Happening::OBJECT_TYPE))) {
// TRANS: Exception thrown when event plugin comes across a non-event type object. // TRANS: Exception thrown when event plugin comes across a non-event type object.
throw new Exception(_m('Wrong type for object.')); throw new Exception(_m('Wrong type for object.'));
} }
return Happening::saveActivityObject($actobj, $stored->getProfile()); return Happening::saveActivityObject($actobj, $stored);
break; break;
case RSVP::POSITIVE: case RSVP::POSITIVE:
case RSVP::NEGATIVE: case RSVP::NEGATIVE:
@ -157,9 +196,9 @@ class EventPlugin extends MicroAppPlugin
// TRANS: Exception thrown when trying to RSVP for an unknown event. // TRANS: Exception thrown when trying to RSVP for an unknown event.
throw new Exception(_m('RSVP for unknown event.')); throw new Exception(_m('RSVP for unknown event.'));
} }
$object = RSVP::saveNewFromNotice($stored, $happening, $activity->verb); $object = RSVP::saveNewFromNotice($stored, $happening, $act->verb);
// Our data model expects this // Our data model expects this
$stored->object_type = $activity->verb; $stored->object_type = $act->verb;
return $object; return $object;
break; break;
default: default:

View File

@ -100,93 +100,7 @@ class Happening extends Managed_DataObject
); );
} }
static function saveNew(Profile $profile, $start_time, $end_time, $title, $location, $description, $url, $options=array()) public static function saveActivityObject(ActivityObject $actobj, Notice $stored)
{
if (array_key_exists('uri', $options)) {
$other = Happening::getKV('uri', $options['uri']);
if ($other instanceof Happening) {
// TRANS: Client exception thrown when trying to create an event that already exists.
throw new ClientException(_m('Event already exists.'));
}
}
$ev = new Happening();
$ev->id = UUID::gen();
$ev->profile_id = $profile->getID();
$ev->start_time = $start_time;
$ev->end_time = $end_time;
$ev->title = $title;
$ev->location = $location;
$ev->description = $description;
$ev->url = $url;
if (array_key_exists('created', $options)) {
$ev->created = $options['created'];
} else {
$ev->created = common_sql_now();
}
if (array_key_exists('uri', $options)) {
$ev->uri = $options['uri'];
} else {
$ev->uri = common_local_url('showevent',
array('id' => $ev->id));
}
$ev->insert();
// XXX: does this get truncated?
// TRANS: Event description. %1$s is a title, %2$s is start time, %3$s is end time,
// TRANS: %4$s is location, %5$s is a description.
$content = sprintf(_m('"%1$s" %2$s - %3$s (%4$s): %5$s'),
$title,
common_exact_date($ev->start_time),
common_exact_date($ev->end_time),
$location,
$description);
// TRANS: Rendered microformats2 tagged event description.
// TRANS: %1$s is a title, %2$s is start time, %3$s is start time,
// TRANS: %4$s is end time, %5$s is end time, %6$s is location, %7$s is description.
// TRANS: Class names should not be translated.
$rendered = sprintf(_m('<div class="h-event">'.
'<p class="p-name p-summary">%1$s</p> '.
'<time class="dt-start" datetime="%2$s">%3$s</time> - '.
'<time class="dt-end" datetime="%4$s">%5$s</time> '.
'(<span class="p-location">%6$s</span>): '.
'<div class="p-description">%7$s</div> '.
'</div>'),
htmlspecialchars($title),
htmlspecialchars(common_date_iso8601($ev->start_time)),
htmlspecialchars(common_exact_date($ev->start_time)),
htmlspecialchars(common_date_iso8601($ev->end_time)),
htmlspecialchars(common_exact_date($ev->end_time)),
htmlspecialchars($location),
htmlspecialchars($description));
$options = array_merge(array('object_type' => Happening::OBJECT_TYPE),
$options);
if (!array_key_exists('uri', $options)) {
$options['uri'] = $ev->getUri();
}
if (!empty($url)) {
$options['urls'] = array($url);
}
$saved = Notice::saveNew($profile->getID(),
$content,
array_key_exists('source', $options) ?
$options['source'] : 'web',
$options);
return $saved;
}
public function saveActivityObject(ActivityObject $actobj, Profile $stored)
{ {
$other = Happening::getKV('uri', $actobj->id); $other = Happening::getKV('uri', $actobj->id);
if ($other instanceof Happening) { if ($other instanceof Happening) {
@ -194,53 +108,69 @@ class Happening extends Managed_DataObject
throw new ClientException(_m('Event already exists.')); throw new ClientException(_m('Event already exists.'));
} }
$dtstart = $actobj->element->getElementsByTagName('dtstart'); $dtstart = null;
if($dtstart->length == 0) { $dtend = null;
$location = null;
$url = null;
foreach ($actobj->extra as $extra) {
switch ($extra[0]) {
case 'dtstart':
$dtstart = $extra[2];
case 'dtend':
$dtend = $extra[2];
break;
case 'location':
// location is optional
$location = $extra[2];
break;
case 'url':
// url is optional
$url = $extra[2];
}
}
if(empty($dtstart)) {
// TRANS: Exception thrown when has no start date // TRANS: Exception thrown when has no start date
throw new Exception(_m('No start date for event.')); throw new Exception(_m('No start date for event.'));
} }
$dtend = $actobj->element->getElementsByTagName('dtend'); if(empty($dtend)) {
if($dtend->length == 0) {
// TRANS: Exception thrown when has no end date // TRANS: Exception thrown when has no end date
throw new Exception(_m('No end date for event.')); throw new Exception(_m('No end date for event.'));
} }
// convert RFC3339 dates delivered in Activity Stream to MySQL DATETIME date format // convert RFC3339 dates delivered in Activity Stream to MySQL DATETIME date format
$start_time = new DateTime($dtstart->item(0)->nodeValue); $start_time = new DateTime($dtstart);
$start_time->setTimezone(new DateTimeZone('UTC')); $start_time->setTimezone(new DateTimeZone('UTC'));
$start_time = $start_time->format('Y-m-d H:i:s'); $start_time = $start_time->format('Y-m-d H:i:s');
$end_time = new DateTime($dtend->item(0)->nodeValue); $end_time = new DateTime($dtend);
$end_time->setTimezone(new DateTimeZone('UTC')); $end_time->setTimezone(new DateTimeZone('UTC'));
$end_time = $end_time->format('Y-m-d H:i:s'); $end_time = $end_time->format('Y-m-d H:i:s');
// location is optional
$location = null;
$location_object = $happeningObj->element->getElementsByTagName('location');
if($location_object->length > 0) {
$location = $location_object->item(0)->nodeValue;
}
// url is optional
$url = null;
$url_object = $happeningObj->element->getElementsByTagName('url');
if($url_object->length > 0) {
$url = $url_object->item(0)->nodeValue;
}
$ev = new Happening(); $ev = new Happening();
$ev->id = UUID::gen(); $ev->id = UUID::gen();
$ev->uri = $actobj->uri; $ev->uri = $actobj->id;
$ev->profile_id = $stored->getProfile()->getID(); $ev->profile_id = $stored->getProfile()->getID();
$ev->start_time = $start_time; $ev->start_time = $start_time;
$ev->end_time = $end_time; $ev->end_time = $end_time;
$ev->title = $actobj->title; $ev->title = $actobj->title;
$ev->location = $location; $ev->location = $location;
$ev->description = $actobj->summary; $ev->description = $stored->getContent();
$ev->url = $url; $ev->url = $url;
$ev->created = $stored->getCreated(); $ev->created = $stored->getCreated();
$ev->insert(); $ev->insert();
return $ev;
}
public function insert()
{
$result = parent::insert();
if ($result === false) {
common_log_db_error($this, 'INSERT', __FILE__);
throw new ServerException(_('Failed to insert '._ve(get_called_class()).' into database'));
}
return $result;
} }
/** /**

View File

@ -402,12 +402,6 @@ class Fave extends Managed_DataObject
return $object; return $object;
} }
public function getAttentionArray() {
// not all objects can/should carry attentions, so we don't require extending this
// the format should be an array with URIs to mentioned profiles
return array();
}
public function getTarget() public function getTarget()
{ {
return Notice::getByID($this->notice_id); return Notice::getByID($this->notice_id);