forena-8.x-1.x-dev/forena.drush.inc

forena.drush.inc
<?php
/**
 * @file forena.drush.inc
 * Implementation of drush command hook.
 */
function forena_drush_command() {
  $items = array();

  $items['forena-deliver-reports'] = array(
    'description' => 'Forena Revert Delivered module provided forena reports',
    'examples' => array('drush frxrevert'),
    'aliases' => array('frxcp', 'frxrevert'),
  );
  $items['forena-report'] = array(
    'description' => 'Render a report',
    'arguments' => array(
  	  'report_uri' => 'The name of the report to render.  Include parameters as url parameters to the report as you would see them on the url',
      'filename' => 'The file to write the report data to',
    ),
    'options' => array('language'),
    'aliases' => array('frx'),
  	'examples' => array(
  	  'drush forena-report sample/states.html states.html' => 'Export an html report as a simple table',
  	  "drush forena-report 'sample/user_distribution_simple.xml?state=wa wa.xml'" => 'Export the states as an xml for washington sate',
    ),
  );
  return $items;
}


/**
 * Execute copy of the reports from drush.
 */
function drush_forena_deliver_reports() {
  require_once 'forena.common.inc';
  require_once 'forena.admin.inc';
  forena_sync_reports(TRUE);
}

/**
 * Run a report to a fiel.
 */
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)));

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc