Projet

Général

Profil

Paste
Télécharger (7,47 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / pathauto / pathauto.pathauto.inc @ ba09eb79

1
<?php
2

    
3
/**
4
 * @file
5
 * Pathauto integration for core modules.
6
 *
7
 * @ingroup pathauto
8
 */
9

    
10
/**
11
 * Batch processing callback; Generate aliases for nodes.
12
 */
13
function node_pathauto_bulk_update_batch_process(&$context) {
14
  if (!isset($context['sandbox']['current'])) {
15
    $context['sandbox']['count'] = 0;
16
    $context['sandbox']['current'] = 0;
17
  }
18

    
19
  $query = db_select('node', 'n');
20
  $query->leftJoin('url_alias', 'ua', "CONCAT('node/', n.nid) = ua.source");
21
  $query->addField('n', 'nid');
22
  $query->isNull('ua.source');
23
  $query->condition('n.nid', $context['sandbox']['current'], '>');
24
  $query->orderBy('n.nid');
25
  $query->addTag('pathauto_bulk_update');
26
  $query->addMetaData('entity', 'node');
27

    
28
  // Get the total amount of items to process.
29
  if (!isset($context['sandbox']['total'])) {
30
    $context['sandbox']['total'] = $query->countQuery()->execute()->fetchField();
31

    
32
    // If there are no nodes to update, the stop immediately.
33
    if (!$context['sandbox']['total']) {
34
      $context['finished'] = 1;
35
      return;
36
    }
37
  }
38

    
39
  $query->range(0, 25);
40
  $nids = $query->execute()->fetchCol();
41

    
42
  pathauto_node_update_alias_multiple($nids, 'bulkupdate');
43
  $context['sandbox']['count'] += count($nids);
44
  $context['sandbox']['current'] = max($nids);
45
  $context['message'] = t('Updated alias for node @nid.', array('@nid' => end($nids)));
46

    
47
  if ($context['sandbox']['count'] != $context['sandbox']['total']) {
48
    $context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
49
  }
50
}
51

    
52
/**
53
 * Batch processing callback; Generate aliases for taxonomy terms.
54
 */
55
function taxonomy_pathauto_bulk_update_batch_process(&$context) {
56
  if (!isset($context['sandbox']['current'])) {
57
    $context['sandbox']['count'] = 0;
58
    $context['sandbox']['current'] = 0;
59
  }
60

    
61
  $query = db_select('taxonomy_term_data', 'td');
62
  $query->leftJoin('url_alias', 'ua', "CONCAT('taxonomy/term/', td.tid) = ua.source");
63
  $query->addField('td', 'tid');
64
  $query->isNull('ua.source');
65
  $query->condition('td.tid', $context['sandbox']['current'], '>');
66
  // Exclude the forums terms.
67
  if ($forum_vid = variable_get('forum_nav_vocabulary', '')) {
68
    $query->condition('td.vid', $forum_vid, '<>');
69
  }
70
  $query->orderBy('td.tid');
71
  $query->addTag('pathauto_bulk_update');
72
  $query->addMetaData('entity', 'taxonomy_term');
73

    
74
  // Get the total amount of items to process.
75
  if (!isset($context['sandbox']['total'])) {
76
    $context['sandbox']['total'] = $query->countQuery()->execute()->fetchField();
77

    
78
    // If there are no nodes to update, the stop immediately.
79
    if (!$context['sandbox']['total']) {
80
      $context['finished'] = 1;
81
      return;
82
    }
83
  }
84

    
85
  $query->range(0, 25);
86
  $tids = $query->execute()->fetchCol();
87

    
88
  pathauto_taxonomy_term_update_alias_multiple($tids, 'bulkupdate');
89
  $context['sandbox']['count'] += count($tids);
90
  $context['sandbox']['current'] = max($tids);
91
  $context['message'] = t('Updated alias for term @tid.', array('@tid' => end($tids)));
92

    
93
  if ($context['sandbox']['count'] != $context['sandbox']['total']) {
94
    $context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
95
  }
96
}
97

    
98
/**
99
 * Batch processing callback; Generate aliases for forums.
100
 */
101
function forum_pathauto_bulk_update_batch_process(&$context) {
102
  if (!isset($context['sandbox']['current'])) {
103
    $context['sandbox']['count'] = 0;
104
    $context['sandbox']['current'] = 0;
105
  }
106

    
107
  $query = db_select('taxonomy_term_data', 'td');
108
  $query->leftJoin('url_alias', 'ua', "CONCAT('forum/', td.tid) = ua.source");
109
  $query->addField('td', 'tid');
110
  $query->isNull('ua.source');
111
  $query->condition('td.tid', $context['sandbox']['current'], '>');
112
  $query->condition('td.vid', variable_get('forum_nav_vocabulary', ''));
113
  $query->orderBy('td.tid');
114
  $query->addTag('pathauto_bulk_update');
115
  $query->addMetaData('entity', 'taxonomy_term');
116

    
117
  // Get the total amount of items to process.
118
  if (!isset($context['sandbox']['total'])) {
119
    $context['sandbox']['total'] = $query->countQuery()->execute()->fetchField();
120

    
121
    // If there are no nodes to update, the stop immediately.
122
    if (!$context['sandbox']['total']) {
123
      $context['finished'] = 1;
124
      return;
125
    }
126
  }
127

    
128
  $query->range(0, 25);
129
  $tids = $query->execute()->fetchCol();
130

    
131
  pathauto_taxonomy_term_update_alias_multiple($tids, 'bulkupdate');
132
  $context['sandbox']['count'] += count($tids);
133
  $context['sandbox']['current'] = max($tids);
134
  $context['message'] = t('Updated alias for forum @tid.', array('@tid' => end($tids)));
135

    
136
  if ($context['sandbox']['count'] != $context['sandbox']['total']) {
137
    $context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
138
  }
139
}
140

    
141
/**
142
 * Batch processing callback; Generate aliases for users.
143
 */
144
function user_pathauto_bulk_update_batch_process(&$context) {
145
  if (!isset($context['sandbox']['current'])) {
146
    $context['sandbox']['count'] = 0;
147
    $context['sandbox']['current'] = 0;
148
  }
149

    
150
  $query = db_select('users', 'u');
151
  $query->leftJoin('url_alias', 'ua', "CONCAT('user/', u.uid) = ua.source");
152
  $query->addField('u', 'uid');
153
  $query->isNull('ua.source');
154
  $query->condition('u.uid', $context['sandbox']['current'], '>');
155
  $query->orderBy('u.uid');
156
  $query->addTag('pathauto_bulk_update');
157
  $query->addMetaData('entity', 'user');
158

    
159
  // Get the total amount of items to process.
160
  if (!isset($context['sandbox']['total'])) {
161
    $context['sandbox']['total'] = $query->countQuery()->execute()->fetchField();
162

    
163
    // If there are no nodes to update, the stop immediately.
164
    if (!$context['sandbox']['total']) {
165
      $context['finished'] = 1;
166
      return;
167
    }
168
  }
169

    
170
  $query->range(0, 25);
171
  $uids = $query->execute()->fetchCol();
172

    
173
  pathauto_user_update_alias_multiple($uids, 'bulkupdate', array('alias blog' => FALSE));
174
  $context['sandbox']['count'] += count($uids);
175
  $context['sandbox']['current'] = max($uids);
176
  $context['message'] = t('Updated alias for user @uid.', array('@uid' => end($uids)));
177

    
178
  if ($context['sandbox']['count'] != $context['sandbox']['total']) {
179
    $context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
180
  }
181
}
182

    
183
/**
184
 * Batch processing callback; Generate aliases for blogs.
185
 */
186
function blog_pathauto_bulk_update_batch_process(&$context) {
187
  if (!isset($context['sandbox']['current'])) {
188
    $context['sandbox']['count'] = 0;
189
    $context['sandbox']['current'] = 0;
190
  }
191

    
192
  $query = db_select('users', 'u');
193
  $query->leftJoin('url_alias', 'ua', "CONCAT('blog/', u.uid) = ua.source");
194
  $query->addField('u', 'uid');
195
  $query->isNull('ua.source');
196
  $query->condition('u.uid', $context['sandbox']['current'], '>');
197
  $query->orderBy('u.uid');
198
  $query->addTag('pathauto_bulk_update');
199
  $query->addMetaData('entity', 'user');
200

    
201
  // Get the total amount of items to process.
202
  if (!isset($context['sandbox']['total'])) {
203
    $context['sandbox']['total'] = $query->countQuery()->execute()->fetchField();
204

    
205
    // If there are no nodes to update, the stop immediately.
206
    if (!$context['sandbox']['total']) {
207
      $context['finished'] = 1;
208
      return;
209
    }
210
  }
211

    
212
  $query->range(0, 25);
213
  $uids = $query->execute()->fetchCol();
214

    
215
  $accounts = user_load_multiple($uids);
216
  foreach ($accounts as $account) {
217
    pathauto_blog_update_alias($account, 'bulkupdate');
218
  }
219

    
220
  $context['sandbox']['count'] += count($uids);
221
  $context['sandbox']['current'] = max($uids);
222
  $context['message'] = t('Updated alias for blog user @uid.', array('@uid' => end($uids)));
223

    
224
  if ($context['sandbox']['count'] != $context['sandbox']['total']) {
225
    $context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
226
  }
227
}