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).
This commit is contained in:
Mikael Nordfeldth 2014-03-05 01:27:27 +01:00
parent 4baaf7274c
commit f83b2cf324
3 changed files with 17 additions and 21 deletions

View File

@ -148,14 +148,14 @@ class Notice extends Managed_DataObject
if ($this->_profile === -1) { if ($this->_profile === -1) {
$this->_setProfile(Profile::getKV('id', $this->profile_id)); $this->_setProfile(Profile::getKV('id', $this->profile_id));
} }
if (!$this->_profile instanceof Profile) {
throw new NoProfileException($this->profile_id);
}
return $this->_profile; 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; $this->_profile = $profile;
} }
@ -2510,10 +2510,15 @@ class Notice extends Managed_DataObject
{ {
$map = self::getProfiles($notices); $map = self::getProfiles($notices);
foreach ($notices as $notice) { foreach ($notices as $entry=>$notice) {
try {
if (array_key_exists($notice->profile_id, $map)) { if (array_key_exists($notice->profile_id, $map)) {
$notice->_setProfile($map[$notice->profile_id]); $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); return array_values($map);

View File

@ -28,13 +28,7 @@
* @link http://status.net/ * @link http://status.net/
*/ */
if (!defined('STATUSNET') && !defined('LACONICA')) { if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); }
exit(1);
}
require_once INSTALLDIR.'/lib/favorform.php';
require_once INSTALLDIR.'/lib/disfavorform.php';
require_once INSTALLDIR.'/lib/attachmentlist.php';
/** /**
* widget for displaying a list of notices * widget for displaying a list of notices
@ -136,8 +130,7 @@ class NoticeList extends Widget
$profiles = Notice::fillProfiles($notices); $profiles = Notice::fillProfiles($notices);
$p = Profile::current(); $p = Profile::current();
if ($p instanceof Profile) {
if (!empty($p)) {
$ids = array(); $ids = array();

View File

@ -27,9 +27,7 @@
* @link http://status.net/ * @link http://status.net/
*/ */
if (!defined('STATUSNET') && !defined('LACONICA')) { if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); }
exit(1);
}
/** /**
* widget for displaying a list of notices * widget for displaying a list of notices