Commit e62ac579 authored by Dave Reid's avatar Dave Reid
Browse files

by Dave Reid: Drupal 7 port fixing round 5.

parent 3cdfbf69
......@@ -72,7 +72,7 @@ function xmlsitemap_regenerate() {
*/
function _xmlsitemap_regenerate_before() {
// Attempt to increase the available processing time and memory limit.
@set_time_limit(240);
drupal_set_time_limit(240);
_xmlsitemap_set_memory_limit();
// Set a timer so we can track how long this takes.
......@@ -89,13 +89,7 @@ function _xmlsitemap_regenerate_before() {
function _xmlsitemap_get_memory_usage($start = FALSE) {
static $memory_start;
$current = 0;
if (function_exists('memory_get_peak_usage')) {
$current = memory_get_peak_usage(TRUE);
}
if (function_exists('memory_get_usage')) {
$current = version_compare(PHP_VERSION, '5.2') ? memory_get_usage(TRUE) : memory_get_usage();
}
$current = memory_get_peak_usage(TRUE);
if (!isset($memory_start) || $start) {
$memory_start = $current;
}
......@@ -263,29 +257,26 @@ function xmlsitemap_generate_chunk($handle, &$status, $chunk, $language) {
$languages[''] = language_default();
}
$query = array(
'SELECT' => 'SELECT x.loc, x.lastmod, x.changefreq, x.changecount, x.priority, x.language',
'FROM' => 'FROM {xmlsitemap} x',
'WHERE' => 'WHERE x.access = 1 AND x.status = 1',
'ORDER BY' => 'ORDER BY x.language, x.loc',
);
$args = array();
$url_options = xmlsitemap_get_url_options(array('alias' => TRUE));
// Allow other modules to alter the sitemap query SQL and arguments.
$data = &$query;
$data['__drupal_alter_by_ref'] = array(&$args);
drupal_alter('xmlsitemap_query', $data, $language);
$query = db_select('xmlsitemap', 'x');
$query->fields('x', array('loc', 'lastmod', 'changefreq', 'changecount', 'priority', 'language', 'access', 'status'));
$query->condition('access', 1);
$query->condition('status', 1);
$query->orderBy('language', 'DESC');
$query->orderBy('loc');
$query->addTag('xmlsitemap');
$query->addMetaData('language', $language);
$sql = implode($query, ' ');
$url_options = xmlsitemap_get_url_options(array('alias' => TRUE));
$offset = max($chunk - 1, 0) * xmlsitemap_get_chunk_size();
$limit = xmlsitemap_get_chunk_size();
$query = db_query_range($sql, $offset, $limit, $args);
$query->range($offset, $limit);
$links = $query->execute();
// Add the XML header and XSL if desired.
xmlsitemap_generate_chunk_header('urlset', $handle, $status, $language);
while ($link = $query->fetchAssoc()) {
foreach ($links->fetchAssoc() as $link) {
$url_options['language'] = $link['language'] ? $languages[$link['language']] : $language;
$link['alias'] = xmlsitemap_get_path_alias($link['loc'], $url_options['language']->language);
$link_url = url($link['alias'], $url_options);
......@@ -406,18 +397,15 @@ function xmlsitemap_rebuild_batch_clear($modules, $save_custom, &$context) {
}
if ($purge) {
$where = array();
$where[] = 'type IN (' . db_placeholders($purge, 'varchar') . ')';
$query = db_delete('xmlsitemap');
$query->condition('type', $purge);
// If we want to save the custom data, make sure to exclude any links
// that are not using default inclusion or priority.
if ($save_custom) {
$where[] = 'status_override = 0';
$where[] = 'priority_override = 0';
$query->condition('status_override', 0);
$query->condition('priority_override', 0);
}
$sql = "DELETE FROM {xmlsitemap} WHERE " . implode(' AND ', $where);
db_query($sql, $purge);
$query->execute();
}
$context['message'] = t('Purging links.');
......
......@@ -21,15 +21,14 @@ function xmlsitemap_i18n_form_xmlsitemap_settings_form_alter(&$form, $form_state
}
/**
* Implements hook_xmlsitemap_query_alter().
* Implements hook_query_TAG_alter().
*
* @see i18n_db_rewrite_where()
*/
function xmlsitemap_i18n_xmlsitemap_query_alter(array &$query, array &$args, stdClass $language) {
function xmlsitemap_i18n_query_xmlsitemap_alter(QueryAlterableInterface $query) {
// Get languages to simplify query building.
$mode = variable_get('i18n_selection_mode', 'simple');
//$current = i18n_get_lang();
$current = $language->language;
$current = $query->getMetaData('language')->language;
$default = i18n_default_language();
if ($mode == 'mixed' && $current == $default) {
......@@ -40,25 +39,28 @@ function xmlsitemap_i18n_xmlsitemap_query_alter(array &$query, array &$args, std
switch ($mode) {
case 'simple':
// Current language and language neutral.
$query['WHERE'] .= " AND x.language IN ('%s', '')";
$args[] = $current;
$query->condition('language', array($current, ''));
break;
case 'mixed':
// Mixed current language (if available) or default language (if not) and language neutral.
$query['WHERE'] .= " AND x.language IN ('%s', '%s', '')";
$args[] = $current;
$args[] = $default;
$query->condition('language', array($current, $default, ''));
break;
case 'default':
// Only default language and language neutral.
$query['WHERE'] .= " AND x.language IN ('%s', '')";
$args[] = $default;
$query->condition('language', array($default, ''));
break;
case 'strict':
// Only current language (for nodes), simple for all other types.
$query['WHERE'] .= " AND ((x.type = 'node' AND x.language = '%s') OR (x.type <> 'node' AND x.language IN ('%s', '')))";
$args[] = $current;
$args[] = $current;
$node_condition = db_and();
$node_condition->condition('type', 'node');
$node_condition->condition('language', $current);
$normal_condition = db_and();
$normal_condition->condition('type', 'node', '<>');
$normal_condition->condition('language', array($current, ''));
$condition = db_or();
$condition->condition($node_condition);
$condition->condition($normal_condition);
$query->condition($condition);
break;
case 'off':
// All content. No language conditions apply.
......
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