Eventify Notice getAsTimestamp (for Deleted_notice)

This commit is contained in:
Mikael Nordfeldth 2016-01-13 21:01:47 +01:00
parent 29b45bb87a
commit 45dd343126
2 changed files with 32 additions and 18 deletions

View File

@ -2615,21 +2615,21 @@ class Notice extends Managed_DataObject
*/ */
public static function getAsTimestamp($id) public static function getAsTimestamp($id)
{ {
if (!$id) { if (empty($id)) {
return false; throw new EmptyIdException('Notice');
} }
$notice = Notice::getKV('id', $id); $timestamp = null;
if ($notice) { if (Event::handle('GetNoticeSqlTimestamp', array($id, &$timestamp))) {
return $notice->created; // getByID throws exception if $id isn't found
$notice = Notice::getByID($id);
$timestamp = $notice->created;
} }
$deleted = Deleted_notice::getKV('id', $id); if (empty($timestamp)) {
if ($deleted) { throw new ServerException('No timestamp found for Notice with id=='._ve($id));
return $deleted->created;
} }
return $timestamp;
return false;
} }
/** /**
@ -2645,11 +2645,12 @@ class Notice extends Managed_DataObject
*/ */
public static function whereSinceId($id, $idField='id', $createdField='created') public static function whereSinceId($id, $idField='id', $createdField='created')
{ {
$since = Notice::getAsTimestamp($id); try {
if ($since) { $since = Notice::getAsTimestamp($id);
return sprintf("($createdField = '%s' and $idField > %d) or ($createdField > '%s')", $since, $id, $since); } catch (Exception $e) {
return false;
} }
return false; return sprintf("($createdField = '%s' and $idField > %d) or ($createdField > '%s')", $since, $id, $since);
} }
/** /**
@ -2684,11 +2685,12 @@ class Notice extends Managed_DataObject
*/ */
public static function whereMaxId($id, $idField='id', $createdField='created') public static function whereMaxId($id, $idField='id', $createdField='created')
{ {
$max = Notice::getAsTimestamp($id); try {
if ($max) { $max = Notice::getAsTimestamp($id);
return sprintf("($createdField < '%s') or ($createdField = '%s' and $idField <= %d)", $max, $max, $id); } catch (Exception $e) {
return false;
} }
return false; return sprintf("($createdField < '%s') or ($createdField = '%s' and $idField <= %d)", $max, $max, $id);
} }
/** /**

View File

@ -34,6 +34,18 @@ class ActivityModerationPlugin extends ActivityVerbHandlerPlugin
return true; return true;
} }
public function onGetNoticeSqlTimestamp($id, &$timestamp)
{
try {
$deleted = Deleted_notice::getByID($id);
$timestamp = $deleted->act_created;
} catch (NoResultException $e) {
return true;
}
// we're done for the event, so return false to stop it
return false;
}
protected function getActionTitle(ManagedAction $action, $verb, Notice $target, Profile $scoped) protected function getActionTitle(ManagedAction $action, $verb, Notice $target, Profile $scoped)
{ {
// FIXME: switch based on action type // FIXME: switch based on action type