From f83b2cf324c0f54d73530bf0e00a958f5f04f219 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Wed, 5 Mar 2014 01:27:27 +0100 Subject: [PATCH] Handle removed profile more gracefully in noticelist Just hide it from the visitor, but log a warning (and error, since the exception itself logs that). --- classes/Notice.php | 23 ++++++++++++++--------- lib/noticelist.php | 11 ++--------- lib/threadednoticelist.php | 4 +--- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index 2cebc47574..c25f702989 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -142,20 +142,20 @@ class Notice extends Managed_DataObject const FOLLOWER_SCOPE = 8; protected $_profile = -1; - + public function getProfile() { if ($this->_profile === -1) { $this->_setProfile(Profile::getKV('id', $this->profile_id)); } - if (!$this->_profile instanceof Profile) { - throw new NoProfileException($this->profile_id); - } return $this->_profile; } - function _setProfile(Profile $profile) + public function _setProfile(Profile $profile=null) { + if (!$profile instanceof Profile) { + throw new NoProfileException($this->profile_id); + } $this->_profile = $profile; } @@ -2510,10 +2510,15 @@ class Notice extends Managed_DataObject { $map = self::getProfiles($notices); - foreach ($notices as $notice) { - if (array_key_exists($notice->profile_id, $map)) { - $notice->_setProfile($map[$notice->profile_id]); - } + foreach ($notices as $entry=>$notice) { + try { + if (array_key_exists($notice->profile_id, $map)) { + $notice->_setProfile($map[$notice->profile_id]); + } + } catch (NoProfileException $e) { + common_log(LOG_WARNING, "Failed to fill profile in Notice with non-existing entry for profile_id: {$e->id}"); + unset($notices[$entry]); + } } return array_values($map); diff --git a/lib/noticelist.php b/lib/noticelist.php index df6e8d98c2..b00e476d92 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -28,13 +28,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} - -require_once INSTALLDIR.'/lib/favorform.php'; -require_once INSTALLDIR.'/lib/disfavorform.php'; -require_once INSTALLDIR.'/lib/attachmentlist.php'; +if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); } /** * widget for displaying a list of notices @@ -136,8 +130,7 @@ class NoticeList extends Widget $profiles = Notice::fillProfiles($notices); $p = Profile::current(); - - if (!empty($p)) { + if ($p instanceof Profile) { $ids = array(); diff --git a/lib/threadednoticelist.php b/lib/threadednoticelist.php index c3382897c7..6d8570fbee 100644 --- a/lib/threadednoticelist.php +++ b/lib/threadednoticelist.php @@ -27,9 +27,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} +if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); } /** * widget for displaying a list of notices