You are here

function taxonomy_csv_vocabulary_export in Taxonomy CSV import/export 6.5

Same name and namespace in other branches
  1. 6.2 export/taxonomy_csv.export.api.inc \taxonomy_csv_vocabulary_export()
  2. 6.3 export/taxonomy_csv.export.api.inc \taxonomy_csv_vocabulary_export()
  3. 6.4 export/taxonomy_csv.export.api.inc \taxonomy_csv_vocabulary_export()
  4. 7.5 export/taxonomy_csv.export.api.inc \taxonomy_csv_vocabulary_export()
  5. 7.4 export/taxonomy_csv.export.api.inc \taxonomy_csv_vocabulary_export()

Prepare the export of a vocabulary. If not used in a form, don't forget to use batch_process().

Parameters

$options: Array. Same as taxonomy_csv_export.

Return value

Array of errors or nothing (batch process to execute).

2 calls to taxonomy_csv_vocabulary_export()
taxonomy_csv_export in export/taxonomy_csv.export.api.inc
Process the export of a vocabulary.
taxonomy_csv_form_export_submit in export/taxonomy_csv.export.admin.inc
Handles CSV export form submission and launch batch set.

File

export/taxonomy_csv.export.api.inc, line 113
Validate export options and manage export process.

Code

function taxonomy_csv_vocabulary_export($options) {

  // Check options and return array of messages in case of errors.
  if ($options['check_options']) {

    // Invoke export admin file.
    $module_dir = drupal_get_path('module', 'taxonomy_csv');
    require_once "{$module_dir}/export/taxonomy_csv.export.admin.inc";
    $result = _taxonomy_csv_export_check_options($options);
    if (count($result)) {
      return $result;
    }
  }

  // Complete $options with some csv variables.
  $options['separator'] = $options['enclosure'] . $options['delimiter'] . $options['enclosure'];
  $line_ending = array(
    'Unix' => "\n",
    'Mac' => "\r",
    'MS-DOS' => "\r\n",
  );
  $options['end_of_line'] = $line_ending[$options['line_ending']];

  // Calculates number of terms to be exported.
  $options['total_terms'] = taxonomy_csv_vocabulary_count_terms($options['vocabulary_id']);

  // Prepare export batch.
  $batch = array(
    'title' => t('Exporting !total_terms terms to CSV file...', array(
      '!total_terms' => $options['total_terms'],
    )),
    'init_message' => t('Starting downloading of datas...') . '<br />' . t('Wait some seconds for pre-processing...'),
    'progress_message' => '',
    'error_message' => t('An error occurred during the export.'),
    'finished' => '_taxonomy_csv_vocabulary_export_finished',
    'file' => drupal_get_path('module', 'taxonomy_csv') . '/export/taxonomy_csv.export.api.inc',
    'progressive' => TRUE,
    'operations' => array(
      0 => array(
        '_taxonomy_csv_vocabulary_export_process',
        array(
          $options,
        ),
      ),
    ),
  );
  batch_set($batch);
}