function drush_uc_csv_export in Ubercart CSV 7.2
Drush export cvs file from ubercart command callback
We need to basically create a report on the fly and create a report object to send to the fuction which generates this
File
- ./
uc_csv.drush.inc, line 113
Code
function drush_uc_csv_export($of = NULL) {
$form = $form_state = array();
// Convert order-by into our legacy options so we don't have to re-write our schema
$order_by = drush_get_option('order-by');
$order_by($order_by != 'order-id' && $order_by != 'last-name') ? 'orderid' : $order_by;
if ($order_by == 'last-name') {
$order_by = 'last_name';
}
elseif ($order_by == 'order-id') {
$order_by = 'orderid';
}
// Sanity check on the file type, defaulting to csv if all else fails
$file_type = drush_get_option('file-type');
$file_type($file_type != 'csv' && $file_type != 'xls') ? 'csv' : $file_type;
// Simulate a report by generating the report object used by the creation process.
// TODO: make all currently assigned items (save track) selectable as options in
// the command line.
$report = new stdClass();
$report->volatile = TRUE;
$report->shipping_address = drush_get_option('shipping-address');
$report->billing_address = drush_get_option('billing-address');
$report->products = drush_get_option('products');
$report->track = FALSE;
$report->start_date = drush_get_option('start-date');
$report->end_date = drush_get_option('end-date');
$report->file_type = $file_type;
$report->order_by = $order_by;
$report->report_name = !empty($of) ? $of : 'exported_report';
$report->email_address = drush_get_option('email');
$report->email_enable = !empty($report->email_address) ? TRUE : FALSE;
// For now we will assume all statuses are to be exported as part of this report.
// We may want to make it in the future so you can select which statuses are to
// be exported, but that could be confusing.
$result = db_query("SELECT order_status_id\n FROM {uc_order_statuses}\n ORDER BY weight ASC");
while ($sdata = $result
->fetchObject()) {
$statuses[] = $sdata->order_status_id;
}
$report->statuses = serialize($statuses);
// Generate the report
$data = uc_csv_select_report_to_export_submit($form, $form_state, $report);
if ($report->email_enable == FALSE) {
// Save the report to our specified location or right here if nothing selected.
_uc_csv_save_report($report, $data['contents'], $report->report_name);
}
}