Skip to content

Instantly share code, notes, and snippets.

@djevans
Created April 25, 2017 13:36
Show Gist options
  • Save djevans/ece40002a2f4bdc415a3ab60ec416541 to your computer and use it in GitHub Desktop.
Save djevans/ece40002a2f4bdc415a3ab60ec416541 to your computer and use it in GitHub Desktop.
Cron hook in progress
<?php
/**
* Implements hook_cron().
*/
function orx_saved_searches_cron() {
$query = <<<EOF
SELECT id, view_path FROM {saved_search}
WHERE (last_executed IS NULL OR last_queued < last_executed)
AND last_queued + notification_interval <= :request_time
EOF;
$result = db_query($query, [':request_time' => REQUEST_TIME])->fetchAllAssoc('id');
$queue = \Drupal::queue('saved_search_queue');
foreach ($result as $id => $values) {
$user = user_load($values['user_id']);
$data = [
'id' => $id,
'name' => $values['name'],
'view_path' => $values['view_path'],
'user_email' => $user->getEmail(),
'user_name' => $user->getDisplayName(),
];
$queue->createItem($data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment