pathauto.install 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /**
  3. * @file
  4. * Install, update, and uninstall functions for Pathauto.
  5. *
  6. * @ingroup pathauto
  7. */
  8. /**
  9. * Implements hook_install().
  10. */
  11. function pathauto_install() {
  12. // Set some default variables necessary for the module to perform.
  13. variable_set('pathauto_node_pattern', 'content/[node:title]');
  14. variable_set('pathauto_taxonomy_term_pattern', '[term:vocabulary]/[term:name]');
  15. variable_set('pathauto_forum_pattern', '[term:vocabulary]/[term:name]');
  16. variable_set('pathauto_user_pattern', 'users/[user:name]');
  17. variable_set('pathauto_blog_pattern', 'blogs/[user:name]');
  18. // Set the default separator character to replace instead of remove (default).
  19. variable_set('pathauto_punctuation_hyphen', 1);
  20. // Set the weight to 1
  21. db_update('system')
  22. ->fields(array('weight' => 1))
  23. ->condition('type', 'module')
  24. ->condition('name', 'pathauto')
  25. ->execute();
  26. }
  27. /**
  28. * Implements hook_uninstall().
  29. */
  30. function pathauto_uninstall() {
  31. // Delete all the pathauto variables and then clear the variable cache.
  32. db_query("DELETE FROM {variable} WHERE name LIKE 'pathauto_%'");
  33. cache_clear_all('variables', 'cache');
  34. }
  35. /**
  36. * Remove the unsupported user/%/contact and user/%/tracker pattern variables.
  37. */
  38. function pathauto_update_6200() {
  39. variable_del('pathauto_contact_bulkupdate');
  40. variable_del('pathauto_contact_pattern');
  41. variable_del('pathauto_contact_supportsfeeds');
  42. variable_del('pathauto_contact_applytofeeds');
  43. variable_del('pathauto_tracker_bulkupdate');
  44. variable_del('pathauto_tracker_pattern');
  45. variable_del('pathauto_tracker_supportsfeeds');
  46. variable_del('pathauto_tracker_applytofeeds');
  47. }
  48. /**
  49. * Empty update since it is handled by pathauto_update_7000().
  50. */
  51. function pathauto_update_6201() {
  52. }
  53. /**
  54. * Empty update since it is handled by pathauto_update_7004().
  55. */
  56. function pathauto_update_6202() {
  57. }
  58. /**
  59. * Remove obsolete variables since batch API is now used.
  60. */
  61. function pathauto_update_7000() {
  62. variable_del('pathauto_max_bulk_update');
  63. variable_del('pathauto_node_bulkupdate');
  64. variable_del('pathauto_taxonomy_bulkupdate');
  65. variable_del('pathauto_forum_bulkupdate');
  66. variable_del('pathauto_user_bulkupdate');
  67. variable_del('pathauto_blog_bulkupdate');
  68. variable_del('pathauto_modulelist');
  69. variable_del('pathauto_indexaliases');
  70. variable_del('pathauto_indexaliases_bulkupdate');
  71. }
  72. /**
  73. * Empty update since feed paths are no longer supported.
  74. */
  75. function pathauto_update_7001() {
  76. }
  77. /**
  78. * Update pathauto_taxonomy_[vid]_pattern variables to pathauto_taxonomy_[machinename]_pattern.
  79. */
  80. function pathauto_update_7002() {
  81. if (module_exists('taxonomy')) {
  82. $vocabularies = taxonomy_get_vocabularies();
  83. foreach ($vocabularies as $vid => $vocabulary) {
  84. if ($vid == variable_get('forum_nav_vocabulary', '')) {
  85. // Skip the forum vocabulary.
  86. continue;
  87. }
  88. if ($pattern = variable_get('pathauto_taxonomy_' . $vid . '_pattern', '')) {
  89. variable_set('pathauto_taxonomy_' . $vocabulary->machine_name . '_pattern', $pattern);
  90. }
  91. variable_del('pathauto_taxonomy_' . $vid . '_pattern');
  92. }
  93. }
  94. }
  95. /**
  96. * Rename 'taxonomy' variables to use the entity type 'taxonomy_term'.
  97. */
  98. function pathauto_update_7003() {
  99. $variables = db_select('variable', 'v')
  100. ->fields('v', array('name'))
  101. ->condition(db_and()
  102. ->condition('name', db_like("pathauto_taxonomy_") . '%', 'LIKE')
  103. ->condition('name', db_like("pathauto_taxonomy_term_") . '%', 'NOT LIKE')
  104. )
  105. ->execute()
  106. ->fetchCol();
  107. foreach ($variables as $variable) {
  108. $value = variable_get($variable);
  109. variable_del($variable);
  110. $variable = strtr($variable, array('pathauto_taxonomy_' => 'pathauto_taxonomy_term_'));
  111. variable_set($variable, $value);
  112. }
  113. }
  114. /**
  115. * Remove obsolete variables for removed feed handling.
  116. */
  117. function pathauto_update_7004() {
  118. variable_del('pathauto_node_supportsfeeds');
  119. variable_del('pathauto_node_applytofeeds');
  120. variable_del('pathauto_taxonomy_supportsfeeds');
  121. variable_del('pathauto_taxonomy_applytofeeds');
  122. variable_del('pathauto_forum_supportsfeeds');
  123. variable_del('pathauto_forum_applytofeeds');
  124. variable_del('pathauto_user_supportsfeeds');
  125. variable_del('pathauto_user_applytofeeds');
  126. variable_del('pathauto_blog_supportsfeeds');
  127. variable_del('pathauto_blog_applytofeeds');
  128. }
  129. /**
  130. * Fix original incorrect tokens in taxonomy and forum patterns.
  131. */
  132. function pathauto_update_7005() {
  133. $replacements = array(
  134. '[vocabulary:name]' => '[term:vocabulary]',
  135. '[vocabulary:' => '[term:vocabulary:',
  136. '[term:catpath]' => '[term:name]',
  137. '[term:path]' => '[term:name]',
  138. );
  139. $variables = db_select('variable', 'v')
  140. ->fields('v', array('name'))
  141. ->condition(db_or()
  142. ->condition('name', db_like("pathauto_taxonomy_term_") . '%' . db_like('pattern'), 'LIKE')
  143. ->condition('name', db_like("pathauto_forum_") . '%' . db_like('pattern'), 'LIKE')
  144. )
  145. ->execute()
  146. ->fetchCol();
  147. foreach ($variables as $variable) {
  148. if ($pattern = variable_get($variable)) {
  149. $pattern = strtr($pattern, $replacements);
  150. variable_set($variable, $pattern);
  151. }
  152. }
  153. return 'Your Pathauto taxonomy and forum patterns have been corrected. You may wish to regenerate your taxonomy and forum term URL aliases.';
  154. }
  155. /**
  156. * Build a list of Drupal 6 tokens and their Drupal 7 token names.
  157. */
  158. function _pathauto_upgrade_token_list() {
  159. $tokens = array(
  160. //'catpath' => 'node:term-lowest:parent:path][node:term-lowest',
  161. //'catalias' => 'node:term-lowest:path',
  162. //'termpath' => 'term:parent:path][term:name',
  163. //'termalias' => 'term:url:alias',
  164. //'bookpathalias' => 'node:book:parent:path',
  165. );
  166. }