Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function foiagen_menu() {
- $items['node/%node/foia-generator'] = array(
- 'title' => 'Foia Generator',
- 'description' => 'A foia generator form.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('foiagen_form', 1),
- 'access callback' => TRUE,
- );
- return $items;
- }
- function foiagen_form($form, &$form_state) {
- $form['submit_button'] = array(
- '#type' => 'submit',
- '#value' => t('Generate FOIA'),
- );
- return $form;
- }
- function foiagen_form_submit($form, &$form_state) {
- }
- //Implement hook_path_alias_types().
- function foiagen_path_alias_types() {
- $objects = array();
- $objects[foiagen_internal_path] = t('Foiagens');
- return $objects;
- }
- //Implement hook_pathauto
- function foiagen_pathauto($op) {
- switch ($op) {
- case 'settings':
- $settings = array();
- $settings['module'] = 'foiagen';
- $settings['token_type'] = 'node';
- $settings['groupheader'] = t('foiagen paths');
- $settings['patterndescr'] = t('Pattern for foiagen');
- $settings['patterndefault'] = 'schools/[node:title]/foiagenerator';
- $settings['batch_update_callback'] =
- 'foiagen_pathauto_bulk_update_batch_process';
- return (object) $settings;
- default:
- break;
- }
- }
- //Batch processing callback; Generate aliases for subsites.
- function foiagen_pathauto_bulk_update_batch_process(&$context) {
- if (!isset($context['sandbox']['current'])) {
- $context['sandbox']['count'] = 0;
- $context['sandbox']['current'] = 0;
- }
- $query = db_select('node', 'n');
- //$query->leftJoin('url_alias', 'ua', "CONCAT(foiagen_internal_path, n.nid) = ua.source");
- $query->addField('n', 'nid');
- //$query->isNull('ua.source');
- $query->condition('n.nid', $context['sandbox']['current'], '>');
- $query->orderBy('n.nid');
- $query->addTag('pathauto_bulk_update');
- $query->addMetaData('entity', 'node');
- $query->fields('n', array('nid'));
- // Get the total amount of items to process.
- if (!isset($context['sandbox']['total'])) {
- $context['sandbox']['total'] = $query->countQuery()->execute()->fetchField();
- //If there are no nodes to update, the stop immediately.
- if (!$context['sandbox']['total']) {
- $context['finished'] = 1;
- return;
- }
- }
- $query->range(0, 25);
- $nids = $query->execute()->fetchCol();
- foiagen_update_alias_multiple($nids, 'bulkupdate');
- $context['sandbox']['count'] += count($nids);
- $context['sandbox']['current'] = max($nids);
- $context['message'] = t('Updated foiagen alias for node @nid.', array('@nid' => end($nids)));
- if ($context['sandbox']['count'] != $context['sandbox']['total']) {
- $context['finished'] = $context['sandbox']['count'] / $context['sandbox'}['total'];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement