function drush_forena_report in Forena Reports 8
Same name and namespace in other branches
- 7.5 forena.drush.inc \drush_forena_report()
- 7.4 forena.drush.inc \drush_forena_report()
Run a report to a fiel.
File
- ./
forena.drush.inc, line 43 - forena.drush.inc Implementation of drush command hook.
Code
function drush_forena_report($report_uri, $filename = '') {
$parms = array();
$query = '';
$m1 = memory_get_usage();
$t1 = time();
if (strpos($report_uri, '?')) {
list($report_name, $query) = explode('?', $report_uri);
}
else {
$report_name = $report_uri;
}
if ($query) {
parse_str($query, $parms);
}
$content = \Drupal\forena\ReportManager::instance()
->report($report_name, $parms);
$d = \Drupal\forena\DocManager::instance();
$doc_type = $d
->getDocumentType();
$email_override = \Drupal::config('forena.settings')
->get('email_override');
$user = \Drupal::currentUser();
$email = $email_override ? $user
->getEmail() : '';
switch ($doc_type) {
case 'drupal':
$content = $content['report']['#template'];
break;
case 'email':
/** @var \Drupal\forena\FrxPlugin\Document\EmailMerge $merge */
$merge = $d
->getDocument();
$merge
->sendMail($email, 0);
break;
}
if ($filename) {
drupal_set_message(t('Writing report %s to %f.', array(
'%s' => $report_name,
'%f' => $filename,
)));
file_put_contents($filename, $content);
}
else {
drupal_set_message(t('Generating report %s.', array(
'%s' => $report_name,
)));
print $content;
}
$t2 = time();
$m2 = memory_get_usage();
$p = memory_get_peak_usage();
$dur = $t2 - $t1;
$mem = $m2 - $m1;
drupal_set_message(t('Finished Report ( %s seconds, %b bytes, peak %p)', array(
'%s' => $dur,
'%b' => $mem,
'%p' => $p,
)));
}