Commit 87693800 authored by Dave Reid's avatar Dave Reid

by Dave Reid: Provide a better context upgrade path and a default sitemap with...

by Dave Reid: Provide a better context upgrade path and a default sitemap with empty context on module install.
parent 5dfe21f8
......@@ -103,97 +103,6 @@ function xmlsitemap_requirements($phase) {
return $requirements;
}
/**
* Check the status of all hook_requirements() from xmlsitemap modules.
*/
function xmlsitemap_check_status() {
$messages = &drupal_static(__FUNCTION__);
if (!isset($messages)) {
// Cache the list of modules that are checked.
if ($cache = cache_get('xmlsitemap:status:modules')) {
$modules = $cache->data;
}
else {
$modules = array();
foreach (module_implements('requirements') as $module) {
if (strpos($module, 'xmlsitemap') !== FALSE) {
$modules[] = $module;
}
}
cache_set('xmlsitemap:status:modules', $modules);
}
$messages = array();
foreach ($modules as $module) {
module_load_install($module);
$requirements = module_invoke($module, 'requirements', 'runtime');
foreach ($requirements as $requirement) {
if (isset($requirement['severity']) && max(REQUIREMENT_OK, $requirement['severity'])) {
$messages[] = $requirement['description'];
}
}
}
if ($messages) {
$message = t('One or more problems were detected with your XML sitemap configuration: !messages', array('!messages' => theme('item_list', array('items' => $messages))));
if (user_access('access site reports')) {
$message .= t('Check the <a href="@status-report">status report</a> for more information.', array('@status-report' => url('admin/reports/status')));
}
drupal_set_message($message, 'warning', FALSE);
}
}
return !empty($messages);
}
/**
* Implements hook_install().
*/
function xmlsitemap_install() {
// Set this module's weight to 1 so xmlsitemap_cron() runs after all other
// xmlsitemap_x_cron() runs.
db_update('system')
->fields(array('weight' => 1))
->condition('type', 'module')
->condition('name', 'xmlsitemap')
->execute();
// Load the module so we can use xmlsitemap_var().
drupal_load('module', 'xmlsitemap');
// Add files directory.
xmlsitemap_check_directory();
// Insert the homepage link into the {xmlsitemap} table so we do not show an
// empty sitemap after install.
db_query("INSERT INTO {xmlsitemap} (type, id, loc, priority, changefreq, language) VALUES ('frontpage', 0, '', :priority, :changefreq, :language)", array(':priority' => variable_get('xmlsitemap_frontpage_priority', 1.0), 'changefreq' => variable_get('xmlsitemap_frontpage_changefreq', 86400), ':language' => LANGUAGE_NONE));
// @todo Does the sitemap show up on first install or is it a 404 page?
}
/**
* Implements hook_enable().
*/
function xmlsitemap_enable() {
variable_set('xmlsitemap_regenerate_needed', TRUE);
}
/**
* Implements hook_uninstall().
*/
function xmlsitemap_uninstall() {
// Remove variables.
drupal_load('module', 'xmlsitemap');
$variables = array_keys(xmlsitemap_variables());
foreach ($variables as $variable) {
variable_del($variable);
}
// Remove files directory.
xmlsitemap_clear_directory(TRUE);
}
/**
* Implements hook_schema().
*/
......@@ -353,6 +262,113 @@ function xmlsitemap_schema() {
return $schema;
}
/**
* Implements hook_install().
*/
function xmlsitemap_install() {
// Set this module's weight to 1 so xmlsitemap_cron() runs after all other
// xmlsitemap_x_cron() runs.
db_update('system')
->fields(array('weight' => 1))
->condition('type', 'module')
->condition('name', 'xmlsitemap')
->execute();
// Load the module and clear the schema cache.
drupal_load('module', 'xmlsitemap');
drupal_get_schema(NULL, TRUE);
// Insert the homepage link into the {xmlsitemap} table so we do not show an
// empty sitemap after install.
// @todo Use xmlsitemap_save_link()?
db_insert('xmlsitemap')
->fields(array(
'type' => 'frontpage',
'id' => 0,
'loc' => '',
'priority' => variable_get('xmlsitemap_frontpage_priority', 1.0),
'changefreq' => XMLSITEMAP_FREQUENCY_DAILY,
'language' => LANGUAGE_NONE,
))
->execute();
// Insert the default context sitemap.
$sitemap = array('context' => array());
xmlsitemap_sitemap_save($sitemap);
// @todo Does the sitemap show up on first install or is it a 404 page?
}
/**
* Implements hook_enable().
*/
function xmlsitemap_enable() {
// Load the module and ensure the file cache directory is available and ready.
drupal_load('module', 'xmlsitemap');
xmlsitemap_check_directory();
variable_set('xmlsitemap_regenerate_needed', TRUE);
}
/**
* Implements hook_uninstall().
*/
function xmlsitemap_uninstall() {
// Remove variables.
drupal_load('module', 'xmlsitemap');
$variables = array_keys(xmlsitemap_variables());
foreach ($variables as $variable) {
variable_del($variable);
}
// Remove the file cache directory.
xmlsitemap_clear_directory(TRUE);
}
/**
* Check the status of all hook_requirements() from xmlsitemap modules.
*/
function xmlsitemap_check_status() {
$messages = &drupal_static(__FUNCTION__);
if (!isset($messages)) {
// Cache the list of modules that are checked.
if ($cache = cache_get('xmlsitemap:status:modules')) {
$modules = $cache->data;
}
else {
$modules = array();
foreach (module_implements('requirements') as $module) {
if (strpos($module, 'xmlsitemap') !== FALSE) {
$modules[] = $module;
}
}
cache_set('xmlsitemap:status:modules', $modules);
}
$messages = array();
foreach ($modules as $module) {
module_load_install($module);
$requirements = module_invoke($module, 'requirements', 'runtime');
foreach ($requirements as $requirement) {
if (isset($requirement['severity']) && max(REQUIREMENT_OK, $requirement['severity'])) {
$messages[] = $requirement['description'];
}
}
}
if ($messages) {
$message = t('One or more problems were detected with your XML sitemap configuration: !messages', array('!messages' => theme('item_list', array('items' => $messages))));
if (user_access('access site reports')) {
$message .= t('Check the <a href="@status-report">status report</a> for more information.', array('@status-report' => url('admin/reports/status')));
}
drupal_set_message($message, 'warning', FALSE);
}
}
return !empty($messages);
}
/**
* Implements hook_update_last_removed().
*/
......@@ -361,57 +377,75 @@ function xmlsitemap_update_last_removed() {
}
/**
* Create the {xmlsitemap_sitemap} table.
* Create the {xmlsitemap_sitemap} table and add the sitemap context data.
*/
function xmlsitemap_update_6202() {
if (db_table_exists('xmlsitemap_sitemap')) {
return;
}
$schema['xmlsitemap_sitemap'] = array(
'fields' => array(
'smid' => array(
'description' => 'Sitemap ID',
'type' => 'serial',
'not null' => TRUE,
),
'context_hash' => array(
'description' => 'The MD5 hash of the context field.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'context' => array(
'description' => 'Serialized array with the sitemaps context',
'type' => 'text',
'not null' => TRUE,
),
'updated' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'links' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
if (!db_table_exists('xmlsitemap_sitemap')) {
$schema['xmlsitemap_sitemap'] = array(
'fields' => array(
'smid' => array(
'description' => 'Sitemap ID',
'type' => 'serial',
'not null' => TRUE,
),
'context_hash' => array(
'description' => 'The MD5 hash of the context field.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'context' => array(
'description' => 'Serialized array with the sitemaps context',
'type' => 'text',
'not null' => TRUE,
),
'updated' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'links' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'chunks' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'chunks' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'primary key' => array('smid'),
'unique keys' => array(
'context_hash' => array('context_hash'),
),
),
'primary key' => array('smid'),
'unique keys' => array(
'context_hash' => array('context_hash'),
),
);
db_create_table('xmlsitemap_sitemap', $schema['xmlsitemap_sitemap']);
);
db_create_table('xmlsitemap_sitemap', $schema['xmlsitemap_sitemap']);
}
// Add the default sitemap(s) and use language contexts if possible.
if (!db_query("SELECT COUNT(smid) FROM {xmlsitemap_sitemap}")->fetchField()) {
// Refresh the schema.
drupal_get_schema(NULL, TRUE);
if (module_exists('xmlsitemap_i18n') && $languages = variable_get('xmlsitemap_languages', array())) {
foreach ($languages as $language) {
$sitemap = array('context' => array('language' => $language));
xmlsitemap_sitemap_save($sitemap);
}
}
else {
$sitemap = array('context' => array());
xmlsitemap_sitemap_save($sitemap);
}
}
// Language variable is no longer needed, so go ahead and delete it.
variable_del('xmlsitemap_languages');
}
/**
......@@ -423,3 +457,10 @@ function xmlsitemap_update_7200() {
->condition('language', '')
->execute();
}
/**
* Re-run xmlsitemap_update_6202() to ensure sitemap data has been added.
*/
function xmlsitemap_update_7201() {
xmlsitemap_update_6202();
}
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