]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Use "newer" terminology and throw exceptions
authorMikael Nordfeldth <mmn@hethane.se>
Mon, 18 Jan 2016 23:21:16 +0000 (00:21 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Mon, 18 Jan 2016 23:21:16 +0000 (00:21 +0100)
plugins/Event/EventPlugin.php
plugins/Event/actions/showevent.php [deleted file]
plugins/Event/classes/Happening.php
plugins/Event/classes/RSVP.php

index 7dfd061efedf889ca197b068125db5915a301187..0a0afc216b67e1d6cec6f552666e9fb3c20b375a 100644 (file)
@@ -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 (file)
index f1d8c6a..0000000
+++ /dev/null
@@ -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;
-    }
-}
index e4e1f962361b2b7f6a54579bea0c6c8725df41c3..df868ad03ddb504acfca93bcd7c194f49a4ebfe3 100644 (file)
@@ -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()));
     }
index 90c9d25a8d74010fa318a6662a9b85a71e8dd7c6..8f5be4d5f5f00f2efd5f2be0920dbde50f28abed 100644 (file)
@@ -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;
         }