Projet

Général

Profil

Paste
Télécharger (5,59 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / pathauto / pathauto.install @ 87dbc3bf

1
<?php
2

    
3
/**
4
 * @file
5
 * Install, update, and uninstall functions for Pathauto.
6
 *
7
 * @ingroup pathauto
8
 */
9

    
10
/**
11
 * Implements hook_install().
12
 */
13
function pathauto_install() {
14
  // Set some default variables necessary for the module to perform.
15
  variable_set('pathauto_node_pattern', 'content/[node:title]');
16
  variable_set('pathauto_taxonomy_term_pattern', '[term:vocabulary]/[term:name]');
17
  variable_set('pathauto_forum_pattern', '[term:vocabulary]/[term:name]');
18
  variable_set('pathauto_user_pattern', 'users/[user:name]');
19
  variable_set('pathauto_blog_pattern', 'blogs/[user:name]');
20

    
21
  // Set the default separator character to replace instead of remove (default).
22
  variable_set('pathauto_punctuation_hyphen', 1);
23

    
24
  // Set the weight to 1
25
  db_update('system')
26
    ->fields(array('weight' => 1))
27
    ->condition('type', 'module')
28
    ->condition('name', 'pathauto')
29
    ->execute();
30
}
31

    
32
/**
33
 * Implements hook_uninstall().
34
 */
35
function pathauto_uninstall() {
36
  // Delete all the pathauto variables and then clear the variable cache.
37
  db_query("DELETE FROM {variable} WHERE name LIKE 'pathauto_%'");
38
  cache_clear_all('variables', 'cache');
39
}
40

    
41
/**
42
 * Remove the unsupported user/%/contact and user/%/tracker pattern variables.
43
 */
44
function pathauto_update_6200() {
45
  variable_del('pathauto_contact_bulkupdate');
46
  variable_del('pathauto_contact_pattern');
47
  variable_del('pathauto_contact_supportsfeeds');
48
  variable_del('pathauto_contact_applytofeeds');
49
  variable_del('pathauto_tracker_bulkupdate');
50
  variable_del('pathauto_tracker_pattern');
51
  variable_del('pathauto_tracker_supportsfeeds');
52
  variable_del('pathauto_tracker_applytofeeds');
53
}
54

    
55
/**
56
 * Empty update since it is handled by pathauto_update_7000().
57
 */
58
function pathauto_update_6201() {
59
}
60

    
61
/**
62
 * Empty update since it is handled by pathauto_update_7004().
63
 */
64
function pathauto_update_6202() {
65
}
66

    
67
/**
68
 * Remove obsolete variables since batch API is now used.
69
 */
70
function pathauto_update_7000() {
71
  variable_del('pathauto_max_bulk_update');
72
  variable_del('pathauto_node_bulkupdate');
73
  variable_del('pathauto_taxonomy_bulkupdate');
74
  variable_del('pathauto_forum_bulkupdate');
75
  variable_del('pathauto_user_bulkupdate');
76
  variable_del('pathauto_blog_bulkupdate');
77
  variable_del('pathauto_modulelist');
78
  variable_del('pathauto_indexaliases');
79
  variable_del('pathauto_indexaliases_bulkupdate');
80
}
81

    
82
/**
83
 * Empty update since feed paths are no longer supported.
84
 */
85
function pathauto_update_7001() {
86
}
87

    
88
/**
89
 * Update pathauto_taxonomy_[vid]_pattern variables to pathauto_taxonomy_[machinename]_pattern.
90
 */
91
function pathauto_update_7002() {
92
  if (module_exists('taxonomy')) {
93
    $vocabularies = taxonomy_get_vocabularies();
94
    foreach ($vocabularies as $vid => $vocabulary) {
95
      if ($vid == variable_get('forum_nav_vocabulary', '')) {
96
        // Skip the forum vocabulary.
97
        continue;
98
      }
99
      if ($pattern = variable_get('pathauto_taxonomy_' . $vid . '_pattern', '')) {
100
        variable_set('pathauto_taxonomy_' . $vocabulary->machine_name . '_pattern', $pattern);
101
      }
102
      variable_del('pathauto_taxonomy_' . $vid . '_pattern');
103
    }
104
  }
105
}
106

    
107
/**
108
 * Rename 'taxonomy' variables to use the entity type 'taxonomy_term'.
109
 */
110
function pathauto_update_7003() {
111
  $variables = db_select('variable', 'v')
112
    ->fields('v', array('name'))
113
    ->condition(db_and()
114
      ->condition('name', db_like("pathauto_taxonomy_") . '%', 'LIKE')
115
      ->condition('name', db_like("pathauto_taxonomy_term_") . '%', 'NOT LIKE')
116
    )
117
    ->execute()
118
    ->fetchCol();
119
  foreach ($variables as $variable) {
120
    $value = variable_get($variable);
121
    variable_del($variable);
122
    $variable = strtr($variable, array('pathauto_taxonomy_' => 'pathauto_taxonomy_term_'));
123
    variable_set($variable, $value);
124
  }
125
}
126

    
127
/**
128
 * Remove obsolete variables for removed feed handling.
129
 */
130
function pathauto_update_7004() {
131
  variable_del('pathauto_node_supportsfeeds');
132
  variable_del('pathauto_node_applytofeeds');
133
  variable_del('pathauto_taxonomy_supportsfeeds');
134
  variable_del('pathauto_taxonomy_applytofeeds');
135
  variable_del('pathauto_forum_supportsfeeds');
136
  variable_del('pathauto_forum_applytofeeds');
137
  variable_del('pathauto_user_supportsfeeds');
138
  variable_del('pathauto_user_applytofeeds');
139
  variable_del('pathauto_blog_supportsfeeds');
140
  variable_del('pathauto_blog_applytofeeds');
141
}
142

    
143
/**
144
 * Fix original incorrect tokens in taxonomy and forum patterns.
145
 */
146
function pathauto_update_7005() {
147
  $replacements = array(
148
    '[vocabulary:name]' => '[term:vocabulary]',
149
    '[vocabulary:' => '[term:vocabulary:',
150
    '[term:catpath]' => '[term:name]',
151
    '[term:path]' => '[term:name]',
152
  );
153
  $variables = db_select('variable', 'v')
154
    ->fields('v', array('name'))
155
    ->condition(db_or()
156
      ->condition('name', db_like("pathauto_taxonomy_term_") . '%' . db_like('pattern'), 'LIKE')
157
      ->condition('name', db_like("pathauto_forum_") . '%' . db_like('pattern'), 'LIKE')
158
    )
159
    ->execute()
160
    ->fetchCol();
161
  foreach ($variables as $variable) {
162
    if ($pattern = variable_get($variable)) {
163
      $pattern = strtr($pattern, $replacements);
164
      variable_set($variable, $pattern);
165
    }
166
  }
167

    
168
  return 'Your Pathauto taxonomy and forum patterns have been corrected. You may wish to regenerate your taxonomy and forum term URL aliases.';
169
}
170

    
171
/**
172
 * Build a list of Drupal 6 tokens and their Drupal 7 token names.
173
 */
174
function _pathauto_upgrade_token_list() {
175
  $tokens = array(
176
    //'catpath' => 'node:term-lowest:parent:path][node:term-lowest',
177
    //'catalias' => 'node:term-lowest:path',
178
    //'termpath' => 'term:parent:path][term:name',
179
    //'termalias' => 'term:url:alias',
180
    //'bookpathalias' => 'node:book:parent:path',
181
  );
182
}