Created
October 27, 2012 11:40
-
-
Save damiankloip/3964368 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Drush views execute command. | |
*/ | |
function drush_views_execute($view_name, $display_id = 'default') { | |
$args = func_get_args(); | |
$view_args = array(); | |
// If it's more than 2, we have arguments. A display has to be specified in | |
// that case. | |
if (count($args) > 2) { | |
$view_args = array_slice($args, 2); | |
} | |
if (!$view = views_get_view($view_name)) { | |
drush_set_error(dt('View: "@view" not found.', array('@view' => $view_name))); | |
return; | |
} | |
// Set the display and execute the view. | |
$view->setDisplay($display_id); | |
if (!empty($view_args)) { | |
$view->preExecute($view_args); | |
} | |
$view->execute(); | |
if (drush_get_option('count', FALSE)) { | |
$count = count($view->result); | |
drush_print('Result count: ' . $count); | |
return $count; | |
} | |
elseif (!empty($view->result)) { | |
// If HTML output if being displayed we don't want to run this through | |
// drush_format. | |
if (drush_get_option('html', FALSE)) { | |
$output = $view->preview(); | |
} | |
else { | |
$output = drush_format($view->result); | |
} | |
// Print the results. | |
drush_print($output); | |
return $output; | |
} | |
else { | |
drush_log(dt('No results returned for this view.') ,'warning'); | |
return NULL; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment