You are here

function _uc_csv_save_report in Ubercart CSV 7.2

Save the report

Take the contents and place into a file. Make the uri to the file part of the report object so it can be saved when completed

2 calls to _uc_csv_save_report()
drush_uc_csv_export in ./uc_csv.drush.inc
Drush export cvs file from ubercart command callback
drush_uc_csv_export_report in ./uc_csv.drush.inc
Do the report

File

./uc_csv.module, line 810

Code

function _uc_csv_save_report(&$report, $contents, $file_name) {
  if (drupal_is_cli() && function_exists('drush_main')) {
    file_put_contents($file_name, $contents);
    $report->filepath = getcwd() . '/' . $file_name;
    drush_log('File successfully saved.', 'ok');
  }
  else {
    if (!file_exists(drupal_realpath('public://uc-csv-reports/'))) {
      drupal_mkdir('public://uc-csv-reports/');
    }
    $destination = 'public://uc-csv-reports/' . $file_name;
    $filepath = file_unmanaged_save_data($contents, $destination, FILE_EXISTS_REPLACE);
    if ($filepath != FALSE) {
      $report->filepath = $filepath;
    }
    else {
      $report->filepath = FALSE;
      drupal_set_message('File could not be saved or assigned.', 'error');
    }
  }
}