From 73992a1ed81e02fd9d4894fb8300e3511d814f77 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Tue, 19 Jan 2016 00:21:16 +0100 Subject: [PATCH] Use "newer" terminology and throw exceptions --- plugins/Event/EventPlugin.php | 42 ++++---------- plugins/Event/actions/showevent.php | 85 ----------------------------- plugins/Event/classes/Happening.php | 2 +- plugins/Event/classes/RSVP.php | 8 +-- 4 files changed, 16 insertions(+), 121 deletions(-) delete mode 100644 plugins/Event/actions/showevent.php diff --git a/plugins/Event/EventPlugin.php b/plugins/Event/EventPlugin.php index 7dfd061efe..0a0afc216b 100644 --- a/plugins/Event/EventPlugin.php +++ b/plugins/Event/EventPlugin.php @@ -207,25 +207,18 @@ class EventPlugin extends ActivityVerbHandlerPlugin } } - /** - * Turn a Notice into an activity object - * - * @param Notice $notice - * - * @return ActivityObject - */ - function activityObjectFromNotice(Notice $notice) + function activityObjectFromNotice(Notice $stored) { $happening = null; switch (true) { - case ActivityUtils::compareVerbs($notice->verb, array(ActivityVerb::POST)) && - ActivityUtils::compareTypes($notice->object_type, array(Happening::OBJECT_TYPE)): - $happening = Happening::fromStored($notice); + case ActivityUtils::compareVerbs($stored->verb, array(ActivityVerb::POST)) && + ActivityUtils::compareTypes($stored->object_type, array(Happening::OBJECT_TYPE)): + $happening = Happening::fromStored($stored); break; // FIXME: Why are these object_type?? case ActivityUtils::compareTypes($stored->object_type, array(RSVP::POSITIVE, RSVP::NEGATIVE, RSVP::POSSIBLE)): - $rsvp = RSVP::fromNotice($notice); + $rsvp = RSVP::fromNotice($stored); $happening = $rsvp->getEvent(); break; default: @@ -233,18 +226,13 @@ class EventPlugin extends ActivityVerbHandlerPlugin throw new Exception(_m('Unknown object type.')); } - // This is a bit weird, if it's a Notice for a Happening. We should only do this for RSVP. - $notice = $happening->getNotice(); - $obj = new ActivityObject(); $obj->id = $happening->getUri(); $obj->type = Happening::OBJECT_TYPE; $obj->title = $happening->title; $obj->summary = $happening->description; - $obj->link = $notice->getUrl(); - - // XXX: how to get this stuff into JSON?! + $obj->link = $happening->getStored()->getUrl(); $obj->extra[] = array('dtstart', array('xmlns' => 'urn:ietf:params:xml:ns:xcal'), @@ -255,9 +243,6 @@ class EventPlugin extends ActivityVerbHandlerPlugin $obj->extra[] = array('location', false, $happening->location); $obj->extra[] = array('url', false, $happening->url); - // XXX: probably need other stuff here - - common_debug('EVENTDEBUG: activity object from notice: '._ve($obj)); return $obj; } @@ -299,8 +284,12 @@ class EventPlugin extends ActivityVerbHandlerPlugin switch ($notice->object_type) { case Happening::OBJECT_TYPE: common_log(LOG_DEBUG, "Deleting event from notice..."); - $happening = Happening::fromStored($notice); - $happening->delete(); + try { + $happening = Happening::fromStored($notice); + $happening->delete(); + } catch (NoResultException $e) { + // already gone + } break; case RSVP::POSITIVE: case RSVP::NEGATIVE: @@ -328,7 +317,6 @@ class EventPlugin extends ActivityVerbHandlerPlugin function onStartAddNoticeReply($nli, $parent, $child) { - // Filter out any poll responses if (($parent->object_type == Happening::OBJECT_TYPE) && in_array($child->object_type, array(RSVP::POSITIVE, RSVP::NEGATIVE, RSVP::POSSIBLE))) { return false; @@ -336,12 +324,6 @@ class EventPlugin extends ActivityVerbHandlerPlugin return true; } - protected function showNoticeItemNotice(NoticeListItem $nli) - { - $nli->showAuthor(); - $nli->showContent(); - } - protected function showNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped=null) { switch (true) { diff --git a/plugins/Event/actions/showevent.php b/plugins/Event/actions/showevent.php deleted file mode 100644 index f1d8c6a0dd..0000000000 --- a/plugins/Event/actions/showevent.php +++ /dev/null @@ -1,85 +0,0 @@ -. - * - * @category Event - * @package StatusNet - * @author Evan Prodromou - * @copyright 2011 StatusNet, Inc. - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 - * @link http://status.net/ - */ - -if (!defined('STATUSNET')) { - // This check helps protect against security problems; - // your code file can't be executed directly from the web. - exit(1); -} - -/** - * Show a single event, with associated information - * - * @category Event - * @package StatusNet - * @author Evan Prodromou - * @copyright 2011 StatusNet, Inc. - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 - * @link http://status.net/ - */ -class ShoweventAction extends ShownoticeAction -{ - protected $id = null; - protected $event = null; - - function getNotice() - { - $this->id = $this->trimmed('id'); - - $this->event = Happening::getKV('id', $this->id); - - if (empty($this->event)) { - // TRANS: Client exception thrown when referring to a non-existing event. - throw new ClientException(_m('No such event.'), 404); - } - - $notice = $this->event->getNotice(); - - if (empty($notice)) { - // Did we used to have it, and it got deleted? - // TRANS: Client exception thrown when referring to a non-existing event. - throw new ClientException(_m('No such event.'), 404); - } - - return $notice; - } - - /** - * Title of the page - * - * Used by Action class for layout. - * - * @return string page tile - */ - function title() - { - return $this->event->title; - } -} diff --git a/plugins/Event/classes/Happening.php b/plugins/Event/classes/Happening.php index e4e1f96236..df868ad03d 100644 --- a/plugins/Event/classes/Happening.php +++ b/plugins/Event/classes/Happening.php @@ -193,7 +193,7 @@ class Happening extends Managed_DataObject return $this->uri; } - public function getNotice() + public function getStored() { return Notice::getByKeys(array('uri'=>$this->getUri())); } diff --git a/plugins/Event/classes/RSVP.php b/plugins/Event/classes/RSVP.php index 90c9d25a8d..8f5be4d5f5 100644 --- a/plugins/Event/classes/RSVP.php +++ b/plugins/Event/classes/RSVP.php @@ -127,7 +127,7 @@ class RSVP extends Managed_DataObject function saveNew($profile, $event, $verb, $options=array()) { - $eventNotice = $event->getNotice(); + $eventNotice = $event->getStored(); $options = array_merge(array('source' => 'web'), $options); $act = new Activity(); @@ -235,7 +235,7 @@ class RSVP extends Managed_DataObject static function fromNotice(Notice $notice) { $rsvp = new RSVP(); - $rsvp->uri = $notice->uri; + $rsvp->uri = $notice->getUri(); if (!$rsvp->find(true)) { throw new NoResultException($rsvp); } @@ -354,8 +354,7 @@ class RSVP extends Managed_DataObject // TRANS: Used as: Username [is [not ] attending|might attend] an unknown event. $eventTitle = _m('an unknown event'); } else { - $notice = $event->getNotice(); - $eventUrl = $notice->getUrl(); + $eventUrl = $event->getStored()->getUrl(); $eventTitle = $event->title; } @@ -398,7 +397,6 @@ class RSVP extends Managed_DataObject // TRANS: Used as: Username [is [not ] attending|might attend] an unknown event. $eventTitle = _m('an unknown event'); } else { - $notice = $event->getNotice(); $eventTitle = $event->title; }