* Fetch a single item row
*
* @param mixed $stmt statement object
- * @return array current row
+ * @return array|false current row or false
+ * @throws \Exception
*/
public static function fetch($stmt)
{
$row = DBA::fetch($stmt);
- if (is_bool($row)) {
+ if (!is_array($row)) {
return $row;
}
self::markForDeletion(['uri' => $item['uri'], 'deleted' => false], $priority);
// send the notification upstream/downstream
- Worker::add(['priority' => $priority, 'dont_fork' => true], "Notifier", Delivery::DELETION, intval($item['id']));
+ if ($priority) {
+ Worker::add(['priority' => $priority, 'dont_fork' => true], "Notifier", Delivery::DELETION, intval($item['id']));
+ }
} elseif ($item['uid'] != 0) {
Post\User::update($item['uri-id'], $item['uid'], ['hidden' => true]);
return false;
}
+ if (!empty($item['uid'])) {
+ $owner = User::getOwnerDataById($item['uid'], false);
+ if (!$owner) {
+ Logger::notice('Missing item user owner data', ['uid' => $item['uid']]);
+ return false;
+ }
+
+ if ($owner['account_expired'] || $owner['account_removed']) {
+ Logger::notice('Item user has been deleted/expired/removed', ['uid' => $item['uid'], 'deleted' => $owner['deleted'], 'account_expired' => $owner['account_expired'], 'account_removed' => $owner['account_removed']]);
+ return false;
+ }
+ }
+
if (!empty($item['author-id']) && Contact::isBlocked($item['author-id'])) {
Logger::notice('Author is blocked node-wide', ['author-link' => $item['author-link'], 'item-uri' => $item['uri']]);
return false;
* @param array $item
* @return boolean item is too old
*/
- public static function tooOld(array $item)
+ public static function isTooOld(array $item)
{
// check for create date and expire time
$expire_interval = DI::config()->get('system', 'dbclean-expire-days', 0);
$item['network'] = Protocol::DFRN;
$item['protocol'] = Conversation::PARCEL_DIRECT;
- if (is_int($notify)) {
+ if (in_array($notify, PRIORITIES)) {
$priority = $notify;
}
} else {
$datarray['api_source'] = true;
// We have to tell the hooks who we are - this really should be improved
- $_SESSION["authenticated"] = true;
- $_SESSION["uid"] = $contact['uid'];
+ $_SESSION['authenticated'] = true;
+ $_SESSION['uid'] = $contact['uid'];
- return $result;
+ return (bool)$result;
}
/**
$expired = 0;
+ $priority = DI::config()->get('system', 'expire-notify-priority');
+
while ($item = Item::fetch($items)) {
// don't expire filed items
continue;
}
- self::markForDeletionById($item['id'], PRIORITY_LOW);
+ self::markForDeletionById($item['id'], $priority);
++$expired;
}
*/
public static function putInCache(&$item, $update = false)
{
- $body = $item["body"];
+ // Save original body to prevent addons to modify it
+ $body = $item['body'];
$rendered_hash = $item['rendered-hash'] ?? '';
$rendered_html = $item['rendered-html'] ?? '';
if ($rendered_hash == ''
- || $rendered_html == ""
- || $rendered_hash != hash("md5", $item["body"])
- || DI::config()->get("system", "ignore_cache")
+ || $rendered_html == ''
+ || $rendered_hash != hash('md5', BBCode::VERSION . '::' . $body)
+ || DI::config()->get('system', 'ignore_cache')
) {
self::addRedirToImageTags($item);
- $item["rendered-html"] = BBCode::convert($item["body"]);
- $item["rendered-hash"] = hash("md5", $item["body"]);
+ $item['rendered-html'] = BBCode::convert($item['body']);
+ $item['rendered-hash'] = hash('md5', BBCode::VERSION . '::' . $body);
$hook_data = ['item' => $item, 'rendered-html' => $item['rendered-html'], 'rendered-hash' => $item['rendered-hash']];
Hook::callAll('put_item_in_cache', $hook_data);
unset($hook_data);
// Force an update if the generated values differ from the existing ones
- if ($rendered_hash != $item["rendered-hash"]) {
+ if ($rendered_hash != $item['rendered-hash']) {
$update = true;
}
// Only compare the HTML when we forcefully ignore the cache
- if (DI::config()->get("system", "ignore_cache") && ($rendered_html != $item["rendered-html"])) {
+ if (DI::config()->get('system', 'ignore_cache') && ($rendered_html != $item['rendered-html'])) {
$update = true;
}
- if ($update && !empty($item["id"])) {
+ if ($update && !empty($item['id'])) {
self::update(
[
- 'rendered-html' => $item["rendered-html"],
- 'rendered-hash' => $item["rendered-hash"]
+ 'rendered-html' => $item['rendered-html'],
+ 'rendered-hash' => $item['rendered-hash']
],
- ['id' => $item["id"]]
+ ['id' => $item['id']]
);
}
}
- $item["body"] = $body;
+ $item['body'] = $body;
}
/**