Projet

Général

Profil

Paste
Télécharger (8,82 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / pathauto / pathauto.install @ 5136ce55

1
<?php
2

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

    
10
/**
11
 * Implements hook_schema().
12
 */
13
function pathauto_schema() {
14
  $schema['pathauto_state'] = array(
15
    'description' => 'The status of each entity alias (whether it was automatically generated or not).',
16
    'fields' => array(
17
      'entity_type' => array(
18
        'type' => 'varchar',
19
        'length' => 32,
20
        'not null' => TRUE,
21
        'description' => 'An entity type.',
22
      ),
23
      'entity_id' => array(
24
        'type' => 'int',
25
        'unsigned' => TRUE,
26
        'not null' => TRUE,
27
        'description' => 'An entity ID.',
28
      ),
29
      'pathauto' => array(
30
        'type' => 'int',
31
        'size' => 'tiny',
32
        'not null' => TRUE,
33
        'default' => 0,
34
        'description' => 'The automatic alias status of the entity.',
35
      ),
36
    ),
37
    'primary key' => array('entity_type', 'entity_id'),
38
  );
39

    
40
  return $schema;
41
}
42

    
43

    
44
/**
45
 * Implements hook_install().
46
 */
47
function pathauto_install() {
48
  // Set some default variables necessary for the module to perform.
49
  $defaults = array(
50
    'pathauto_node_pattern' => 'content/[node:title]',
51
    'pathauto_taxonomy_term_pattern' => '[term:vocabulary]/[term:name]',
52
    'pathauto_forum_pattern' => '[term:vocabulary]/[term:name]',
53
    'pathauto_user_pattern' => 'users/[user:name]',
54
    'pathauto_blog_pattern' => 'blogs/[user:name]',
55
    // Set hyphen character to replace instead of remove.
56
    'pathauto_punctuation_hyphen' => 1,
57
  );
58
  foreach ($defaults as $variable => $default) {
59
    if (variable_get($variable) === NULL) {
60
      variable_set($variable, $default);
61
    }
62
  }
63

    
64
  // Set the weight to 1
65
  db_update('system')
66
    ->fields(array('weight' => 1))
67
    ->condition('type', 'module')
68
    ->condition('name', 'pathauto')
69
    ->execute();
70
}
71

    
72
/**
73
 * Implements hook_uninstall().
74
 */
75
function pathauto_uninstall() {
76
  // Delete all the pathauto variables and then clear the variable cache.
77
  db_query("DELETE FROM {variable} WHERE name LIKE 'pathauto_%'");
78
  cache_clear_all('variables', 'cache');
79
}
80

    
81
/**
82
 * Implements hook_requirements().
83
 */
84
function pathauto_requirements($phase) {
85
  $requirements = array();
86
  $t = get_t();
87
  if ($phase == 'runtime' && module_exists('pathauto_persist')) {
88
    $requirements['pathauto'] = array(
89
      'title' => $t('Pathauto Persist'),
90
      'value' => $t('Enabled'),
91
      'description' => $t('Pathauto Persist is installed and enabled. As Pathauto Persist has been merged into Pathauto, the Pathauto Persist module can be safely disabled and removed. All Pathauto Persist settings have been migrated to the Pathauto implementation.'),
92
      'severity' => REQUIREMENT_INFO,
93
    );
94
  }
95
  return $requirements;
96
}
97

    
98
/**
99
 * Remove the unsupported user/%/contact and user/%/tracker pattern variables.
100
 */
101
function pathauto_update_6200() {
102
  variable_del('pathauto_contact_bulkupdate');
103
  variable_del('pathauto_contact_pattern');
104
  variable_del('pathauto_contact_supportsfeeds');
105
  variable_del('pathauto_contact_applytofeeds');
106
  variable_del('pathauto_tracker_bulkupdate');
107
  variable_del('pathauto_tracker_pattern');
108
  variable_del('pathauto_tracker_supportsfeeds');
109
  variable_del('pathauto_tracker_applytofeeds');
110
}
111

    
112
/**
113
 * Empty update since it is handled by pathauto_update_7000().
114
 */
115
function pathauto_update_6201() {
116
}
117

    
118
/**
119
 * Empty update since it is handled by pathauto_update_7004().
120
 */
121
function pathauto_update_6202() {
122
}
123

    
124
/**
125
 * Remove obsolete variables since batch API is now used.
126
 */
127
function pathauto_update_7000() {
128
  variable_del('pathauto_max_bulk_update');
129
  variable_del('pathauto_node_bulkupdate');
130
  variable_del('pathauto_taxonomy_bulkupdate');
131
  variable_del('pathauto_forum_bulkupdate');
132
  variable_del('pathauto_user_bulkupdate');
133
  variable_del('pathauto_blog_bulkupdate');
134
  variable_del('pathauto_modulelist');
135
  variable_del('pathauto_indexaliases');
136
  variable_del('pathauto_indexaliases_bulkupdate');
137
}
138

    
139
/**
140
 * Empty update since feed paths are no longer supported.
141
 */
142
function pathauto_update_7001() {
143
}
144

    
145
/**
146
 * Update pathauto_taxonomy_[vid]_pattern variables to pathauto_taxonomy_[machinename]_pattern.
147
 */
148
function pathauto_update_7002() {
149
  if (module_exists('taxonomy')) {
150
    $vocabularies = taxonomy_get_vocabularies();
151
    foreach ($vocabularies as $vid => $vocabulary) {
152
      if ($vid == variable_get('forum_nav_vocabulary', '')) {
153
        // Skip the forum vocabulary.
154
        continue;
155
      }
156
      if ($pattern = variable_get('pathauto_taxonomy_' . $vid . '_pattern', '')) {
157
        variable_set('pathauto_taxonomy_' . $vocabulary->machine_name . '_pattern', $pattern);
158
      }
159
      variable_del('pathauto_taxonomy_' . $vid . '_pattern');
160
    }
161
  }
162
}
163

    
164
/**
165
 * Rename 'taxonomy' variables to use the entity type 'taxonomy_term'.
166
 */
167
function pathauto_update_7003() {
168
  $variables = db_select('variable', 'v')
169
    ->fields('v', array('name'))
170
    ->condition(db_and()
171
      ->condition('name', db_like("pathauto_taxonomy_") . '%', 'LIKE')
172
      ->condition('name', db_like("pathauto_taxonomy_term_") . '%', 'NOT LIKE')
173
    )
174
    ->execute()
175
    ->fetchCol();
176
  foreach ($variables as $variable) {
177
    $value = variable_get($variable);
178
    variable_del($variable);
179
    $variable = strtr($variable, array('pathauto_taxonomy_' => 'pathauto_taxonomy_term_'));
180
    variable_set($variable, $value);
181
  }
182
}
183

    
184
/**
185
 * Remove obsolete variables for removed feed handling.
186
 */
187
function pathauto_update_7004() {
188
  variable_del('pathauto_node_supportsfeeds');
189
  variable_del('pathauto_node_applytofeeds');
190
  variable_del('pathauto_taxonomy_supportsfeeds');
191
  variable_del('pathauto_taxonomy_applytofeeds');
192
  variable_del('pathauto_forum_supportsfeeds');
193
  variable_del('pathauto_forum_applytofeeds');
194
  variable_del('pathauto_user_supportsfeeds');
195
  variable_del('pathauto_user_applytofeeds');
196
  variable_del('pathauto_blog_supportsfeeds');
197
  variable_del('pathauto_blog_applytofeeds');
198
}
199

    
200
/**
201
 * Fix original incorrect tokens in taxonomy and forum patterns.
202
 */
203
function pathauto_update_7005() {
204
  $replacements = array(
205
    '[vocabulary:name]' => '[term:vocabulary]',
206
    '[vocabulary:' => '[term:vocabulary:',
207
    '[term:catpath]' => '[term:name]',
208
    '[term:path]' => '[term:name]',
209
  );
210
  $variables = db_select('variable', 'v')
211
    ->fields('v', array('name'))
212
    ->condition(db_or()
213
      ->condition('name', db_like("pathauto_taxonomy_term_") . '%' . db_like('pattern'), 'LIKE')
214
      ->condition('name', db_like("pathauto_forum_") . '%' . db_like('pattern'), 'LIKE')
215
    )
216
    ->execute()
217
    ->fetchCol();
218
  foreach ($variables as $variable) {
219
    if ($pattern = variable_get($variable)) {
220
      $pattern = strtr($pattern, $replacements);
221
      variable_set($variable, $pattern);
222
    }
223
  }
224

    
225
  return 'Your Pathauto taxonomy and forum patterns have been corrected. You may wish to regenerate your taxonomy and forum term URL aliases.';
226
}
227

    
228
/**
229
 * Create pathauto_state table, using data from pathauto_persist if it exists.
230
 */
231
function pathauto_update_7006() {
232
  if (!db_table_exists('pathauto_state')) {
233

    
234
    $schema['pathauto_state'] = array(
235
      'description' => 'The status of each entity alias (whether it was automatically generated or not).',
236
      'fields' => array(
237
        'entity_type' => array(
238
          'type' => 'varchar',
239
          'length' => 32,
240
          'not null' => TRUE,
241
          'description' => 'The entity type.',
242
        ),
243
        'entity_id' => array(
244
          'type' => 'int',
245
          'unsigned' => TRUE,
246
          'not null' => TRUE,
247
          'description' => 'The entity ID.',
248
        ),
249
        'pathauto' => array(
250
          'type' => 'int',
251
          'size' => 'tiny',
252
          'not null' => TRUE,
253
          'default' => 0,
254
          'description' => 'The automatic alias status of the entity.',
255
        ),
256
      ),
257
      'primary key' => array('entity_type', 'entity_id'),
258
    );
259

    
260
    if (db_table_exists('pathauto_persist')) {
261
      // Rename pathauto_persist's table, then create a new empty one just so
262
      // that we can cleanly disable that module.
263
      db_rename_table('pathauto_persist', 'pathauto_state');
264
      db_create_table('pathauto_persist', $schema['pathauto_state']);
265
      // Disable the module and inform the user.
266
      if (module_exists('pathauto_persist')) {
267
        module_disable(array('pathauto_persist'));
268
      }
269
      return t('The Pathauto Persist module and all of its data has been merged into Pathauto. The Pathauto Persist module has been disabled and can be safely uninstalled.');
270
    }
271
    else {
272
      db_create_table('pathauto_state', $schema['pathauto_state']);
273
    }
274
  }
275
}
276

    
277
/**
278
 * Build a list of Drupal 6 tokens and their Drupal 7 token names.
279
 */
280
function _pathauto_upgrade_token_list() {
281
  $tokens = array(
282
    //'catpath' => 'node:term-lowest:parent:path][node:term-lowest',
283
    //'catalias' => 'node:term-lowest:path',
284
    //'termpath' => 'term:parent:path][term:name',
285
    //'termalias' => 'term:url:alias',
286
    //'bookpathalias' => 'node:book:parent:path',
287
  );
288
}