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