annotate vendor/chi-teck/drupal-code-generator/templates/d7/hook/update_index.twig @ 5:12f9dff5fda9
tip
Update to Drupal core 8.7.1
author |
Chris Cannam |
date |
Thu, 09 May 2019 15:34:47 +0100 |
parents |
c75dbcec494b |
children |
|
rev |
line source |
Chris@0
|
1 /**
|
Chris@0
|
2 * Implements hook_update_index().
|
Chris@0
|
3 */
|
Chris@0
|
4 function {{ machine_name }}_update_index() {
|
Chris@0
|
5 $limit = (int)variable_get('search_cron_limit', 100);
|
Chris@0
|
6
|
Chris@0
|
7 $result = db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE d.sid IS NULL OR d.reindex <> 0 ORDER BY d.reindex ASC, n.nid ASC", 0, $limit);
|
Chris@0
|
8
|
Chris@0
|
9 foreach ($result as $node) {
|
Chris@0
|
10 $node = node_load($node->nid);
|
Chris@0
|
11
|
Chris@0
|
12 // Save the changed time of the most recent indexed node, for the search
|
Chris@0
|
13 // results half-life calculation.
|
Chris@0
|
14 variable_set('node_cron_last', $node->changed);
|
Chris@0
|
15
|
Chris@0
|
16 // Render the node.
|
Chris@0
|
17 node_build_content($node, 'search_index');
|
Chris@0
|
18 $node->rendered = drupal_render($node->content);
|
Chris@0
|
19
|
Chris@0
|
20 $text = '<h1>' . check_plain($node->title) . '</h1>' . $node->rendered;
|
Chris@0
|
21
|
Chris@0
|
22 // Fetch extra data normally not visible
|
Chris@0
|
23 $extra = module_invoke_all('node_update_index', $node);
|
Chris@0
|
24 foreach ($extra as $t) {
|
Chris@0
|
25 $text .= $t;
|
Chris@0
|
26 }
|
Chris@0
|
27
|
Chris@0
|
28 // Update index
|
Chris@0
|
29 search_index($node->nid, 'node', $text);
|
Chris@0
|
30 }
|
Chris@0
|
31 }
|