$user->uid, ':nid' => $nid))->fetchObject(); } return (isset($history[$nid]->timestamp) ? $history[$nid]->timestamp : 0); } /** * Updates 'last viewed' timestamp of the specified entity for the current user. * * @param $nid * The node ID that has been read. * @param $account * (optional) The user account to update the history for. Defaults to the * current user. */ function history_write($nid, $account = NULL) { global $user; if (!isset($account)) { $account = $user; } if ($account->uid) { db_merge('history') ->key(array( 'uid' => $account->uid, 'nid' => $nid, )) ->fields(array('timestamp' => REQUEST_TIME)) ->execute(); } } /** * Implements hook_cron(). */ function history_cron() { db_delete('history') ->condition('timestamp', HISTORY_READ_LIMIT, '<') ->execute(); } /** * Implements hook_node_delete(). */ function history_node_delete(EntityInterface $node) { db_delete('history') ->condition('nid', $node->nid) ->execute(); } /** * Implements hook_user_cancel(). */ function history_user_cancel($edit, $account, $method) { switch ($method) { case 'user_cancel_reassign': db_delete('history') ->condition('uid', $account->uid) ->execute(); break; } } /** * Implements hook_user_delete(). */ function history_user_delete($account) { db_delete('history') ->condition('uid', $account->uid) ->execute(); }