Created
April 25, 2017 13:36
-
-
Save djevans/ece40002a2f4bdc415a3ab60ec416541 to your computer and use it in GitHub Desktop.
Cron hook in progress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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