s/EmptyIdException/EmptyPkeyValueException/

This commit is contained in:
Mikael Nordfeldth 2016-06-25 11:50:59 +02:00
parent d7a4098b56
commit 7978cd6d59
6 changed files with 11 additions and 8 deletions

View File

@ -174,7 +174,7 @@ class ApiStatusesUpdateAction extends ApiAuthAction
foreach (array_unique($matches[0]) as $match) { foreach (array_unique($matches[0]) as $match) {
try { try {
$this->media_ids[$match] = File::getByID($match); $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 // got a zero from the client, at least Twidere does this on occasion
} catch (NoResultException $e) { } catch (NoResultException $e) {
// File ID was not found. Do we abort and report to the client? // File ID was not found. Do we abort and report to the client?

View File

@ -120,7 +120,7 @@ class File extends Managed_DataObject
// $args['attachment'] should always be set if action===attachment, given our routing rules // $args['attachment'] should always be set if action===attachment, given our routing rules
$file = File::getByID($args['attachment']); $file = File::getByID($args['attachment']);
return $file; return $file;
} catch (EmptyIdException $e) { } catch (EmptyPkeyValueException $e) {
// ...but $args['attachment'] can also be 0... // ...but $args['attachment'] can also be 0...
} catch (NoResultException $e) { } catch (NoResultException $e) {
// apparently this link goes to us, but is _not_ an existing attachment (File) ID? // apparently this link goes to us, but is _not_ an existing attachment (File) ID?

View File

@ -384,7 +384,7 @@ abstract class Managed_DataObject extends Memcached_DataObject
static function getByID($id) static function getByID($id)
{ {
if (empty($id)) { if (empty($id)) {
throw new EmptyIdException(get_called_class()); throw new EmptyPkeyValueException(get_called_class(), 'id');
} }
// getByPK throws exception if id is null // getByPK throws exception if id is null
// or if the class does not have a single 'id' column as primary key // or if the class does not have a single 'id' column as primary key

View File

@ -2683,7 +2683,7 @@ class Notice extends Managed_DataObject
public static function getAsTimestamp($id) public static function getAsTimestamp($id)
{ {
if (empty($id)) { if (empty($id)) {
throw new EmptyIdException('Notice'); throw new EmptyPkeyValueException('Notice', 'id');
} }
$timestamp = null; $timestamp = null;

View File

@ -29,10 +29,13 @@
if (!defined('GNUSOCIAL')) { exit(1); } 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));
} }
} }

View File

@ -132,7 +132,7 @@ class Fave extends Managed_DataObject
} catch (NoResultException $e) { } catch (NoResultException $e) {
// In case there's some inconsistency where the profile or notice was deleted without losing the fave db entry // 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...'); 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 // Some buggy instances of GNU social have had favorites with notice id==0 stored in the database
common_log(LOG_INFO, _ve($e->getMessage())); common_log(LOG_INFO, _ve($e->getMessage()));
} }