pathauto.pathauto.inc 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <?php
  2. /**
  3. * @file
  4. * Pathauto integration for core modules.
  5. *
  6. * @ingroup pathauto
  7. */
  8. /**
  9. * Batch processing callback; Generate aliases for nodes.
  10. */
  11. function node_pathauto_bulk_update_batch_process(&$context) {
  12. if (!isset($context['sandbox']['current'])) {
  13. $context['sandbox']['count'] = 0;
  14. $context['sandbox']['current'] = 0;
  15. }
  16. $query = db_select('node', 'n');
  17. $query->leftJoin('url_alias', 'ua', "CONCAT('node/', n.nid) = ua.source");
  18. $query->addField('n', 'nid');
  19. $query->isNull('ua.source');
  20. $query->condition('n.nid', $context['sandbox']['current'], '>');
  21. $query->orderBy('n.nid');
  22. $query->addTag('pathauto_bulk_update');
  23. $query->addMetaData('entity', 'node');
  24. // Get the total amount of items to process.
  25. if (!isset($context['sandbox']['total'])) {
  26. $context['sandbox']['total'] = $query->countQuery()->execute()->fetchField();
  27. // If there are no nodes to update, the stop immediately.
  28. if (!$context['sandbox']['total']) {
  29. $context['finished'] = 1;
  30. return;
  31. }
  32. }
  33. $query->range(0, 25);
  34. $nids = $query->execute()->fetchCol();
  35. pathauto_node_update_alias_multiple($nids, 'bulkupdate');
  36. $context['sandbox']['count'] += count($nids);
  37. $context['sandbox']['current'] = max($nids);
  38. $context['message'] = t('Updated alias for node @nid.', array('@nid' => end($nids)));
  39. if ($context['sandbox']['count'] != $context['sandbox']['total']) {
  40. $context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
  41. }
  42. }
  43. /**
  44. * Batch processing callback; Generate aliases for taxonomy terms.
  45. */
  46. function taxonomy_pathauto_bulk_update_batch_process(&$context) {
  47. if (!isset($context['sandbox']['current'])) {
  48. $context['sandbox']['count'] = 0;
  49. $context['sandbox']['current'] = 0;
  50. }
  51. $query = db_select('taxonomy_term_data', 'td');
  52. $query->leftJoin('url_alias', 'ua', "CONCAT('taxonomy/term/', td.tid) = ua.source");
  53. $query->addField('td', 'tid');
  54. $query->isNull('ua.source');
  55. $query->condition('td.tid', $context['sandbox']['current'], '>');
  56. // Exclude the forums terms.
  57. if ($forum_vid = variable_get('forum_nav_vocabulary', '')) {
  58. $query->condition('td.vid', $forum_vid, '<>');
  59. }
  60. $query->orderBy('td.tid');
  61. $query->addTag('pathauto_bulk_update');
  62. $query->addMetaData('entity', 'taxonomy_term');
  63. // Get the total amount of items to process.
  64. if (!isset($context['sandbox']['total'])) {
  65. $context['sandbox']['total'] = $query->countQuery()->execute()->fetchField();
  66. // If there are no nodes to update, the stop immediately.
  67. if (!$context['sandbox']['total']) {
  68. $context['finished'] = 1;
  69. return;
  70. }
  71. }
  72. $query->range(0, 25);
  73. $tids = $query->execute()->fetchCol();
  74. pathauto_taxonomy_term_update_alias_multiple($tids, 'bulkupdate');
  75. $context['sandbox']['count'] += count($tids);
  76. $context['sandbox']['current'] = max($tids);
  77. $context['message'] = t('Updated alias for term @tid.', array('@tid' => end($tids)));
  78. if ($context['sandbox']['count'] != $context['sandbox']['total']) {
  79. $context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
  80. }
  81. }
  82. /**
  83. * Batch processing callback; Generate aliases for forums.
  84. */
  85. function forum_pathauto_bulk_update_batch_process(&$context) {
  86. if (!isset($context['sandbox']['current'])) {
  87. $context['sandbox']['count'] = 0;
  88. $context['sandbox']['current'] = 0;
  89. }
  90. $query = db_select('taxonomy_term_data', 'td');
  91. $query->leftJoin('url_alias', 'ua', "CONCAT('forum/', td.tid) = ua.source");
  92. $query->addField('td', 'tid');
  93. $query->isNull('ua.source');
  94. $query->condition('td.tid', $context['sandbox']['current'], '>');
  95. $query->condition('td.vid', variable_get('forum_nav_vocabulary', ''));
  96. $query->orderBy('td.tid');
  97. $query->addTag('pathauto_bulk_update');
  98. $query->addMetaData('entity', 'taxonomy_term');
  99. // Get the total amount of items to process.
  100. if (!isset($context['sandbox']['total'])) {
  101. $context['sandbox']['total'] = $query->countQuery()->execute()->fetchField();
  102. // If there are no nodes to update, the stop immediately.
  103. if (!$context['sandbox']['total']) {
  104. $context['finished'] = 1;
  105. return;
  106. }
  107. }
  108. $query->range(0, 25);
  109. $tids = $query->execute()->fetchCol();
  110. pathauto_taxonomy_term_update_alias_multiple($tids, 'bulkupdate');
  111. $context['sandbox']['count'] += count($tids);
  112. $context['sandbox']['current'] = max($tids);
  113. $context['message'] = t('Updated alias for forum @tid.', array('@tid' => end($tids)));
  114. if ($context['sandbox']['count'] != $context['sandbox']['total']) {
  115. $context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
  116. }
  117. }
  118. /**
  119. * Batch processing callback; Generate aliases for users.
  120. */
  121. function user_pathauto_bulk_update_batch_process(&$context) {
  122. if (!isset($context['sandbox']['current'])) {
  123. $context['sandbox']['count'] = 0;
  124. $context['sandbox']['current'] = 0;
  125. }
  126. $query = db_select('users', 'u');
  127. $query->leftJoin('url_alias', 'ua', "CONCAT('user/', u.uid) = ua.source");
  128. $query->addField('u', 'uid');
  129. $query->isNull('ua.source');
  130. $query->condition('u.uid', $context['sandbox']['current'], '>');
  131. $query->orderBy('u.uid');
  132. $query->addTag('pathauto_bulk_update');
  133. $query->addMetaData('entity', 'user');
  134. // Get the total amount of items to process.
  135. if (!isset($context['sandbox']['total'])) {
  136. $context['sandbox']['total'] = $query->countQuery()->execute()->fetchField();
  137. // If there are no nodes to update, the stop immediately.
  138. if (!$context['sandbox']['total']) {
  139. $context['finished'] = 1;
  140. return;
  141. }
  142. }
  143. $query->range(0, 25);
  144. $uids = $query->execute()->fetchCol();
  145. pathauto_user_update_alias_multiple($uids, 'bulkupdate', array('alias blog' => FALSE));
  146. $context['sandbox']['count'] += count($uids);
  147. $context['sandbox']['current'] = max($uids);
  148. $context['message'] = t('Updated alias for user @uid.', array('@uid' => end($uids)));
  149. if ($context['sandbox']['count'] != $context['sandbox']['total']) {
  150. $context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
  151. }
  152. }
  153. /**
  154. * Batch processing callback; Generate aliases for blogs.
  155. */
  156. function blog_pathauto_bulk_update_batch_process(&$context) {
  157. if (!isset($context['sandbox']['current'])) {
  158. $context['sandbox']['count'] = 0;
  159. $context['sandbox']['current'] = 0;
  160. }
  161. $query = db_select('users', 'u');
  162. $query->leftJoin('url_alias', 'ua', "CONCAT('blog/', u.uid) = ua.source");
  163. $query->addField('u', 'uid');
  164. $query->isNull('ua.source');
  165. $query->condition('u.uid', $context['sandbox']['current'], '>');
  166. $query->orderBy('u.uid');
  167. $query->addTag('pathauto_bulk_update');
  168. $query->addMetaData('entity', 'user');
  169. // Get the total amount of items to process.
  170. if (!isset($context['sandbox']['total'])) {
  171. $context['sandbox']['total'] = $query->countQuery()->execute()->fetchField();
  172. // If there are no nodes to update, the stop immediately.
  173. if (!$context['sandbox']['total']) {
  174. $context['finished'] = 1;
  175. return;
  176. }
  177. }
  178. $query->range(0, 25);
  179. $uids = $query->execute()->fetchCol();
  180. $accounts = user_load_multiple($uids);
  181. foreach ($accounts as $account) {
  182. pathauto_blog_update_alias($account, 'bulkupdate');
  183. }
  184. $context['sandbox']['count'] += count($uids);
  185. $context['sandbox']['current'] = max($uids);
  186. $context['message'] = t('Updated alias for blog user @uid.', array('@uid' => end($uids)));
  187. if ($context['sandbox']['count'] != $context['sandbox']['total']) {
  188. $context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
  189. }
  190. }