You are here

function tft_archive_folder_batch_process in Taxonomy File Tree 7

Same name and namespace in other branches
  1. 7.2 tft.module \tft_archive_folder_batch_process()

Processes the batch logic.

1 string reference to 'tft_archive_folder_batch_process'
tft_archive_folder_batch in ./tft.module
Defines a batch for adding an archive folder to all groups that do not have one.

File

./tft.module, line 1409
Module hooks.

Code

function tft_archive_folder_batch_process(&$context) {
  module_load_include('inc', 'tft', 'tft.admin');
  if (empty($context['sandbox'])) {
    $context['sandbox']['progress'] = 0;
    $context['sandbox']['max'] = (int) db_query("SELECT COUNT(*) FROM {node} WHERE type = 'og'")
      ->fetchField();
    $context['finished'] = 0;
  }
  $result = db_query("SELECT * FROM {node} WHERE type = 'og' LIMIT :limit, 10", array(
    ':limit' => $context['sandbox']['progress'],
  ));
  while ($node = $result
    ->fetchObject()) {
    $og_tid = tft_get_og_tid($node->nid);
    $archive_tid = tft_get_archive_tid($og_tid);
    if (empty($archive_tid)) {
      $form_state = array();
      $form_state['values']['name'] = "Archives";
      $form_state['values']['parent'] = $og_tid;
      tft_add_term_form_submit(array(), $form_state);
    }
    $context['sandbox']['progress']++;
  }

  // Set the percentage for the loadbar
  if ($context['sandbox']['progress'] < $context['sandbox']['max'] && !$stop) {
    $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
  }
  else {
    $context['finished'] = 1;
  }
}