You are here

function node_authlink_batch_generate in Node authorize link 7

Same name and namespace in other branches
  1. 8 node_authlink.module \node_authlink_batch_generate()

Callback: Generate authkeys for all nodes in node type.

1 string reference to 'node_authlink_batch_generate'
node_authlink_form_node_type_form_alter in ./node_authlink.module
Implements hook_form_node_type_form_alter().

File

./node_authlink.module, line 93
Provides functionality for the node_authlink module.

Code

function node_authlink_batch_generate(&$form, &$form_state) {

  // Load NIDs that are not in the authkeys table.
  $query = db_select('node', 'n');
  $query
    ->leftJoin('node_authlink_nodes', 'a', 'n.nid = a.nid');
  $query
    ->fields('n', array(
    'nid',
  ))
    ->condition('type', $form_state['values']['type'])
    ->isNull('authkey');
  $nids = $query
    ->execute()
    ->fetchCol();

  // Create keys.
  foreach ($nids as $nid) {
    node_authlink_node_insert($nid);
    if (module_exists('entitycache')) {
      cache_clear_all($nid, 'cache_entity_node');
    }
  }
  drupal_set_message(t('%num authkeys has been generated.', array(
    '%num' => count($nids),
  )));
}