From c84b21008ed546e9c474cdb503d9b493004c7cb0 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Tue, 2 Jun 2015 13:45:49 +0200 Subject: [PATCH] Notice->getParent code reuse ...not entirely sure whether to allow getParent calls on Notice objects which have not been created, but we'll leave that in for now... --- classes/Notice.php | 9 +++----- lib/noparentnoticeexception.php | 41 +++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 lib/noparentnoticeexception.php diff --git a/classes/Notice.php b/classes/Notice.php index ed2686a383..4d57c5a8db 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -2762,13 +2762,10 @@ class Notice extends Managed_DataObject public function getParent() { - $parent = Notice::getKV('id', $this->reply_to); - - if (!$parent instanceof Notice) { - throw new ServerException('Notice has no parent'); + if (empty($this->reply_to)) { + throw new NoParentNoticeException($this); } - - return $parent; + return self::getById($this->reply_to); } /** diff --git a/lib/noparentnoticeexception.php b/lib/noparentnoticeexception.php new file mode 100644 index 0000000000..fea179c409 --- /dev/null +++ b/lib/noparentnoticeexception.php @@ -0,0 +1,41 @@ +. + * + * @category Exception + * @package GNUsocial + * @author Mikael Nordfeldth + * @copyright 2013 Free Software Foundation, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3 + * @link http://www.gnu.org/software/social/ + */ + +if (!defined('GNUSOCIAL')) { exit(1); } + +class NoParentNoticeException extends ServerException +{ + public $notice; // The notice which has no parent + + public function __construct(Notice $notice) + { + $this->notice = $notice; + parent::__construct(sprintf(_('No parent for notice with ID "%s".'), $this->notice->id)); + } +} -- 2.39.5