forked from GNUsocial/gnu-social
Eventify Notice getAsTimestamp (for Deleted_notice)
This commit is contained in:
parent
29b45bb87a
commit
45dd343126
@ -2615,21 +2615,21 @@ class Notice extends Managed_DataObject
|
||||
*/
|
||||
public static function getAsTimestamp($id)
|
||||
{
|
||||
if (!$id) {
|
||||
return false;
|
||||
if (empty($id)) {
|
||||
throw new EmptyIdException('Notice');
|
||||
}
|
||||
|
||||
$notice = Notice::getKV('id', $id);
|
||||
if ($notice) {
|
||||
return $notice->created;
|
||||
$timestamp = null;
|
||||
if (Event::handle('GetNoticeSqlTimestamp', array($id, &$timestamp))) {
|
||||
// getByID throws exception if $id isn't found
|
||||
$notice = Notice::getByID($id);
|
||||
$timestamp = $notice->created;
|
||||
}
|
||||
|
||||
$deleted = Deleted_notice::getKV('id', $id);
|
||||
if ($deleted) {
|
||||
return $deleted->created;
|
||||
if (empty($timestamp)) {
|
||||
throw new ServerException('No timestamp found for Notice with id=='._ve($id));
|
||||
}
|
||||
|
||||
return false;
|
||||
return $timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2645,12 +2645,13 @@ class Notice extends Managed_DataObject
|
||||
*/
|
||||
public static function whereSinceId($id, $idField='id', $createdField='created')
|
||||
{
|
||||
try {
|
||||
$since = Notice::getAsTimestamp($id);
|
||||
if ($since) {
|
||||
return sprintf("($createdField = '%s' and $idField > %d) or ($createdField > '%s')", $since, $id, $since);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
return sprintf("($createdField = '%s' and $idField > %d) or ($createdField > '%s')", $since, $id, $since);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an SQL 'where' fragment for timestamp-based sorting from a since_id
|
||||
@ -2684,12 +2685,13 @@ class Notice extends Managed_DataObject
|
||||
*/
|
||||
public static function whereMaxId($id, $idField='id', $createdField='created')
|
||||
{
|
||||
try {
|
||||
$max = Notice::getAsTimestamp($id);
|
||||
if ($max) {
|
||||
return sprintf("($createdField < '%s') or ($createdField = '%s' and $idField <= %d)", $max, $max, $id);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
return sprintf("($createdField < '%s') or ($createdField = '%s' and $idField <= %d)", $max, $max, $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an SQL 'where' fragment for timestamp-based sorting from a max_id
|
||||
|
@ -34,6 +34,18 @@ class ActivityModerationPlugin extends ActivityVerbHandlerPlugin
|
||||
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)
|
||||
{
|
||||
// FIXME: switch based on action type
|
||||
|
Loading…
Reference in New Issue
Block a user