You are here

function community_tags_delete_all_form_submit in Community Tags 6.2

Same name and namespace in other branches
  1. 6 community_tags.admin.inc \community_tags_delete_all_form_submit()
  2. 7 community_tags.admin.inc \community_tags_delete_all_form_submit()

Submit handler for community_tags_delete_all_form().

File

./community_tags.admin.inc, line 445
community_tags.admin.inc

Code

function community_tags_delete_all_form_submit($form, &$form_state) {
  $vid = $form['#vocabulary']->vid;
  $content_type = $form['#content_type_obj']->type;
  $settings = $form['#ct_settings'];
  if (isset($form['#delete_ops']['#quick_delete'])) {
    db_query("DELETE FROM ct\n       USING {community_tags} ct, {term_data} AS td, {node} AS n\n       WHERE ct.tid = td.tid\n       AND td.vid = %d\n       AND ct.nid = n.nid\n       AND n.type = '%s'", $vid, $content_type);
    drupal_set_message(t('@delete_count community tags deleted.', array(
      '@delete_count' => db_affected_rows(),
    )));
  }
  else {

    // do batched delete
    $operations = array();
    $mode = $form['#ct_settings']['opmode'];

    // set up the tag delete operations
    // remove mode flags for unchecked mode options
    if ($settings['opmode'] & COMMUNITY_TAGS_OPMODE_DELETE_ORPHAN_TERMS && empty($form_state['values']['delete_policy'])) {

      // unset
      $mode = $settings['opmode'] &= ~COMMUNITY_TAGS_OPMODE_DELETE_ORPHAN_TERMS;
    }
    $config = array(
      'ct_settings' => array(
        'opmode' => $mode,
      ),
    );
    $operations[] = array(
      'community_tags_delete_tags_batch_process',
      array(
        $vid,
        $content_type,
        $form['#counts'],
        $mode,
      ),
    );
    $batch = array(
      'operations' => $operations,
      'finished' => 'community_tags_batch_finished',
      'title' => t('Processing Community Tags Delete Batch'),
      'init_message' => t('Community Tags Delete Batch is starting.'),
      // 'progress_message' => t('Processed @current out of @total.'),
      'error_message' => t('Community Tags Delete Batch has encountered an error.'),
      'file' => drupal_get_path('module', 'community_tags') . '/community_tags.batch.inc',
    );
    batch_set($batch);
  }
}