| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: xmlsitemap.install,v 1.5.2.38.2.88 2010/04/29 16:22:09 davereid Exp $ 3 4 /** 5 * @file 6 * Install, update and uninstall functions for the xmlsitemap module. 7 * 8 * @ingroup xmlsitemap 9 */ 10 11 /** 12 * Implements hook_requirements(). 13 */ 14 function xmlsitemap_requirements($phase) { 15 $requirements = array(); 16 $t = get_t(); 17 18 if (variable_get('clean_url', 0) && file_exists('./sitemap.xml')) { 19 $requirements['xmlsitemap_file'] = array( 20 'title' => $t('XML sitemap'), 21 'value' => $t('Existing sitemap.xml file found.'), 22 'severity' => REQUIREMENT_ERROR, 23 'description' => $t('The XML sitemap module cannot display its XML output if there is an existing sitemap.xml file in your website root.'), 24 ); 25 } 26 27 if ($phase == 'runtime') { 28 if (!user_access('access content', drupal_anonymous_user())) { 29 $requirements['xmlsitemap_access'] = array( 30 'title' => $t('XML sitemap anonymous content access'), 31 'value' => $t('Access denied'), 32 'description' => $t('In order to allow search engines to view the XML sitemap and content on your site, the anonymous user role must have the <a href="@perm-link">%permission</a> permission.', array('@perm-link' => url('admin/user/permissions/' . DRUPAL_ANONYMOUS_RID, array('fragment' => 'module-node')), '%permission' => 'access content')), 33 'severity' => REQUIREMENT_ERROR, 34 ); 35 } 36 if (!xmlsitemap_check_directory()) { 37 $requirements['xmlsitemap_directory'] = array( 38 'title' => $t('XML sitemap cache directory'), 39 'value' => $t('Not found or not writable'), 40 'severity' => REQUIREMENT_ERROR, 41 'description' => xmlsitemap_get_directory(), 42 ); 43 } 44 $max_links = XMLSITEMAP_MAX_SITEMAP_LINKS * XMLSITEMAP_MAX_SITEMAP_LINKS; 45 if (xmlsitemap_get_link_count() > $max_links) { 46 $requirements['xmlsitemap_link_count'] = array( 47 'title' => $t('XML sitemap link count'), 48 'value' => xmlsitemap_get_link_count(), 49 'description' => $t('You have exceeded the number of links that your sitemap can contain (@num).', array('@num' => number_format($max_links))), 50 'severity' => REQUIREMENT_ERROR, 51 ); 52 } 53 if (xmlsitemap_get_chunk_count() > XMLSITEMAP_MAX_SITEMAP_LINKS) { 54 $requirements['xmlsitemap_chunk_count'] = array( 55 'title' => $t('XML sitemap page count'), 56 'value' => xmlsitemap_get_chunk_count(), 57 'description' => $t('You have exceeded the number of sitemap pages (@number).', array('@number' => number_format(XMLSITEMAP_MAX_SITEMAP_LINKS))), 58 'severity' => REQUIREMENT_ERROR, 59 ); 60 if (!in_array(xmlsitemap_get_chunk_size(), array(50000, 'auto'))) { 61 $requirements['xmlsitemap_chunk_count']['description'] .= ' ' . t('Please increase the number of links per page.'); 62 } 63 } 64 65 // Check maximum file size. 66 $max_filesize = variable_get('xmlsitemap_max_filesize', 0); 67 $requirements['xmlsitemap_file_size'] = array( 68 'title' => $t('XML sitemap maximum file size'), 69 'value' => format_size($max_filesize), 70 ); 71 if ($max_filesize > XMLSITEMAP_MAX_SITEMAP_FILESIZE) { 72 $requirements['xmlsitemap_file_size']['description'] = $t('You have exceeded the maximum sitemap file size of @size. If possible, decrease the number of links per sitemap page.', array('@size' => format_size(XMLSITEMAP_MAX_SITEMAP_FILESIZE))); 73 $requirements['xmlsitemap_file_size']['severity'] = REQUIREMENT_ERROR; 74 } 75 elseif (!variable_get('xmlsitemap_developer_mode', 0)) { 76 unset($requirements['xmlsitemap_file_size']); 77 } 78 79 // Check when the cached files were last generated. 80 $generated_last = xmlsitemap_var('generated_last'); 81 $generated_ago = REQUEST_TIME - $generated_last; 82 $requirements['xmlsitemap_generated'] = array( 83 'title' => $t('XML sitemap'), 84 'value' => $generated_last ? $t('Last generated on !date (!interval ago).', array('!date' => format_date($generated_last, 'small'), '!interval' => format_interval($generated_ago))) : $t('Cached files have not been generated yet.'), 85 'severity' => REQUIREMENT_OK, 86 ); 87 if (xmlsitemap_var('rebuild_needed')) { 88 $requirements['xmlsitemap_generated']['severity'] = REQUIREMENT_ERROR; 89 $requirements['xmlsitemap_generated']['description'] = $t('The XML sitemap data is out of sync and needs to be <a href="@link-rebuild">completely rebuilt</a>.', array('@link-rebuild' => url('admin/settings/xmlsitemap/rebuild'))); 90 } 91 elseif (xmlsitemap_var('regenerate_needed')) { 92 if ($generated_ago >= variable_get('cron_threshold_error', 1209600)) { 93 $requirements['xmlsitemap_generated']['severity'] = REQUIREMENT_ERROR; 94 } 95 elseif ($generated_ago >= variable_get('cron_threshold_warning', 172800)) { 96 $requirements['xmlsitemap_generated']['severity'] = REQUIREMENT_WARNING; 97 } 98 if ($requirements['xmlsitemap_generated']['severity']) { 99 $requirements['xmlsitemap_generated']['description'] = $t('The XML cached files are out of date and need to be regenerated. You can <a href="@link-cron">run cron manually</a> to regenerate the sitemap files.', array('@link-cron' => url('admin/reports/status/run-cron', array('query' => drupal_get_destination())))); 100 } 101 } 102 } 103 return $requirements; 104 } 105 106 /** 107 * Implements hook_schema(). 108 */ 109 function xmlsitemap_schema() { 110 // @todo Rename to xmlsitemap_link 111 $schema['xmlsitemap'] = array( 112 'description' => 'The base table for xmlsitemap links.', 113 'fields' => array( 114 'id' => array( 115 'description' => 'Primary key with type; a unique id for the item.', 116 'type' => 'int', 117 'not null' => TRUE, 118 'unsigned' => TRUE, 119 'default' => 0, 120 ), 121 'type' => array( 122 'description' => 'Primary key with id; the type of item (e.g. node, user, etc.).', 123 'type' => 'varchar', 124 'length' => 32, 125 'not null' => TRUE, 126 'default' => '', 127 ), 128 'subtype' => array( 129 'description' => 'A sub-type identifier for the link (node type, menu name, term VID, etc.).', 130 'type' => 'varchar', 131 'length' => 128, 132 'not null' => TRUE, 133 'default' => '', 134 ), 135 'loc' => array( 136 'description' => 'The URL to the item relative to the Drupal path.', 137 'type' => 'varchar', 138 'length' => 255, 139 'not null' => TRUE, 140 'default' => '', 141 ), 142 'language' => array( 143 'description' => 'The {languages}.language of this link or an empty string if it is language-neutral.', 144 'type' => 'varchar', 145 'length' => 12, 146 'not null' => TRUE, 147 'default' => '', 148 ), 149 'access' => array( 150 'description' => 'A boolean that represents if the item is viewable by the anonymous user. This field is useful to store the result of node_access() so we can retain changefreq and priority_override information.', 151 'type' => 'int', 152 'size' => 'tiny', 153 'not null' => TRUE, 154 'default' => 1, 155 ), 156 'status' => array( 157 'description' => 'An integer that represents if the item is included in the sitemap.', 158 'type' => 'int', 159 'size' => 'tiny', 160 'not null' => TRUE, 161 'default' => 1, 162 ), 163 'status_override' => array( 164 'description' => 'A boolean that if TRUE means that the status field has been overridden from its default value.', 165 'type' => 'int', 166 'size' => 'tiny', 167 'not null' => TRUE, 168 'default' => 0, 169 ), 170 'lastmod' => array( 171 'description' => 'The UNIX timestamp of last modification of the item.', 172 'type' => 'int', 173 'unsigned' => TRUE, 174 'not null' => TRUE, 175 'default' => 0, 176 ), 177 'priority' => array( 178 'description' => 'The priority of this URL relative to other URLs on your site. Valid values range from 0.0 to 1.0.', 179 'type' => 'float', 180 'default' => NULL, 181 // @todo Convert this field to non-nullable. 182 //'default' => 0.5, 183 //'not null' => NULL, 184 ), 185 'priority_override' => array( 186 'description' => 'A boolean that if TRUE means that the priority field has been overridden from its default value.', 187 'type' => 'int', 188 'size' => 'tiny', 189 'not null' => TRUE, 190 'default' => 0, 191 ), 192 'changefreq' => array( 193 'description' => 'The average time in seconds between changes of this item.', 194 'type' => 'int', 195 'unsigned' => TRUE, 196 'not null' => TRUE, 197 'default' => 0, 198 ), 199 'changecount' => array( 200 'description' => 'The number of times this item has been changed. Used to help calculate the next changefreq value.', 201 'type' => 'int', 202 'unsigned' => TRUE, 203 'not null' => TRUE, 204 'default' => 0, 205 ), 206 ), 207 'primary key' => array('id', 'type'), 208 'indexes' => array( 209 'loc' => array('loc'), 210 'access_status_loc' => array('access', 'status', 'loc'), 211 'type_subtype' => array('type', 'subtype'), 212 'language' => array('language'), 213 ), 214 ); 215 216 $schema['xmlsitemap_sitemap'] = array( 217 'fields' => array( 218 'smid' => array( 219 'description' => 'Sitemap ID', 220 'type' => 'serial', 221 'unsigned' => TRUE, 222 'not null' => TRUE, 223 ), 224 'context_hash' => array( 225 'description' => 'The MD5 hash of the context field.', 226 'type' => 'varchar', 227 'length' => 32, 228 'not null' => TRUE, 229 'default' => '', 230 ), 231 'context' => array( 232 'description' => 'Serialized array with the sitemaps context', 233 'type' => 'text', 234 'not null' => TRUE, 235 'serialize' => TRUE, 236 ), 237 'updated' => array( 238 'type' => 'int', 239 'unsigned' => TRUE, 240 'not null' => TRUE, 241 'default' => 0, 242 ), 243 'links' => array( 244 'type' => 'int', 245 'unsigned' => TRUE, 246 'not null' => TRUE, 247 'default' => 0, 248 ), 249 'chunks' => array( 250 'type' => 'int', 251 'unsigned' => TRUE, 252 'not null' => TRUE, 253 'default' => 0, 254 ), 255 //'queued' => array( 256 // 'type' => 'int', 257 // 'unsigned' => TRUE, 258 // 'not null' => TRUE, 259 // 'default' => 0, 260 // 'description' => 'Time when this sitemap was queued for regeneration, 0 if not queued.', 261 //), 262 ), 263 'primary key' => array('smid'), 264 'unique keys' => array( 265 'context_hash' => array('context_hash'), 266 ), 267 ); 268 269 return $schema; 270 } 271 272 /** 273 * Implements hook_install(). 274 */ 275 function xmlsitemap_install() { 276 // Add tables. 277 drupal_install_schema('xmlsitemap'); 278 279 // Set this module's weight to 1 so xmlsitemap_cron() runs after all other 280 // xmlsitemap_x_cron() runs. 281 db_query("UPDATE {system} SET weight = 1 WHERE type = 'module' AND name = 'xmlsitemap'"); 282 283 // Load the module. 284 drupal_load('module', 'xmlsitemap'); 285 286 // Insert the homepage link into the {xmlsitemap} table so we do not show an 287 // empty sitemap after install. 288 db_query("INSERT INTO {xmlsitemap} (type, id, loc, priority, changefreq) VALUES ('frontpage', 0, '', %f, %d)", variable_get('xmlsitemap_frontpage_priority', 1.0), variable_get('xmlsitemap_frontpage_changefreq', XMLSITEMAP_FREQUENCY_DAILY)); 289 290 // Insert the default context sitemap. 291 $context = serialize(array()); 292 db_query("INSERT INTO {xmlsitemap_sitemap} (context, context_hash) VALUES ('%s', '%s')", $context, md5($context)); 293 294 // @todo Does the sitemap show up on first install or is it a 404 page? 295 } 296 297 /** 298 * Implements hook_enable(). 299 */ 300 function xmlsitemap_enable() { 301 // Ensure the file cache directory is available and ready. 302 xmlsitemap_check_directory(); 303 304 variable_set('xmlsitemap_regenerate_needed', TRUE); 305 } 306 307 /** 308 * Implements hook_uninstall(). 309 */ 310 function xmlsitemap_uninstall() { 311 // Remove tables. 312 drupal_uninstall_schema('xmlsitemap'); 313 314 // Remove variables. 315 drupal_load('module', 'xmlsitemap'); 316 $variables = array_keys(xmlsitemap_variables()); 317 foreach ($variables as $variable) { 318 variable_del($variable); 319 } 320 321 // Remove the file cache directory. 322 xmlsitemap_clear_directory(NULL, TRUE); 323 } 324 325 /** 326 * Upgrade 6.x-1.x variables. 327 */ 328 function xmlsitemap_update_6196() { 329 $value = variable_get('xmlsitemap_cron_limit', 100); 330 variable_set('xmlsitemap_batch_limit', $value); 331 332 $value = variable_get('xmlsitemap_cache_directory', file_directory_path() . '/xmlsitemap'); 333 if (strpos($value, file_directory_path() . '/') === 0) { 334 $value = str_replace(file_directory_path() . '/', '', $value); 335 } 336 else { 337 $value = 'xmlsitemap'; 338 } 339 variable_set('xmlsitemap_path', $value); 340 341 $value = variable_get('xmlsitemap_use_stylesheet', FALSE); 342 variable_set('xmlsitemap_xsl', $value); 343 344 $value = variable_get('xmlsitemap_front_page_changefreq', 3600); 345 variable_set('xmlsitemap_frontpage_changefreq', $value); 346 347 $value = variable_get('xmlsitemap_front_page_priority', 1); 348 variable_set('xmlsitemap_frontpage_priority', $value); 349 350 // Intentionally set this variables so we get a generated sitemap ASAP. 351 variable_set('xmlsitemap_generated_last', 0); 352 variable_set('xmlsitemap_regenerate_needed', TRUE); 353 354 variable_del('xmlsitemap_chunk_size'); 355 return array(); 356 } 357 358 /** 359 * Upgrade the {xmlsitemap} table (drop and re-create). 360 */ 361 function xmlsitemap_update_6198() { 362 $ret = array(); 363 364 if (db_column_exists('xmlsitemap', 'sid')) { 365 db_drop_table($ret, 'xmlsitemap'); 366 367 $schema['xmlsitemap'] = array( 368 'description' => 'The base table for xmlsitemap links.', 369 'fields' => array( 370 'id' => array( 371 'description' => 'Primary key with type; a unique id for the item.', 372 'type' => 'int', 373 'not null' => TRUE, 374 'unsigned' => TRUE, 375 'default' => 0, 376 ), 377 'type' => array( 378 'description' => 'Primary key with id; the type of item (e.g. node, user, etc.).', 379 'type' => 'varchar', 380 'length' => 32, 381 'not null' => TRUE, 382 'default' => '', 383 ), 384 'subtype' => array( 385 'description' => 'A sub-type identifier for the link (node type, menu name, term VID, etc.).', 386 'type' => 'varchar', 387 'length' => 128, 388 'not null' => TRUE, 389 'default' => '', 390 ), 391 'loc' => array( 392 'description' => 'The URL to the item relative to the Drupal path.', 393 'type' => 'varchar', 394 'length' => 255, 395 'not null' => TRUE, 396 'default' => '', 397 ), 398 'language' => array( 399 'description' => 'The {languages}.language of this link or an empty string if it is language-neutral.', 400 'type' => 'varchar', 401 'length' => 12, 402 'not null' => TRUE, 403 'default' => '', 404 ), 405 'access' => array( 406 'description' => 'A boolean that represents if the item is viewable by the anonymous user. This field is useful to store the result of node_access() so we can retain changefreq and priority_override information.', 407 'type' => 'int', 408 'size' => 'tiny', 409 'not null' => TRUE, 410 'default' => 1, 411 ), 412 'status' => array( 413 'description' => 'An integer that represents if the item is included in the sitemap.', 414 'type' => 'int', 415 'size' => 'tiny', 416 'not null' => TRUE, 417 'default' => 1, 418 ), 419 'status_override' => array( 420 'description' => 'A boolean that if TRUE means that the status field has been overridden from its default value.', 421 'type' => 'int', 422 'size' => 'tiny', 423 'not null' => TRUE, 424 'default' => 0, 425 ), 426 'lastmod' => array( 427 'description' => 'The UNIX timestamp of last modification of the item.', 428 'type' => 'int', 429 'unsigned' => TRUE, 430 'not null' => TRUE, 431 'default' => 0, 432 ), 433 'priority' => array( 434 'description' => 'The priority of this URL relative to other URLs on your site. Valid values range from 0.0 to 1.0.', 435 'type' => 'float', 436 'default' => NULL, 437 ), 438 'priority_override' => array( 439 'description' => 'A boolean that if TRUE means that the priority field has been overridden from its default value.', 440 'type' => 'int', 441 'size' => 'tiny', 442 'not null' => TRUE, 443 'default' => 0, 444 ), 445 'changefreq' => array( 446 'description' => 'The average time in seconds between changes of this item.', 447 'type' => 'int', 448 'unsigned' => TRUE, 449 'not null' => TRUE, 450 'default' => 0, 451 ), 452 'changecount' => array( 453 'description' => 'The number of times this item has been changed. Used to help calculate the next changefreq value.', 454 'type' => 'int', 455 'unsigned' => TRUE, 456 'not null' => TRUE, 457 'default' => 0, 458 ), 459 ), 460 'primary key' => array('id', 'type'), 461 'indexes' => array( 462 'loc' => array('loc'), 463 'access_status_loc' => array('access', 'status', 'loc'), 464 'type_subtype' => array('type', 'subtype'), 465 'language' => array('language'), 466 ), 467 ); 468 db_create_table($ret, 'xmlsitemap', $schema['xmlsitemap']); 469 db_query("INSERT INTO {xmlsitemap} (type, id, loc, priority, changefreq) VALUES ('frontpage', 0, '', %f, %d)", variable_get('xmlsitemap_frontpage_priority', 1.0), variable_get('xmlsitemap_frontpage_changefreq', 86400)); 470 471 // Force a rebuild for table schemas. 472 drupal_get_schema(NULL, TRUE); 473 } 474 475 return $ret; 476 } 477 478 /** 479 * Empty update. 480 */ 481 function xmlsitemap_update_6200() { 482 return array(); 483 } 484 485 /** 486 * Cleanup any remaining 6.x-1.x tables, variables or weights. 487 */ 488 function xmlsitemap_update_6201() { 489 $ret = array(); 490 if (db_table_exists('xmlsitemap_additional')) { 491 db_drop_table($ret, 'xmlsitemap_additional'); 492 } 493 if (db_table_exists('xmlsitemap_modules')) { 494 db_drop_table($ret, 'xmlsitemap_modules'); 495 } 496 if (db_table_exists('xmlsitemap_file')) { 497 db_drop_table($ret, 'xmlsitemap_file'); 498 } 499 500 // Take care of any stray 6.x-1.x modules that are no longer supported. 501 $modules = array('xmlsitemap_file', 'xmlsitemap_helper', 'xmlsitemap_term'); 502 module_disable($modules); 503 foreach ($modules as $module) { 504 drupal_set_installed_schema_version($module, SCHEMA_UNINSTALLED); 505 } 506 507 variable_del('xmlsitemap_all_links_to_default_language'); 508 variable_del('xmlsitemap_cache_directory'); 509 // xmlsitemap_chunk_size not deleted since we use the same variable name. 510 db_query("DELETE FROM {variable} WHERE name LIKE 'xmlsitemap_create_cache_result_%%'"); 511 variable_del('xmlsitemap_cron_limit'); 512 variable_del('xmlsitemap_cron_submit'); 513 variable_del('xmlsitemap_cron_submit_frequency'); 514 variable_del('xmlsitemap_front_page_changefreq'); 515 variable_del('xmlsitemap_front_page_priority'); 516 variable_del('xmlsitemap_log_access'); 517 variable_del('xmlsitemap_previous_chunks_count'); 518 variable_del('xmlsitemap_sitemap_is_changed'); 519 variable_del('xmlsitemap_sitemap_needs_update'); 520 variable_del('xmlsitemap_submit'); 521 variable_del('xmlsitemap_update_sitemap_request'); 522 variable_del('xmlsitemap_update_timestamp'); 523 variable_del('xmlsitemap_use_stylesheet'); 524 $ret[] = update_sql("UPDATE {system} SET weight = 1 WHERE type = 'module' AND name = 'xmlsitemap'"); 525 return $ret; 526 } 527 528 /** 529 * Create the {xmlsitemap_sitemap} table and add the sitemap context data. 530 */ 531 function xmlsitemap_update_6202() { 532 $ret = array(); 533 if (!db_table_exists('xmlsitemap_sitemap')) { 534 $schema['xmlsitemap_sitemap'] = array( 535 'fields' => array( 536 'smid' => array( 537 'description' => 'Sitemap ID', 538 'type' => 'serial', 539 'unsigned' => TRUE, 540 'not null' => TRUE, 541 ), 542 'context_hash' => array( 543 'description' => 'The MD5 hash of the context field.', 544 'type' => 'varchar', 545 'length' => 32, 546 'not null' => TRUE, 547 'default' => '', 548 ), 549 'context' => array( 550 'description' => 'Serialized array with the sitemaps context', 551 'type' => 'text', 552 'not null' => TRUE, 553 ), 554 'updated' => array( 555 'type' => 'int', 556 'unsigned' => TRUE, 557 'not null' => TRUE, 558 'default' => 0, 559 ), 560 'links' => array( 561 'type' => 'int', 562 'unsigned' => TRUE, 563 'not null' => TRUE, 564 'default' => 0, 565 ), 566 'chunks' => array( 567 'type' => 'int', 568 'unsigned' => TRUE, 569 'not null' => TRUE, 570 'default' => 0, 571 ), 572 ), 573 'primary key' => array('smid'), 574 'unique keys' => array( 575 'context_hash' => array('context_hash'), 576 ), 577 ); 578 db_create_table($ret, 'xmlsitemap_sitemap', $schema['xmlsitemap_sitemap']); 579 } 580 581 // Add the default sitemap(s) and use language contexts if possible. 582 if (!db_result(db_query("SELECT COUNT(smid) FROM {xmlsitemap_sitemap}"))) { 583 // Refresh the schema and load the module if it's disabled. 584 drupal_get_schema(NULL, TRUE); 585 drupal_load('module', 'xmlsitemap'); 586 587 if (module_exists('xmlsitemap_i18n') && $languages = variable_get('xmlsitemap_languages', array())) { 588 foreach ($languages as $language) { 589 $sitemap = array('context' => array('language' => $language)); 590 xmlsitemap_sitemap_save($sitemap); 591 } 592 } 593 else { 594 $sitemap = array('context' => array()); 595 xmlsitemap_sitemap_save($sitemap); 596 } 597 } 598 599 // Language variable is no longer needed, so go ahead and delete it. 600 variable_del('xmlsitemap_languages'); 601 602 return $ret; 603 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |