web/drupal/modules/xmlsitemap/xmlsitemap.install
branchdrupal
changeset 74 0ff3ba646492
equal deleted inserted replaced
73:fcf75e232c5b 74:0ff3ba646492
       
     1 <?php
       
     2 // $Id: xmlsitemap.install,v 1.5.2.50 2009/07/16 13:35:22 earnie Exp $
       
     3 
       
     4 
       
     5 /**
       
     6  * @file
       
     7  * Installation file for XML sitemap.
       
     8  */
       
     9 
       
    10 /*****************************************************************************
       
    11  * Drupal hooks.
       
    12  ****************************************************************************/
       
    13 
       
    14 /**
       
    15  * Implementation of hook_enable().
       
    16  */
       
    17 function xmlsitemap_enable() {
       
    18   xmlsitemap_flag_sitemap();
       
    19 }
       
    20 
       
    21 /**
       
    22  * Implementation of hook_disable().
       
    23  */
       
    24 function xmlsitemap_disable() {
       
    25   xmlsitemap_flag_sitemap();
       
    26 }
       
    27 
       
    28 /**
       
    29  * Implementation of hook_schema().
       
    30  */
       
    31 function xmlsitemap_schema() {
       
    32   $schema['xmlsitemap'] = array(
       
    33     'description' => 'The base table for xmlsitemap.',
       
    34     'fields' => array(
       
    35       'lid' => array(
       
    36         'description' => 'The primary key.',
       
    37         'type' => 'serial',
       
    38         'not null' => TRUE,
       
    39       ),
       
    40       'loc' => array(
       
    41         'description' => 'The relative URL.',
       
    42         'type' => 'varchar',
       
    43         'length' => 255,
       
    44         'not null' => TRUE,
       
    45         'default' => '',
       
    46       ),
       
    47       'module' => array(
       
    48         'description' => 'The module handling this link.',
       
    49         'type' => 'varchar',
       
    50         'length' => 255,
       
    51         'not null' => TRUE,
       
    52         'default' => '',
       
    53       ),
       
    54       'type' => array(
       
    55         'description' => 'The type of link.',
       
    56         'type' => 'varchar',
       
    57         'length' => 32,
       
    58         'not null' => TRUE,
       
    59         'default' => '',
       
    60       ),
       
    61       'id' => array(
       
    62         'description' => 'The ID associated with the link.',
       
    63         'type' => 'int',
       
    64         'unsigned' => TRUE,
       
    65         'not null' => TRUE,
       
    66         'default' => 0,
       
    67       ),
       
    68       'sid' => array(
       
    69         'description' => 'The sub ID associated with the link.',
       
    70         'type' => 'int',
       
    71         'unsigned' => TRUE,
       
    72         'not null' => TRUE,
       
    73         'default' => 0,
       
    74       ),
       
    75       'language' => array(
       
    76         'description' => 'The language associated with the link.',
       
    77         'type' => 'varchar',
       
    78         'length' => 12,
       
    79         'not null' => TRUE,
       
    80         'default' => '',
       
    81       ),
       
    82       'changed' => array(
       
    83         'description' => 'The Unix timestamp of the last change.',
       
    84         'type' => 'int',
       
    85         'unsigned' => TRUE,
       
    86         'not null' => TRUE,
       
    87         'default' => 0,
       
    88       ),
       
    89       'changefreq' => array(
       
    90         'description' => 'The frequency of the changes.',
       
    91         'type' => 'int',
       
    92         'unsigned' => TRUE,
       
    93         'not null' => TRUE,
       
    94         'default' => 0,
       
    95       ),
       
    96       'priority' => array(
       
    97         'description' => 'The priority of this node in the sitemap.',
       
    98         'type' => 'float',
       
    99         'not null' => TRUE,
       
   100         'default' => 0.5,
       
   101       ),
       
   102     ),
       
   103     'indexes' => array(
       
   104       'link_module' => array(array('module', 25)),
       
   105       'link_language' => array('language'),
       
   106       'link_changed' => array('changed'),
       
   107       'link_priority' => array('priority'),
       
   108       'type_id' => array('type', 'id'),
       
   109     ),
       
   110     'primary key' => array('lid'),
       
   111   );
       
   112   return $schema;
       
   113 }
       
   114 
       
   115 /**
       
   116  * Implementation of hook_install().
       
   117  */
       
   118 function xmlsitemap_install() {
       
   119   drupal_install_schema('xmlsitemap');
       
   120   variable_set('xmlsitemap_chunk_size', 1000);
       
   121   db_query("UPDATE {system} SET weight = 5 WHERE name = 'xmlsitemap'");
       
   122 }
       
   123 
       
   124 /**
       
   125  * Implementation of hook_update_N().
       
   126  */
       
   127 function xmlsitemap_update_6100() {
       
   128   $ret = array();
       
   129   if ($GLOBALS['db_type'] == 'pgsql') {
       
   130     $ret[] = update_sql('DROP FUNCTION IF EXISTS first(anyelement, anyelement);');
       
   131     $result = @update_sql("DROP AGGREGATE first(anyelement)");
       
   132     if ($result['success']) {
       
   133       $ret[] = $result;
       
   134     }
       
   135   }
       
   136   if (db_table_exists('xmlsitemap_additional')) {
       
   137     db_drop_table($ret, 'xmlsitemap_additional');
       
   138   }
       
   139   if (db_table_exists('xmlsitemap')) {
       
   140     $result = array();
       
   141     @db_drop_primary_key($result, 'xmlsitemap');
       
   142     if ($result[0]['success']) {
       
   143       $ret[] = $result[0];
       
   144     }
       
   145     $result = array();
       
   146     @db_drop_index($result, 'xmlsitemap', 'link_module');
       
   147     if ($result[0]['success']) {
       
   148       $ret[] = $result[0];
       
   149     }
       
   150     $result = array();
       
   151     @db_drop_index($result, 'xmlsitemap', 'link_type');
       
   152     if ($result[0]['success']) {
       
   153       $ret[] = $result[0];
       
   154     }
       
   155     $result = array();
       
   156     @db_drop_index($result, 'xmlsitemap', 'link_changed');
       
   157     if ($result[0]['success']) {
       
   158       $ret[] = $result[0];
       
   159     }
       
   160     $result = array();
       
   161     @db_drop_index($result, 'xmlsitemap', 'link_priority');
       
   162     if ($result[0]['success']) {
       
   163       $ret[] = $result[0];
       
   164     }
       
   165     if (!db_column_exists('xmlsitemap', 'lid')) {
       
   166       db_add_field($ret, 'xmlsitemap', 'lid',
       
   167         array(
       
   168           'description' => 'The primary key.',
       
   169           'type' => 'serial',
       
   170           'not null' => TRUE,
       
   171         ),
       
   172         array('primary key' => array('lid'))
       
   173       );
       
   174     }
       
   175     db_change_field($ret, 'xmlsitemap', 'loc', 'loc',
       
   176       array(
       
   177         'description' => 'The relative URL.',
       
   178         'type' => 'varchar',
       
   179         'length' => 255,
       
   180         'not null' => TRUE,
       
   181         'default' => '',
       
   182       )
       
   183     );
       
   184     if (db_column_exists('xmlsitemap', 'module')) {
       
   185       db_change_field($ret, 'xmlsitemap', 'module', 'module',
       
   186         array(
       
   187           'description' => 'The module handling this link.',
       
   188           'type' => 'varchar',
       
   189           'length' => 255,
       
   190           'not null' => TRUE,
       
   191           'default' => '',
       
   192         ),
       
   193         array('indexes' => array('link_module' => array(array('module', 25))))
       
   194       );
       
   195     }
       
   196     else {
       
   197       db_add_field($ret, 'xmlsitemap', 'module',
       
   198         array(
       
   199           'description' => 'The module handling this link.',
       
   200           'type' => 'varchar',
       
   201           'length' => 255,
       
   202           'not null' => TRUE,
       
   203           'default' => '',
       
   204         ),
       
   205         array('indexes' => array('link_module' => array(array('module', 25))))
       
   206       );
       
   207     }
       
   208     if (db_column_exists('xmlsitemap', 'type')) {
       
   209       db_change_field($ret, 'xmlsitemap', 'type', 'type',
       
   210         array(
       
   211           'description' => 'The type of link.',
       
   212           'type' => 'varchar',
       
   213           'length' => 32,
       
   214           'not null' => TRUE,
       
   215           'default' => '',
       
   216         )
       
   217       );
       
   218     }
       
   219     else {
       
   220       db_add_field($ret, 'xmlsitemap', 'type',
       
   221         array(
       
   222           'description' => 'The type of link.',
       
   223           'type' => 'varchar',
       
   224           'length' => 32,
       
   225           'not null' => TRUE,
       
   226           'default' => '',
       
   227         )
       
   228       );
       
   229     }
       
   230     if (!db_column_exists('xmlsitemap', 'id')) {
       
   231       db_add_field($ret, 'xmlsitemap', 'id',
       
   232         array(
       
   233           'description' => 'The ID associated with the link.',
       
   234           'type' => 'int',
       
   235           'unsigned' => TRUE,
       
   236           'not null' => TRUE,
       
   237           'default' => 0,
       
   238         )
       
   239       );
       
   240     }
       
   241     if (!db_column_exists('xmlsitemap', 'sid')) {
       
   242       db_add_field($ret, 'xmlsitemap', 'sid',
       
   243         array(
       
   244           'description' => 'The sub ID associated with the link.',
       
   245           'type' => 'int',
       
   246           'unsigned' => TRUE,
       
   247           'not null' => TRUE,
       
   248           'default' => 0,
       
   249         )
       
   250       );
       
   251     }
       
   252     if (!db_column_exists('xmlsitemap', 'language')) {
       
   253       db_add_field($ret, 'xmlsitemap', 'language',
       
   254         array(
       
   255           'description' => 'The language associated with the link.',
       
   256           'type' => 'varchar',
       
   257           'length' => 12,
       
   258           'not null' => TRUE,
       
   259           'default' => '',
       
   260         ),
       
   261         array('indexes' => array('link_language' => array('language')))
       
   262       );
       
   263     }
       
   264     if (db_column_exists('xmlsitemap', 'lastmod')) {
       
   265       db_change_field($ret, 'xmlsitemap', 'lastmod', 'changed',
       
   266         array(
       
   267           'description' => 'The Unix timestamp of the last change.',
       
   268           'type' => 'int',
       
   269           'unsigned' => TRUE,
       
   270           'not null' => TRUE,
       
   271           'default' => 0,
       
   272         ),
       
   273         array('indexes' => array('link_changed' => array('changed')))
       
   274       );
       
   275     }
       
   276     else {
       
   277       if (!db_column_exists('xmlsitemap', 'changed')) {
       
   278         db_add_field($ret, 'xmlsitemap', 'changed',
       
   279           array(
       
   280             'description' => 'The Unix timestamp of the last change.',
       
   281             'type' => 'int',
       
   282             'unsigned' => TRUE,
       
   283             'not null' => TRUE,
       
   284             'default' => 0,
       
   285           ),
       
   286           array('indexes' => array('link_changed' => array('changed')))
       
   287         );
       
   288       }
       
   289     }
       
   290     if (db_column_exists('xmlsitemap', 'changefreq')) {
       
   291       db_change_field($ret, 'xmlsitemap', 'changefreq', 'changefreq',
       
   292         array(
       
   293           'description' => 'The frequency of the changes.',
       
   294           'type' => 'int',
       
   295           'unsigned' => TRUE,
       
   296           'not null' => TRUE,
       
   297           'default' => 0,
       
   298         )
       
   299       );
       
   300     }
       
   301     if (db_column_exists('xmlsitemap', 'priority')) {
       
   302       db_change_field($ret, 'xmlsitemap', 'priority', 'priority',
       
   303         array(
       
   304           'description' => 'The priority of this node in the sitemap.',
       
   305           'type' => 'float',
       
   306           'not null' => TRUE,
       
   307           'default' => 0.5,
       
   308         ),
       
   309         array('indexes' => array('link_priority' => array('priority')))
       
   310       );
       
   311     }
       
   312   }
       
   313   else {
       
   314     db_create_table($ret, 'xmlsitemap',
       
   315       array(
       
   316         'description' => 'The base table for xmlsitemap.',
       
   317         'fields' => array(
       
   318           'lid' => array(
       
   319             'description' => 'The primary key.',
       
   320             'type' => 'serial',
       
   321             'not null' => TRUE,
       
   322           ),
       
   323           'loc' => array(
       
   324             'description' => 'The relative URL.',
       
   325             'type' => 'varchar',
       
   326             'length' => 255,
       
   327             'not null' => TRUE,
       
   328             'default' => '',
       
   329           ),
       
   330           'module' => array(
       
   331             'description' => 'The module handling this link.',
       
   332             'type' => 'varchar',
       
   333             'length' => 255,
       
   334             'not null' => TRUE,
       
   335             'default' => '',
       
   336           ),
       
   337           'type' => array(
       
   338             'description' => 'The type of link.',
       
   339             'type' => 'varchar',
       
   340             'length' => 32,
       
   341             'not null' => TRUE,
       
   342             'default' => '',
       
   343           ),
       
   344           'id' => array(
       
   345             'description' => 'The ID associated with the link.',
       
   346             'type' => 'int',
       
   347             'unsigned' => TRUE,
       
   348             'not null' => TRUE,
       
   349             'default' => 0,
       
   350           ),
       
   351           'sid' => array(
       
   352             'description' => 'The sub ID associated with the link.',
       
   353             'type' => 'int',
       
   354             'unsigned' => TRUE,
       
   355             'not null' => TRUE,
       
   356             'default' => 0,
       
   357           ),
       
   358           'language' => array(
       
   359             'description' => 'The language associated with the link.',
       
   360             'type' => 'varchar',
       
   361             'length' => 12,
       
   362             'not null' => TRUE,
       
   363             'default' => '',
       
   364           ),
       
   365           'changed' => array(
       
   366             'description' => 'The Unix timestamp of the last change.',
       
   367             'type' => 'int',
       
   368             'unsigned' => TRUE,
       
   369             'not null' => TRUE,
       
   370             'default' => 0,
       
   371           ),
       
   372           'changefreq' => array(
       
   373             'description' => 'The frequency of the changes.',
       
   374             'type' => 'int',
       
   375             'unsigned' => TRUE,
       
   376             'not null' => TRUE,
       
   377             'default' => 0,
       
   378           ),
       
   379           'priority' => array(
       
   380             'description' => 'The priority of this node in the sitemap.',
       
   381             'type' => 'float',
       
   382             'not null' => TRUE,
       
   383             'default' => 0.5,
       
   384           ),
       
   385         ),
       
   386         'indexes' => array(
       
   387           'link_module' => array(array('module', 25)),
       
   388           'link_language' => array('language'),
       
   389           'link_changed' => array('changed'),
       
   390           'link_priority' => array('priority'),
       
   391         ),
       
   392         'primary key' => array('lid'),
       
   393       )
       
   394     );
       
   395   }
       
   396   if (module_exists('xmlsitemap_file')) {
       
   397     module_disable(array('xmlsitemap_file'));
       
   398   }
       
   399   if (module_exists('xmlsitemap_helper')) {
       
   400     module_disable(array('xmlsitemap_helper'));
       
   401   }
       
   402   $ret[] = update_sql("DELETE FROM {system} WHERE name IN ('xmlsitemap_file', 'xmlsitemap_helper') AND type = 'module'");
       
   403   if (db_table_exists('xmlsitemap_file')) {
       
   404     db_drop_table($ret, 'xmlsitemap_file');
       
   405   }
       
   406   if (!variable_get('menu_rebuild_needed', FALSE)) {
       
   407     variable_set('menu_rebuild_needed', TRUE);
       
   408     $ret[] = array(
       
   409       'success' => TRUE,
       
   410       'query' => 'Updated the menu callbacks successfully.',
       
   411     );
       
   412   }
       
   413   module_rebuild_cache();
       
   414   $ret[] = array(
       
   415     'success' => TRUE,
       
   416     'query' => 'Updated the module list successfully.',
       
   417   );
       
   418   return $ret;
       
   419 }
       
   420 
       
   421 /**
       
   422  * Implementation of hook_update_N().
       
   423  */
       
   424 function xmlsitemap_update_6118() {
       
   425   variable_set('xmlsitemap_cron_submit_frequency', variable_get('xmlsitemap_cron_submit', FALSE) ? 1 : -1);
       
   426   $ret[] = array(
       
   427     'success' => TRUE,
       
   428     'query' => 'Updated the module settings successfully.',
       
   429   );
       
   430   return $ret;
       
   431 }
       
   432 
       
   433 /**
       
   434  * Implementation of hook_update_N().
       
   435  *
       
   436  * @TODO: Why are we deleting all rows from xmlsitemap?
       
   437  */
       
   438 function xmlsitemap_update_6126() {
       
   439   $ret[] = update_sql("DELETE FROM {xmlsitemap}");
       
   440   return $ret;
       
   441 }
       
   442 
       
   443 /**
       
   444  * Implementation of hook_update_N().
       
   445  */
       
   446 function xmlsitemap_update_6133() {
       
   447   if ($GLOBALS['db_type'] == 'pgsql') {
       
   448     $ret[] = update_sql('DROP FUNCTION IF EXISTS first(anyelement, anyelement);');
       
   449     $result = @update_sql("DROP AGGREGATE first(anyelement)");
       
   450     if ($result['success']) {
       
   451       $ret[] = $result;
       
   452     }
       
   453   }
       
   454   $ret[] = update_sql("UPDATE {system} SET weight = 5 WHERE name = 'xmlsitemap'");
       
   455   return $ret;
       
   456 }
       
   457 
       
   458 /**
       
   459  * Implementation of hook_update_N().
       
   460  */
       
   461 function xmlsitemap_update_6136() {
       
   462   $ret[] = update_sql("DELETE FROM {variable} WHERE name = 'xmlsitemap_update_sitemap_request'");
       
   463   variable_set('xmlsitemap_chunk_size', 1000);
       
   464   $ret[] = array(
       
   465     'success' => TRUE,
       
   466     'query' => 'Updated the XML sitemap chunk size successfully.',
       
   467   );
       
   468   return $ret;
       
   469 }
       
   470 
       
   471 /**
       
   472  * Implementation of hook_update_N().
       
   473  */
       
   474 function xmlsitemap_update_6138() {
       
   475   $ret = array();
       
   476   $result = array();
       
   477   @db_drop_index($result, 'xmlsitemap', 'link_type');
       
   478   if ($result[0]['success']) {
       
   479     $ret[] = $result[0];
       
   480   }
       
   481   return $ret;
       
   482 }
       
   483 
       
   484 /**
       
   485  * Implementation of hook_update_N().
       
   486  */
       
   487 function xmlsitemap_update_6139() {
       
   488   $ret[] = update_sql("DELETE FROM {system} WHERE name IN ('xmlsitemap_file', 'xmlsitemap_helper') AND type = 'module'");
       
   489   if (db_table_exists('xmlsitemap_file')) {
       
   490     db_drop_table($ret, 'xmlsitemap_file');
       
   491   }
       
   492   module_rebuild_cache();
       
   493   $ret[] = array(
       
   494     'success' => TRUE,
       
   495     'query' => 'Updated the modules list successfully.',
       
   496   );
       
   497   return $ret;
       
   498 }
       
   499 
       
   500 /**
       
   501  * Implementation of hook_update_N().
       
   502  */
       
   503 function xmlsitemap_update_6140() {
       
   504   $ret = array();
       
   505   if (module_exists('xmlsitemap_term')) {
       
   506     module_disable(array('xmlsitemap_term'));
       
   507     drupal_set_message(t('XML sitemap term has been deprecated in favor of XML sitemap taxonomy; enable it in the <a href="@modules">modules page</a>.', array('@modules' => url('admin/build/modules'))), 'status', FALSE);
       
   508     $ret[] = array(
       
   509       'success' => TRUE,
       
   510       'query' => 'Disabled the XML sitemap term module successfully.',
       
   511     );
       
   512   }
       
   513   if (function_exists('rules_clear_cache')) {
       
   514     rules_clear_cache();
       
   515     $ret[] = array(
       
   516       'success' => TRUE,
       
   517       'query' => 'Cleared rules cache successfully.',
       
   518     );
       
   519   }
       
   520   return $ret;
       
   521 }
       
   522 
       
   523 /**
       
   524  * Implementation of hook_update_N().
       
   525  */
       
   526 function xmlsitemap_update_6141() {
       
   527   $ret = array();
       
   528   if (!variable_get('menu_rebuild_needed', FALSE)) {
       
   529     variable_set('menu_rebuild_needed', TRUE);
       
   530     $ret[] = array(
       
   531       'success' => TRUE,
       
   532       'query' => 'Re-build menu callbacks successfully.',
       
   533     );
       
   534   }
       
   535   return $ret;
       
   536 }
       
   537 
       
   538 /**
       
   539  * Implementation of hook_update_N().
       
   540  */
       
   541 function xmlsitemap_update_6150() {
       
   542   // Used 6150 since beta5 contained 6148.
       
   543   // Make sure that the xmlsitemap directory is removed.
       
   544   $ret = array();
       
   545   $path = drupal_get_path('module', 'xmlsitemap');
       
   546   if (is_dir($path . '/xmlsitemap')) {
       
   547     $t = get_t();
       
   548     watchdog('xmlsitemap', 'You have not correctly followed the installation instructions for this module. You must make certain that the old xmlsitemap/xmlsitemap diretory is removed. The xmlsitemap/xmlsitemap/xmlsitemap.* files have been moved back to the modules root directory. The install instructions were to remove the modules/xmlsitemap directory completely before extracting the update. If you had followed that step you would have prevented this message.', NULL, WATCHDOG_ERROR);
       
   549     $ret['#abort'] = array(
       
   550       'success' => FALSE,
       
   551       'query' => $t('You have not correctly followed the installation instructions for this module. You must make certain that the old xmlsitemap/xmlsitemap diretory is removed. The xmlsitemap/xmlsitemap/xmlsitemap.* files have been moved back to the modules root directory. The install instructions were to remove the modules/xmlsitemap directory completely before extracting the update. If you had followed that step you would have prevented this message.'),
       
   552     );
       
   553   }
       
   554   return $ret;
       
   555 }
       
   556 
       
   557 /**
       
   558  * Implementation of hook_update_N().
       
   559  */
       
   560 function xmlsitemap_update_6151() {
       
   561   $ret = array();
       
   562   db_add_index($ret, 'xmlsitemap', 'type_id', array('type', 'id'));
       
   563   return $ret;  
       
   564 }
       
   565 
       
   566 /**
       
   567  * Implementation of hook_requirements().
       
   568  */
       
   569 function xmlsmitemap_requirements($phase) {
       
   570   $requirements = array();
       
   571   $path = drupal_get_path('module', 'xmlsitemap');
       
   572   if (is_dir($path . '/xmlsitemap')) {
       
   573     $t = get_t();
       
   574     watchdog('xmlsitemap', 'You have not correctly followed the installation instructions for this module. You must make certain that the old xmlsitemap/xmlsitemap diretory is removed. The xmlsitemap/xmlsitemap/xmlsitemap.* files have been moved back to the modules root directory. The install instructions were to removed the modules/xmlsitemap directory completely before extracting the update. If you had followed that step you would have prevented this message.', NULL, WATCHDOG_ERROR);
       
   575     $requirements['xmlsitemap'] = array(
       
   576       'title' => $t('xmlsitemap'),
       
   577       'value' => $t('Installation issue'),
       
   578       'description' => $t('You have not correctly followed the installation instructions for this module. You must make certain that the old xmlsitemap/xmlsitemap diretory is removed. The xmlsitemap/xmlsitemap/xmlsitemap.* files have been moved back to the modules root directory. The install instructions were to removed the modules/xmlsitemap directory completely before extracting the update. If you had followed that step you would have prevented this message.'),
       
   579       'severity' => REQUIREMENT_ERROR,
       
   580     );
       
   581   }
       
   582   return $requirements;
       
   583 }
       
   584 
       
   585 /**
       
   586  * Implementation of hook_uninstall().
       
   587  */
       
   588 function xmlsitemap_uninstall() {
       
   589   drupal_uninstall_schema('xmlsitemap');
       
   590   db_query("DELETE FROM {variable} WHERE name LIKE 'xmlsitemap\_%'");
       
   591 }
       
   592