Use "newer" terminology and throw exceptions

This commit is contained in:
Mikael Nordfeldth 2016-01-19 00:21:16 +01:00
parent 9eea255c79
commit 73992a1ed8
4 changed files with 16 additions and 121 deletions

View File

@ -207,25 +207,18 @@ class EventPlugin extends ActivityVerbHandlerPlugin
} }
} }
/** function activityObjectFromNotice(Notice $stored)
* Turn a Notice into an activity object
*
* @param Notice $notice
*
* @return ActivityObject
*/
function activityObjectFromNotice(Notice $notice)
{ {
$happening = null; $happening = null;
switch (true) { switch (true) {
case ActivityUtils::compareVerbs($notice->verb, array(ActivityVerb::POST)) && case ActivityUtils::compareVerbs($stored->verb, array(ActivityVerb::POST)) &&
ActivityUtils::compareTypes($notice->object_type, array(Happening::OBJECT_TYPE)): ActivityUtils::compareTypes($stored->object_type, array(Happening::OBJECT_TYPE)):
$happening = Happening::fromStored($notice); $happening = Happening::fromStored($stored);
break; break;
// FIXME: Why are these object_type?? // FIXME: Why are these object_type??
case ActivityUtils::compareTypes($stored->object_type, array(RSVP::POSITIVE, RSVP::NEGATIVE, RSVP::POSSIBLE)): case ActivityUtils::compareTypes($stored->object_type, array(RSVP::POSITIVE, RSVP::NEGATIVE, RSVP::POSSIBLE)):
$rsvp = RSVP::fromNotice($notice); $rsvp = RSVP::fromNotice($stored);
$happening = $rsvp->getEvent(); $happening = $rsvp->getEvent();
break; break;
default: default:
@ -233,18 +226,13 @@ class EventPlugin extends ActivityVerbHandlerPlugin
throw new Exception(_m('Unknown object type.')); 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 = new ActivityObject();
$obj->id = $happening->getUri(); $obj->id = $happening->getUri();
$obj->type = Happening::OBJECT_TYPE; $obj->type = Happening::OBJECT_TYPE;
$obj->title = $happening->title; $obj->title = $happening->title;
$obj->summary = $happening->description; $obj->summary = $happening->description;
$obj->link = $notice->getUrl(); $obj->link = $happening->getStored()->getUrl();
// XXX: how to get this stuff into JSON?!
$obj->extra[] = array('dtstart', $obj->extra[] = array('dtstart',
array('xmlns' => 'urn:ietf:params:xml:ns:xcal'), 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('location', false, $happening->location);
$obj->extra[] = array('url', false, $happening->url); $obj->extra[] = array('url', false, $happening->url);
// XXX: probably need other stuff here
common_debug('EVENTDEBUG: activity object from notice: '._ve($obj));
return $obj; return $obj;
} }
@ -299,8 +284,12 @@ class EventPlugin extends ActivityVerbHandlerPlugin
switch ($notice->object_type) { switch ($notice->object_type) {
case Happening::OBJECT_TYPE: case Happening::OBJECT_TYPE:
common_log(LOG_DEBUG, "Deleting event from notice..."); common_log(LOG_DEBUG, "Deleting event from notice...");
$happening = Happening::fromStored($notice); try {
$happening->delete(); $happening = Happening::fromStored($notice);
$happening->delete();
} catch (NoResultException $e) {
// already gone
}
break; break;
case RSVP::POSITIVE: case RSVP::POSITIVE:
case RSVP::NEGATIVE: case RSVP::NEGATIVE:
@ -328,7 +317,6 @@ class EventPlugin extends ActivityVerbHandlerPlugin
function onStartAddNoticeReply($nli, $parent, $child) function onStartAddNoticeReply($nli, $parent, $child)
{ {
// Filter out any poll responses
if (($parent->object_type == Happening::OBJECT_TYPE) && if (($parent->object_type == Happening::OBJECT_TYPE) &&
in_array($child->object_type, array(RSVP::POSITIVE, RSVP::NEGATIVE, RSVP::POSSIBLE))) { in_array($child->object_type, array(RSVP::POSITIVE, RSVP::NEGATIVE, RSVP::POSSIBLE))) {
return false; return false;
@ -336,12 +324,6 @@ class EventPlugin extends ActivityVerbHandlerPlugin
return true; return true;
} }
protected function showNoticeItemNotice(NoticeListItem $nli)
{
$nli->showAuthor();
$nli->showContent();
}
protected function showNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped=null) protected function showNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped=null)
{ {
switch (true) { switch (true) {

View File

@ -1,85 +0,0 @@
<?php
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2011, StatusNet, Inc.
*
* Show a single event
*
* PHP version 5
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Event
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @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 <evan@status.net>
* @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;
}
}

View File

@ -193,7 +193,7 @@ class Happening extends Managed_DataObject
return $this->uri; return $this->uri;
} }
public function getNotice() public function getStored()
{ {
return Notice::getByKeys(array('uri'=>$this->getUri())); return Notice::getByKeys(array('uri'=>$this->getUri()));
} }

View File

@ -127,7 +127,7 @@ class RSVP extends Managed_DataObject
function saveNew($profile, $event, $verb, $options=array()) function saveNew($profile, $event, $verb, $options=array())
{ {
$eventNotice = $event->getNotice(); $eventNotice = $event->getStored();
$options = array_merge(array('source' => 'web'), $options); $options = array_merge(array('source' => 'web'), $options);
$act = new Activity(); $act = new Activity();
@ -235,7 +235,7 @@ class RSVP extends Managed_DataObject
static function fromNotice(Notice $notice) static function fromNotice(Notice $notice)
{ {
$rsvp = new RSVP(); $rsvp = new RSVP();
$rsvp->uri = $notice->uri; $rsvp->uri = $notice->getUri();
if (!$rsvp->find(true)) { if (!$rsvp->find(true)) {
throw new NoResultException($rsvp); 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. // TRANS: Used as: Username [is [not ] attending|might attend] an unknown event.
$eventTitle = _m('an unknown event'); $eventTitle = _m('an unknown event');
} else { } else {
$notice = $event->getNotice(); $eventUrl = $event->getStored()->getUrl();
$eventUrl = $notice->getUrl();
$eventTitle = $event->title; $eventTitle = $event->title;
} }
@ -398,7 +397,6 @@ class RSVP extends Managed_DataObject
// TRANS: Used as: Username [is [not ] attending|might attend] an unknown event. // TRANS: Used as: Username [is [not ] attending|might attend] an unknown event.
$eventTitle = _m('an unknown event'); $eventTitle = _m('an unknown event');
} else { } else {
$notice = $event->getNotice();
$eventTitle = $event->title; $eventTitle = $event->title;
} }