Commit ef8f4711 authored by Dave Reid's avatar Dave Reid

by Dave Reid: Drupal 7 port fixing round 6.

parent 9cfd3e58
......@@ -87,24 +87,6 @@ function hook_xmlsitemap_link_alter(&$link) {
}
}
/**
* Alter the query selecting data from {xmlsitemap} during sitemap generation.
*
* Do not alter LIMIT or OFFSET as the query will be passed through
* db_query_range() with a set limit and offset.
*
* @param $query
* An array of a query object, keyed by SQL keyword (SELECT, FROM, WHERE, etc).
* @param $args
* An array of arguments to be passed to db_query() with $query.
* @param $language
* The language object being used for sitemap generation.
*/
function hook_xmlsitemap_query_alter(array &$query, array &$args, stdClass $language) {
$query['WHERE'] .= " AND x.language = '%s'";
$args[] = $language->language;
}
/**
* @} End of "addtogroup hooks".
*/
......@@ -25,19 +25,19 @@ function xmlsitemap_get_path_alias($path, $language) {
static $last_language;
if (!isset($aliases)) {
$aliases['all'] = db_query("SELECT source, alias FROM {url_alias} WHERE language = '' ORDER BY pid")->fetchAllKeyed();
$aliases[LANGUAGE_NONE] = db_query("SELECT source, alias FROM {url_alias} WHERE language = :language ORDER BY pid", array(':language' => LANGUAGE_NONE))->fetchAllKeyed();
}
if ($language && $last_language != $language) {
if ($language != LANGUAGE_NONE && $last_language != $language) {
unset($aliases[$last_language]);
$aliases[$language] = db_query("SELECT source, alias FROM {url_alias} WHERE language = :language ORDER BY pid", array(':language' => $language))->fetchAllKeyed();
$last_language = $language;
}
if ($language && isset($aliases[$language][$path])) {
if ($language != LANGUAGE_NONE && isset($aliases[$language][$path])) {
return $aliases[$language][$path];
}
elseif (isset($aliases['all'][$path])) {
return $aliases['all'][$path];
elseif (isset($aliases[LANGUAGE_NONE][$path])) {
return $aliases[LANGUAGE_NONE][$path];
}
else {
return $path;
......@@ -106,8 +106,7 @@ function _xmlsitemap_get_optimal_memory_limit() {
$optimal_limit += xmlsitemap_get_chunk_size() * 500;
// Add memory for storing the url aliases.
$aliases = db_query("SELECT COUNT(pid) FROM {url_alias} WHERE language = ''")->fetchField();
$aliases += db_query("SELECT COUNT(pid) as pid_count FROM {url_alias} WHERE language <> '' GROUP BY language ORDER BY pid_count DESC")->fetchField();
$aliases = db_query("SELECT COUNT(pid) FROM {url_alias}")->fetchField();
$optimal_limit += $aliases * 250;
}
return $optimal_limit;
......@@ -254,7 +253,7 @@ function xmlsitemap_generate_chunk($handle, &$status, $chunk, $language) {
if (!isset($languages)) {
$languages = language_list();
$languages[''] = language_default();
$languages[LANGUAGE_NONE] = language_default();
}
$url_options = xmlsitemap_get_url_options(array('alias' => TRUE));
......@@ -277,7 +276,7 @@ function xmlsitemap_generate_chunk($handle, &$status, $chunk, $language) {
xmlsitemap_generate_chunk_header('urlset', $handle, $status, $language);
foreach ($links->fetchAssoc() as $link) {
$url_options['language'] = $link['language'] ? $languages[$link['language']] : $language;
$url_options['language'] = $link['language'] != LANGUAGE_NONE ? $languages[$link['language']] : $language;
$link['alias'] = xmlsitemap_get_path_alias($link['loc'], $url_options['language']->language);
$link_url = url($link['alias'], $url_options);
......
......@@ -440,7 +440,7 @@ function xmlsitemap_save_link(array $link) {
'priority_override' => 0,
'changefreq' => 0,
'changecount' => 0,
'language' => '',
'language' => LANGUAGE_NONE,
);
// Allow other modules to alter the link before saving.
......
......@@ -43,12 +43,12 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
}
}
protected function getLanguageObj($langcode = '', $reset = FALSE) {
protected function getLanguageObj($langcode = LANGUAGE_NONE, $reset = FALSE) {
static $languages;
if (!isset($languages) || $reset) {
$languages = language_list('language', TRUE);
$languages[''] = NULL;
$languages[LANGUAGE_NONE] = NULL;
}
return $languages[$langcode];
......@@ -84,7 +84,7 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
return $link;
}
protected function drupalGetSitemap($language = '', $regenerate = FALSE) {
protected function drupalGetSitemap($language = LANGUAGE_NONE, $regenerate = FALSE) {
if ($regenerate) {
$this->regenerateSitemap();
}
......
......@@ -44,7 +44,7 @@ function xmlsitemap_custom_edit_link_form($form_state, $link = array()) {
'lastmod' => 0,
'changefreq' => 0,
'changecount' => 0,
'language' => '',
'language' => LANGUAGE_NONE,
);
$form['type'] = array(
......@@ -82,7 +82,7 @@ function xmlsitemap_custom_edit_link_form($form_state, $link = array()) {
'#type' => 'select',
'#title' => t('Language'),
'#default_value' => $link['language'],
'#options' => array('' => t('Language neutral')) + $languages,
'#options' => array(LANGUAGE_NONE => t('Language neutral')) + $languages,
'#access' => $languages,
);
......@@ -121,7 +121,7 @@ function xmlsitemap_custom_edit_link_form_validate(&$form, &$form_state) {
$menu_item['access'] = FALSE;
}
if (db_query_range("SELECT 1 FROM {xmlsitemap} WHERE type <> 'custom' AND loc = :loc AND status = 1 AND access = 1 AND language IN (:language, '')", 0, 1, array(':loc' => $link['loc'], ':language' => $link['language']))->fetchField()) {
if (db_query_range("SELECT 1 FROM {xmlsitemap} WHERE type <> 'custom' AND loc = :loc AND status = 1 AND access = 1 AND language IN (:languages)", 0, 1, array(':loc' => $link['loc'], ':languages' => array(LANGUAGE_NONE, $link['language'])))->fetchField()) {
form_set_error('loc', t('There is already an existing link in the sitemap with the path %link.', array('%link' => $link['loc'])));
}
elseif (empty($menu_item['access']) && !is_readable('./' . $link['loc'])) {
......
......@@ -37,7 +37,7 @@ class XMLSitemapCustomFunctionalTest extends XMLSitemapTestHelper {
$this->assertNotInSitemap(array('type' => 'custom', 'loc' => $edit['loc']));
// Test a path not accessible to anonymous user.
$edit['loc'] = 'admin/user/user';
$edit['loc'] = 'admin/config/people/accounts';
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertText(t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', array('@link' => $edit['loc'])));
$this->assertNotInSitemap(array('type' => 'custom', 'loc' => $edit['loc']));
......
......@@ -39,15 +39,15 @@ function xmlsitemap_i18n_query_xmlsitemap_alter(QueryAlterableInterface $query)
switch ($mode) {
case 'simple':
// Current language and language neutral.
$query->condition('language', array($current, ''));
$query->condition('language', array($current, LANGUAGE_NONE));
break;
case 'mixed':
// Mixed current language (if available) or default language (if not) and language neutral.
$query->condition('language', array($current, $default, ''));
$query->condition('language', array($current, $default, LANGUAGE_NONE));
break;
case 'default':
// Only default language and language neutral.
$query->condition('language', array($default, ''));
$query->condition('language', array($default, LANGUAGE_NONE));
break;
case 'strict':
// Only current language (for nodes), simple for all other types.
......@@ -56,7 +56,7 @@ function xmlsitemap_i18n_query_xmlsitemap_alter(QueryAlterableInterface $query)
$node_condition->condition('language', $current);
$normal_condition = db_and();
$normal_condition->condition('type', 'node', '<>');
$normal_condition->condition('language', array($current, ''));
$normal_condition->condition('language', array($current, LANGUAGE_NONE));
$condition = db_or();
$condition->condition($node_condition);
$condition->condition($normal_condition);
......
......@@ -43,12 +43,12 @@ class XMLSitemapI18nTest extends XMLSitemapI18nWebTestCase {
function testLanguageSelection() {
// Create our three different language nodes.
$node = $this->addSitemapLink(array('type' => 'node', 'language' => ''));
$node = $this->addSitemapLink(array('type' => 'node', 'language' => LANGUAGE_NONE));
$node_en = $this->addSitemapLink(array('type' => 'node', 'language' => 'en'));
$node_fr = $this->addSitemapLink(array('type' => 'node', 'language' => 'fr'));
// Create three non-node language nodes.
$link = $this->addSitemapLink(array('language' => ''));
$link = $this->addSitemapLink(array('language' => LANGUAGE_NONE));
$link_en = $this->addSitemapLink(array('language' => 'en'));
$link_fr = $this->addSitemapLink(array('language' => 'fr'));
......
......@@ -280,7 +280,7 @@ function xmlsitemap_menu_create_link(array $menu_item) {
// The following values must always be checked because they are volatile.
$menu_item['xmlsitemap']['subtype'] = $menu_item['menu_name'];
$menu_item['xmlsitemap']['access'] = $menu_item['access'] && !$menu_item['external'] && !$menu_item['hidden'];
$menu_item['xmlsitemap']['language'] = isset($menu_item['options']['langcode']) ? $menu_item['options']['langcode'] : '';
$menu_item['xmlsitemap']['language'] = isset($menu_item['options']['langcode']) ? $menu_item['options']['langcode'] : LANGUAGE_NONE;
return $menu_item['xmlsitemap'];
}
......
......@@ -321,7 +321,7 @@ function xmlsitemap_node_create_link(&$node) {
// The following values must always be checked because they are volatile.
$node->xmlsitemap['lastmod'] = isset($node->changed) ? $node->changed : REQUEST_TIME;
$node->xmlsitemap['access'] = $node->nid ? (bool) node_access('view', $node, drupal_anonymous_user()) : 1;
$node->xmlsitemap['language'] = isset($node->language) ? $node->language : '';
$node->xmlsitemap['language'] = isset($node->language) ? $node->language : LANGUAGE_NONE;
return $node->xmlsitemap;
}
......
......@@ -248,7 +248,7 @@ function xmlsitemap_taxonomy_create_link(stdClass $term) {
// The following values must always be checked because they are volatile.
// @todo How can/should we check taxonomy term access?
$term->xmlsitemap['access'] = 1;
$term->xmlsitemap['language'] = isset($term->language) ? $term->language : '';
$term->xmlsitemap['language'] = isset($term->language) ? $term->language : LANGUAGE_NONE;
return $term->xmlsitemap;
}
......
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