Commit c118b5c9 authored by Dave Reid's avatar Dave Reid

by Dave Reid: Synced API changes from Drupal 6.x-2.x branch.

parent 600d503e
......@@ -333,7 +333,7 @@ function xmlsitemap_update_6() {
}
function xmlsitemap_update_7() {
if (xmlsitemap_load_link(array('type' => 'custom'))) {
if (db_query_range("SELECT 1 FROM {xmlsitemap} WHERE type = 'custom'", 0, 1)->fetchField()) {
drupal_install_modules(array('xmlsitemap_custom'));
}
variable_del('xmlsitemap_custom_links');
......
......@@ -418,14 +418,14 @@ function _xmlsitemap_check_changed_link(array $link, $original_link = NULL, $fla
* An array of sitemap link arrays.
*/
function xmlsitemap_link_load_multiple(array $conditions = array()) {
$query = db_select('xmlsitemap', 'x');
$query->fields('x');
$query = db_select('xmlsitemap');
$query->fields('xmlsitemap');
foreach ($conditions as $field => $value) {
$query->condition($field, $value);
}
$links = $query->execute()->fetchAllAssoc();
$links = $query->execute()->fetchAll(PDO::FETCH_ASSOC);
return $links;
}
......
......@@ -67,14 +67,26 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
$this->assertTrue(variable_get('xmlsitemap_generated_last', 0) && !variable_get('xmlsitemap_regenerate_needed', FALSE), t('XML sitemaps regenerated and flag cleared.'));
}
protected function assertSitemapLink($conditions) {
$link = xmlsitemap_load_link($conditions);
protected function assertSitemapLink($entity_type, $entity_id = NULL) {
if (is_array($entity_type)) {
$links = xmlsitemap_link_load_multiple($entity_type);
$link = $links ? reset($links) : FALSE;
}
else {
$link = xmlsitemap_link_load($entity_type, $entity_id);
}
$this->assertTrue(is_array($link), 'Link loaded.');
return $link;
}
protected function assertNoSitemapLink($conditions) {
$link = xmlsitemap_load_link($conditions);
protected function assertNoSitemapLink($entity_type, $entity_id = NULL) {
if (is_array($entity_type)) {
$links = xmlsitemap_link_load_multiple($entity_type);
$link = $links ? reset($links) : FALSE;
}
else {
$link = xmlsitemap_link_load($entity_type, $entity_id);
}
$this->assertFalse($link, 'Link not loaded.');
return $link;
}
......@@ -486,9 +498,9 @@ class XMLSitemapUnitTest extends XMLSitemapTestHelper {
}
/**
* Tests for xmlsitemap_delete_link().
* Tests for xmlsitemap_link_delete().
*/
function testDeleteLink() {
function testLinkDelete() {
// Add our testing data.
$link1 = $this->addSitemapLink(array('loc' => 'testing1', 'status' => 0));
$link2 = $this->addSitemapLink(array('loc' => 'testing1', 'status' => 1));
......@@ -497,16 +509,16 @@ class XMLSitemapUnitTest extends XMLSitemapTestHelper {
// Test delete multiple links.
// Test that the regenerate flag is set when visible links are deleted.
$deleted = xmlsitemap_delete_link(array('loc' => 'testing1'));
$deleted = xmlsitemap_link_delete_multiple(array('loc' => 'testing1'));
$this->assertEqual($deleted, 2);
$this->assertFalse(xmlsitemap_load_link(array('type' => $link1['type'], 'id' => $link1['id'])));
$this->assertFalse(xmlsitemap_load_link(array('type' => $link2['type'], 'id' => $link2['id'])));
$this->assertTrue(xmlsitemap_load_link(array('type' => $link3['type'], 'id' => $link3['id'])));
$this->assertFalse(xmlsitemap_link_load($link1['type'], $link1['id']));
$this->assertFalse(xmlsitemap_link_load($link2['type'], $link2['id']));
$this->assertTrue(xmlsitemap_link_load($link3['type'], $link3['id']));
$this->assertFlag('regenerate_needed', TRUE);
$deleted = xmlsitemap_delete_link(array('type' => $link3['type'], 'id' => $link3['id']));
$deleted = xmlsitemap_link_delete($link3['type'], $link3['id']);
$this->assertEqual($deleted, 1);
$this->assertFalse(xmlsitemap_load_link(array('type' => $link3['type'], 'id' => $link3['id'])));
$this->assertFalse(xmlsitemap_link_load($link3['type'], $link3['id']));
$this->assertFlag('regenerate_needed', FALSE);
}
......@@ -608,7 +620,7 @@ class XMLSitemapFunctionalTest extends XMLSitemapTestHelper {
$this->drupalGetSitemap();
$this->assertRaw('lifetime-test');
xmlsitemap_delete_link(array('type' => $link['type'], 'id' => $link['id']));
xmlsitemap_link_delete($link['type'], $link['id']);
drupal_cron_run();
$this->drupalGetSitemap();
$this->assertRaw('lifetime-test');
......
<?php
// $Id$
/**
* Implements hook_xmlsitemap_link_info().
*/
function xmlsitemap_menu_xmlsitemap_link_info() {
return array(
'menu' => array(
'purge' => TRUE,
'table' => 'menu_links',
'id' => 'mlid',
'subtype' => 'menu_name',
'subtypes' => xmlsitemap_menu_get_menus(),
),
);
}
/**
* Implements hook_cron().
*
......@@ -68,48 +83,6 @@ function xmlsitemap_menu_xmlsitemap_links_batch_info() {
);
}
/**
* Implements hook_xmlsitemap_link_info().
*/
function xmlsitemap_menu_xmlsitemap_link_info() {
return array(
'menu' => array(
'purge' => TRUE,
'table' => 'menu_links',
'id' => 'mlid',
'subtype' => 'menu_name',
'subtypes' => xmlsitemap_menu_get_menus(),
),
);
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Show a summary of menus on the XML sitemap settings page.
*/
function xmlsitemap_menu_form_xmlsitemap_settings_form_alter(&$form, $form_state) {
$type = array(
'type' => 'menu',
'title' => t('Menus'),
'item_title' => t('Menu'),
'access' => user_access('administer menu'),
);
$menus = menu_get_menus();
foreach ($menus as $menu => $name) {
$menus[$menu] = array(
'name' => $name,
'link' => 'admin/build/menu-customize/' . $menu . '/edit',
'status' => variable_get('xmlsitemap_menu_status_' . $menu, 0),
'priority' => variable_get('xmlsitemap_menu_priority_' . $menu, 0.5),
);
}
xmlsitemap_add_form_type_summary($form, $type, $menus);
$form['menu']['#weight'] = 40;
}
/**
* Implements hook_form_FORM_ID_alter().
*
......@@ -259,7 +232,7 @@ function xmlsitemap_menu_get_menus() {
function xmlsitemap_menu_create_link(array $menu_item) {
if (!isset($menu_item['xmlsitemap'])) {
$menu_item['xmlsitemap'] = array();
if ($menu_item['mlid'] && $link = xmlsitemap_load_link('menu', $menu_item['mlid'])) {
if ($menu_item['mlid'] && $link = xmlsitemap_link_load('menu', $menu_item['mlid'])) {
$menu_item['xmlsitemap'] = $link;
}
}
......
<?php
// $Id$
/**
* Implements hook_xmlsitemap_link_info().
*/
function xmlsitemap_node_xmlsitemap_link_info() {
return array(
'node' => array(
'purge' => TRUE,
'table' => 'node',
'id' => 'nid',
'subtype' => 'type',
'subtypes' => xmlsitemap_node_get_types(),
),
);
}
/**
* Implements hook_cron().
*
......@@ -85,33 +100,6 @@ function xmlsitemap_node_node_type_delete($info) {
//xmlsitemap_link_delete_multiple(array('type' => 'node', 'subtype' => $info->type));
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Show a summary of content types on the XML sitemap settings page.
*/
function xmlsitemap_node_form_xmlsitemap_settings_form_alter(&$form, $form_state) {
$type = array(
'type' => 'node',
'title' => t('Content types'),
'item_title' => t('Content type'),
'access' => user_access('administer content types'),
);
$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),
'link' => 'admin/structure/types/manage/' . str_replace('_', '-', $node_type),
'status' => variable_get('xmlsitemap_node_status_' . $node_type, 0),
'priority' => variable_get('xmlsitemap_node_priority_' . $node_type, 0.5),
);
}
xmlsitemap_add_form_type_summary($form, $type, $node_types);
$form['node']['#weight'] = 30;
}
/**
* Implements hook_form_FORM_ID_alter().
*
......@@ -209,21 +197,6 @@ function xmlsitemap_node_xmlsitemap_links_batch_info() {
);
}
/**
* Implements hook_xmlsitemap_link_info().
*/
function xmlsitemap_node_xmlsitemap_link_info() {
return array(
'node' => array(
'purge' => TRUE,
'table' => 'node',
'id' => 'nid',
'subtype' => 'type',
'subtypes' => xmlsitemap_node_get_types(),
),
);
}
/**
* Fetch an array of node types to be included in the sitemap.
*/
......
<?php
// $Id$
/**
* Implements hook_xmlsitemap_link_info().
*/
function xmlsitemap_taxonomy_xmlsitemap_link_info() {
return array(
'taxononomy' => array(
'purge' => TRUE,
'table' => 'term_data',
'id' => 'tid',
'subtype' => 'vid',
'subtypes' => xmlsitemap_taxonomy_get_vids(),
),
);
}
/**
* Implements hook_cron().
*
......@@ -54,48 +69,6 @@ function xmlsitemap_taxonomy_xmlsitemap_links_batch_info() {
);
}
/**
* Implements hook_xmlsitemap_link_info().
*/
function xmlsitemap_taxonomy_xmlsitemap_link_info() {
return array(
'taxononomy' => array(
'purge' => TRUE,
'table' => 'term_data',
'id' => 'tid',
'subtype' => 'vid',
'subtypes' => xmlsitemap_taxonomy_get_vids(),
),
);
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Show a summary of vocabularies on the XML sitemap settings page.
*/
function xmlsitemap_taxonomy_form_xmlsitemap_settings_form_alter(&$form, $form_state) {
$type = array(
'type' => 'taxonomy_term',
'title' => t('Taxonomy'),
'item_title' => t('Vocabulary'),
'access' => user_access('administer taxonomy'),
);
$vocabularies = taxonomy_get_vocabularies();
foreach ($vocabularies as $vid => $vocabulary) {
$vocabularies[$vid] = array(
'name' => $vocabulary->name,
'link' => 'admin/content/taxonomy/edit/vocabulary/' . $vid,
'status' => xmlsitemap_taxonomy_var('status_' . $vid),
'priority' => xmlsitemap_taxonomy_var('priority_' . $vid),
);
}
xmlsitemap_add_form_type_summary($form, $type, $vocabularies);
$form['taxonomy_term']['#weight'] = 40;
}
/**
* Implements hook_form_FORM_ID_alter().
*
......@@ -222,7 +195,7 @@ function xmlsitemap_taxonomy_taxonomy($op, $type, $array = NULL) {
function xmlsitemap_taxonomy_create_link(stdClass $term) {
if (!isset($term->xmlsitemap)) {
$term->xmlsitemap = array();
if ($term->tid && $link = xmlsitemap_load_link(array('type' => 'taxonomy_term', 'id' => $term->tid))) {
if ($term->tid && $link = xmlsitemap_link_load('taxonomy_term', $term->tid)) {
$term->xmlsitemap = $link;
}
}
......
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