Advertisement
Guest User

Untitled

a guest
Jul 11th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. function foiagen_menu() {
  2. $items['node/%node/foia-generator'] = array(
  3. 'title' => 'Foia Generator',
  4. 'description' => 'A foia generator form.',
  5. 'page callback' => 'drupal_get_form',
  6. 'page arguments' => array('foiagen_form', 1),
  7. 'access callback' => TRUE,
  8. );
  9. return $items;
  10. }
  11. function foiagen_form($form, &$form_state) {
  12. $form['submit_button'] = array(
  13. '#type' => 'submit',
  14. '#value' => t('Generate FOIA'),
  15. );
  16. return $form;
  17. }
  18. function foiagen_form_submit($form, &$form_state) {
  19. }
  20.  
  21. //Implement hook_path_alias_types().
  22. function foiagen_path_alias_types() {
  23. $objects = array();
  24. $objects[foiagen_internal_path] = t('Foiagens');
  25. return $objects;
  26. }
  27. //Implement hook_pathauto
  28. function foiagen_pathauto($op) {
  29. switch ($op) {
  30. case 'settings':
  31. $settings = array();
  32. $settings['module'] = 'foiagen';
  33. $settings['token_type'] = 'node';
  34. $settings['groupheader'] = t('foiagen paths');
  35. $settings['patterndescr'] = t('Pattern for foiagen');
  36. $settings['patterndefault'] = 'schools/[node:title]/foiagenerator';
  37. $settings['batch_update_callback'] =
  38. 'foiagen_pathauto_bulk_update_batch_process';
  39. return (object) $settings;
  40. default:
  41. break;
  42. }
  43. }
  44. //Batch processing callback; Generate aliases for subsites.
  45. function foiagen_pathauto_bulk_update_batch_process(&$context) {
  46. if (!isset($context['sandbox']['current'])) {
  47. $context['sandbox']['count'] = 0;
  48. $context['sandbox']['current'] = 0;
  49. }
  50. $query = db_select('node', 'n');
  51. //$query->leftJoin('url_alias', 'ua', "CONCAT(foiagen_internal_path, n.nid) = ua.source");
  52. $query->addField('n', 'nid');
  53. //$query->isNull('ua.source');
  54. $query->condition('n.nid', $context['sandbox']['current'], '>');
  55. $query->orderBy('n.nid');
  56. $query->addTag('pathauto_bulk_update');
  57. $query->addMetaData('entity', 'node');
  58. $query->fields('n', array('nid'));
  59. // Get the total amount of items to process.
  60. if (!isset($context['sandbox']['total'])) {
  61. $context['sandbox']['total'] = $query->countQuery()->execute()->fetchField();
  62. //If there are no nodes to update, the stop immediately.
  63. if (!$context['sandbox']['total']) {
  64. $context['finished'] = 1;
  65. return;
  66. }
  67. }
  68. $query->range(0, 25);
  69. $nids = $query->execute()->fetchCol();
  70. foiagen_update_alias_multiple($nids, 'bulkupdate');
  71. $context['sandbox']['count'] += count($nids);
  72. $context['sandbox']['current'] = max($nids);
  73. $context['message'] = t('Updated foiagen alias for node @nid.', array('@nid' => end($nids)));
  74. if ($context['sandbox']['count'] != $context['sandbox']['total']) {
  75. $context['finished'] = $context['sandbox']['count'] / $context['sandbox'}['total'];
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement