You are here

function metatag_import_export_csv_download_nid in Metatag Import Export CSV 7

Gets the list of nid's according to content type.

2 calls to metatag_import_export_csv_download_nid()
drush_metatag_import_export_csv_metatag_export in ./metatag_import_export_csv.drush.inc
Drush callback for export operation.
metatag_import_export_csv_download_submit in ./metatag_import_export_csv_download_admin.inc
Submit Handler for Export Operation.

File

./metatag_import_export_csv_download_admin.inc, line 64
Stores the code for export process.

Code

function metatag_import_export_csv_download_nid($type, $delimeter) {
  $scheme = variable_get('file_default_scheme', 'public');
  $file_path = $scheme . "://metatag_import_export_csv/";
  $filename = "metatag_import_export_csv_" . $type . ".csv";
  if (!file_prepare_directory($file_path, FILE_CREATE_DIRECTORY)) {
    drupal_set_message(t('Unable to create directory in file system. Check permissions and try again.'), 'error');
    return;
  }
  $type_name = $type;
  $query = db_select('node', 'n')
    ->fields('n', array(
    'nid',
  ));
  if ($type != 'all') {
    $query
      ->condition('type', $type);
  }
  elseif ($type = 'all') {
    $type_list = metatag_import_export_csv_type_list();
    $type_list = array_keys($type_list);
    $query
      ->condition('type', $type_list, 'IN');
  }
  $results = $query
    ->execute()
    ->fetchAll();
  $batch = array(
    'operations' => array(),
    'finished' => 'metatag_import_export_csv_finish_batch_download',
    'title' => t("Processing Nodes for exporting Metatags"),
    'init_message' => t("Starting Metatag export Process"),
    'progress_message' => t("Processed @current out of @total Nodes"),
    'file' => drupal_get_path('module', 'metatag_import_export_csv') . '/metatag_import_export_csv_download_admin.inc',
    'error_message' => t("Metatag export process has encountered an error."),
  );
  foreach ($results as $values) {
    $batch['operations'][] = array(
      'metatag_import_export_csv_start_batch_download',
      array(
        $values->nid,
        $type,
        $delimeter,
      ),
    );
  }
  batch_set($batch);
  if (drupal_is_cli()) {
    $batch =& batch_get();
    $batch['progressive'] = FALSE;
    drush_backend_batch_process();
  }
  else {
    batch_process('admin/config/search/metatags/export');
  }
}