Commit 591f4499 authored by Dave Reid's avatar Dave Reid
Browse files

by Dave Reid: Added hook_xmlsitemap_index_links() and a drush command to only...

by Dave Reid: Added hook_xmlsitemap_index_links() and a drush command to only index un-indexed sitemap ilnks.
parent 78946ba8
......@@ -22,6 +22,14 @@ function xmlsitemap_drush_command() {
'callback' => 'drush_xmlsitemap_rebuild',
'drupal dependencies' => array('xmlsitemap'),
);
$items['xmlsitemap-index'] = array(
'description' => 'Process un-indexed XML sitemap links.',
'callback' => 'drush_xmlsitemap_index',
'drupal dependencies' => array('xmlsitemap'),
'options' => array(
'--limit' => 'The limit of links of each type to process. Default value: ' . variable_get('xmlsitemap_batch_limit', 100),
),
);
return $items;
}
......@@ -69,3 +77,11 @@ function drush_xmlsitemap_rebuild() {
);
drush_print(dt('XML sitemap files rebuilt in @timer ms. Peak memory usage: @memory-peak.', $vars));
}
/**
* Process un-indexed XML sitemap links.
*/
function drush_xmlsitemap_index() {
$limit = (int) drupal_get_option('limit', variable_get('xmlsitemap_batch_limit', 100));
module_invoke_all('xmlsitemap_index_links', $limit);
}
......@@ -7,12 +7,19 @@
* Process old menu links not found in the {xmlsitemap} table.
*/
function xmlsitemap_menu_cron() {
xmlsitemap_menu_xmlsitemap_index_links(xmlsitemap_var('batch_limit'));
}
/**
* Implements hook_xmlsitemap_index_links().
*/
function xmlsitemap_menu_xmlsitemap_index_links($limit) {
if ($menus = xmlsitemap_menu_get_menus()) {
// Set the global user variable to the anonymous user.
xmlsitemap_switch_user(0);
$sql = "SELECT ml.mlid FROM {menu_links} ml LEFT JOIN {xmlsitemap} x ON x.type = 'menu' AND ml.mlid = x.id WHERE x.id IS NULL AND ml.menu_name IN (" . db_placeholders($menus, 'varchar') . ")";
$mlids = db_query_range($sql, 0, xmlsitemap_var('batch_limit'), $menus);
$sql = "SELECT ml.mlid FROM {menu_links} ml LEFT JOIN {xmlsitemap} x ON x.type = 'menu' AND ml.mlid = x.id WHERE x.id IS NULL AND ml.menu_name IN :menus ORDER BY ml.mlid DESC";
$mlids = db_query_range($sql, 0, $limit, array(':menus' => $menus));
foreach ($mlids as $mlid) {
$menu_item = xmlsitemap_menu_menu_link_load($mlid);
......
......@@ -7,12 +7,20 @@
* Process old nodes not found in the {xmlsitemap} table.
*/
function xmlsitemap_node_cron() {
// Start with the most recently changed nodes first.
$nids = db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {xmlsitemap} x ON x.type = 'node' AND n.nid = x.id WHERE x.id IS NULL ORDER BY n.changed DESC", 0, xmlsitemap_var('batch_limit'));
foreach ($nids as $nid) {
$node = node_load($nid, NULL, TRUE);
$link = xmlsitemap_node_create_link($node);
xmlsitemap_save_link($link);
xmlsitemap_node_xmlsitemap_index_links(xmlsitemap_var('batch_limit'));
}
/**
* Implements hook_xmlsitemap_index_links().
*/
function xmlsitemap_node_xmlsitemap_index_links($limit) {
if ($types = xmlsitemap_node_get_types()) {
$nids = db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {xmlsitemap} x ON x.type = 'node' AND n.nid = x.id WHERE x.id IS NULL AND n.type IN :types ORDER BY n.nid DESC", 0, $limit, array(':types' => $types));
foreach ($nids as $nid) {
$node = node_load($nid, NULL, TRUE);
$link = xmlsitemap_node_create_link($node);
xmlsitemap_save_link($link);
}
}
}
......@@ -88,7 +96,7 @@ function xmlsitemap_node_form_xmlsitemap_settings_form_alter(&$form, $form_state
'access' => user_access('administer content types'),
);
$node_types = node_get_types('names');
$node_types = node_type_get_names();
foreach ($node_types as $node_type => $node_type_name) {
$node_types[$node_type] = array(
'name' => drupal_ucfirst($node_type_name),
......@@ -231,7 +239,7 @@ function xmlsitemap_node_xmlsitemap_link_info() {
* Fetch an array of node types to be included in the sitemap.
*/
function xmlsitemap_node_get_types() {
$node_types = array_keys(node_get_types('names'));
$node_types = array_keys(node_type_get_names());
foreach ($node_types as $index => $node_type) {
if (!variable_get('xmlsitemap_node_status_' . $node_type, 0)) {
unset($node_types[$index]);
......@@ -313,7 +321,7 @@ function xmlsitemap_node_create_link(&$node) {
*/
function xmlsitemap_node_variables() {
$defaults = array();
$node_types = array_keys(node_get_types('names'));
$node_types = array_keys(node_type_get_names());
foreach ($node_types as $node_type) {
$defaults['xmlsitemap_node_priority_' . $node_type] = 0.5;
$defaults['xmlsitemap_node_status_' . $node_type] = 0;
......
......@@ -7,8 +7,15 @@
* Process old taxonomy terms not found in the {xmlsitemap} table.
*/
function xmlsitemap_taxonomy_cron() {
xmlsitemap_taxonomy_xmlsitemap_index_links(xmlsitemap_var('batch_limit'));
}
/**
* Implements hook_xmlsitemap_index_links().
*/
function xmlsitemap_taxonomy_xmlsitemap_index_links($limit) {
if ($vids = xmlsitemap_taxonomy_get_vids()) {
$tids = db_query_range("SELECT t.tid FROM {term_data} t LEFT JOIN {xmlsitemap} x ON x.type = 'taxonomy' AND t.tid = x.id WHERE x.id IS NULL AND t.vid IN (" . db_placeholders($vids) . ")", 0, xmlsitemap_var('batch_limit'), $vids);
$tids = db_query_range("SELECT t.tid FROM {term_data} t LEFT JOIN {xmlsitemap} x ON x.type = 'taxonomy' AND t.tid = x.id WHERE x.id IS NULL AND t.vid IN :vids ORDER BY t.tid DESC", 0, $limit, array(':vids' => $vids));
foreach ($tids as $tid) {
$term = xmlsitemap_taxonomy_taxonomy_term_load($tid);
$link = xmlsitemap_taxonomy_create_link($term);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment