diff --git a/actions/apistatusesupdate.php b/actions/apistatusesupdate.php index 09663ac7c2..f2c70f5452 100644 --- a/actions/apistatusesupdate.php +++ b/actions/apistatusesupdate.php @@ -174,7 +174,7 @@ class ApiStatusesUpdateAction extends ApiAuthAction foreach (array_unique($matches[0]) as $match) { try { $this->media_ids[$match] = File::getByID($match); - } catch (EmptyIdException $e) { + } catch (EmptyPkeyValueException $e) { // got a zero from the client, at least Twidere does this on occasion } catch (NoResultException $e) { // File ID was not found. Do we abort and report to the client? diff --git a/classes/File.php b/classes/File.php index 1a38aefa72..b28f1373d6 100644 --- a/classes/File.php +++ b/classes/File.php @@ -120,7 +120,7 @@ class File extends Managed_DataObject // $args['attachment'] should always be set if action===attachment, given our routing rules $file = File::getByID($args['attachment']); return $file; - } catch (EmptyIdException $e) { + } catch (EmptyPkeyValueException $e) { // ...but $args['attachment'] can also be 0... } catch (NoResultException $e) { // apparently this link goes to us, but is _not_ an existing attachment (File) ID? diff --git a/classes/Managed_DataObject.php b/classes/Managed_DataObject.php index 5b22672d7b..89263ee778 100644 --- a/classes/Managed_DataObject.php +++ b/classes/Managed_DataObject.php @@ -384,7 +384,7 @@ abstract class Managed_DataObject extends Memcached_DataObject static function getByID($id) { if (empty($id)) { - throw new EmptyIdException(get_called_class()); + throw new EmptyPkeyValueException(get_called_class(), 'id'); } // getByPK throws exception if id is null // or if the class does not have a single 'id' column as primary key diff --git a/classes/Notice.php b/classes/Notice.php index c130cccc26..96f4769af2 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -2683,7 +2683,7 @@ class Notice extends Managed_DataObject public static function getAsTimestamp($id) { if (empty($id)) { - throw new EmptyIdException('Notice'); + throw new EmptyPkeyValueException('Notice', 'id'); } $timestamp = null; diff --git a/lib/emptyidexception.php b/lib/emptypkeyvalueexception.php similarity index 73% rename from lib/emptyidexception.php rename to lib/emptypkeyvalueexception.php index ddf781b067..4470b7ba31 100644 --- a/lib/emptyidexception.php +++ b/lib/emptypkeyvalueexception.php @@ -29,10 +29,13 @@ if (!defined('GNUSOCIAL')) { exit(1); } -class EmptyIdException extends ServerException +class EmptyPkeyValueException extends ServerException { - public function __construct($called_class) + public function __construct($called_class, $key=null) { - parent::__construct(sprintf(_('Empty ID value was given to query for a "%s" object'), $called_class)); + // FIXME: translate the 'not specified' case? + parent::__construct(sprintf(_('Empty primary key (%1$s) value was given to query for a "%2$s" object'), + is_null($key) ? 'not specified' : _ve($key), + $called_class)); } } diff --git a/plugins/Favorite/classes/Fave.php b/plugins/Favorite/classes/Fave.php index c9bb7a6dd2..fb5575c0d4 100644 --- a/plugins/Favorite/classes/Fave.php +++ b/plugins/Favorite/classes/Fave.php @@ -132,7 +132,7 @@ class Fave extends Managed_DataObject } catch (NoResultException $e) { // In case there's some inconsistency where the profile or notice was deleted without losing the fave db entry common_log(LOG_INFO, '"'.get_class($e->obj).'" with id=='.var_export($e->obj->id, true).' object not found when deleting favorite, ignoring...'); - } catch (EmptyIdException $e) { + } catch (EmptyPkeyValueException $e) { // Some buggy instances of GNU social have had favorites with notice id==0 stored in the database common_log(LOG_INFO, _ve($e->getMessage())); }