updated contrib modules
This commit is contained in:
@@ -2,14 +2,15 @@
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Drush integration of views.
|
||||
* Drush integration for Views.
|
||||
*
|
||||
* drush cache-clear views - Clears the views specific caches.
|
||||
* views-revert - Drush command to revert views overridden in the system.
|
||||
* Useful commands:
|
||||
* - drush cache-clear views - Clears the views specific caches.
|
||||
* - views-revert - Drush command to revert views overridden in the system.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implement hook_drush_help().
|
||||
* Implements hook_drush_help().
|
||||
*/
|
||||
function views_drush_help($section) {
|
||||
switch ($section) {
|
||||
@@ -18,17 +19,20 @@ function views_drush_help($section) {
|
||||
$help .= dt('If no view names are specified, you will be presented with a list of overridden views to choose from. ');
|
||||
$help .= dt('To revert all views, do not specify any view names, and choose the option "All" from the options presented.');
|
||||
return $help;
|
||||
|
||||
case 'drush:views-list':
|
||||
return dt('Show a list of available views with information about them.');
|
||||
|
||||
case 'drush:views-enable':
|
||||
return dt('Enable the specified views. Follow the command with a space delimited list of view names');
|
||||
|
||||
case 'drush:views-disable':
|
||||
return dt('Disable the specified views. Follow the command with a space delimited list of view names');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement hook_drush_command().
|
||||
* Implements hook_drush_command().
|
||||
*/
|
||||
function views_drush_command() {
|
||||
$items = array();
|
||||
@@ -70,7 +74,7 @@ function views_drush_command() {
|
||||
'tags' => 'A comma-separated list of views tags by which to filter the results.',
|
||||
'status' => 'Status of the views by which to filter the results. Choices: enabled, disabled.',
|
||||
'type' => 'Type of the views by which to filter the results. Choices: normal, default or overridden.',
|
||||
),
|
||||
),
|
||||
'examples' => array(
|
||||
'drush vl' => 'Show a list of all available views.',
|
||||
'drush vl --name=blog' => 'Show a list of views which names contain "blog".',
|
||||
@@ -115,10 +119,11 @@ function views_drush_command() {
|
||||
* Callback function for views-revert command.
|
||||
*/
|
||||
function views_revert_views() {
|
||||
$args = func_get_args();
|
||||
// The provided views names specified in the command.
|
||||
$viewnames = _convert_csv_to_array($args);
|
||||
$views = views_get_all_views();
|
||||
$i = 0;
|
||||
// The provided views names specified in the command.
|
||||
$viewnames = _convert_csv_to_array(func_get_args());
|
||||
|
||||
// Find all overridden views.
|
||||
foreach ($views as $view) {
|
||||
@@ -143,10 +148,10 @@ function views_revert_views() {
|
||||
// If the user specified a list of views on the CLI, revert those.
|
||||
elseif (!empty($viewnames)) {
|
||||
foreach ($viewnames as $key => $viewname) {
|
||||
$is_overridden = key_exists($viewname, $overridden);
|
||||
$is_overridden = array_key_exists($viewname, $overridden);
|
||||
|
||||
// Check if the provided view name is in the system
|
||||
if ($viewname && !key_exists($viewname, $views)) {
|
||||
// Check if the provided view name is in the system.
|
||||
if ($viewname && !array_key_exists($viewname, $views)) {
|
||||
drush_set_error(dt("'@viewname' view is not present in the system.", array('@viewname' => $viewname)));
|
||||
}
|
||||
// Check if the provided view is overridden.
|
||||
@@ -158,7 +163,7 @@ function views_revert_views() {
|
||||
views_revert_view($views[$viewname]);
|
||||
$i++;
|
||||
}
|
||||
// We should never get here but well...
|
||||
// We should never get here but well.
|
||||
else {
|
||||
drush_set_error(dt(
|
||||
"The view specified '@viewname' is not provided in code, and thus cannot be reverted.",
|
||||
@@ -168,19 +173,20 @@ function views_revert_views() {
|
||||
}
|
||||
}
|
||||
|
||||
// The user neither selected the "--all" option, nor provided a list of views to revert.
|
||||
// Prompt the user.
|
||||
// The user neither selected the "--all" option, nor provided a list of views
|
||||
// to revert. Prompt the user.
|
||||
else {
|
||||
// list of choices for the user
|
||||
$overridden['all'] = dt('Revert all overridden views'); // add a choice at the end
|
||||
$choice = drush_choice($overridden, 'Enter a number to choose which view to revert.', '!key'); // prompt the user
|
||||
|
||||
// List of choices for the user.
|
||||
$overridden['all'] = dt('Revert all overridden views');
|
||||
// Add a choice at the end.
|
||||
$choice = drush_choice($overridden, 'Enter a number to choose which view to revert.', '!key');
|
||||
// Prompt the user.
|
||||
if ($choice !== FALSE) {
|
||||
// revert all views option
|
||||
// Revert all views option.
|
||||
if ($choice == 'all') {
|
||||
$i = views_revert_allviews($views);
|
||||
}
|
||||
// else the user specified a single view
|
||||
// Else the user specified a single view.
|
||||
else {
|
||||
views_revert_view($views[$choice]);
|
||||
$i++;
|
||||
@@ -189,7 +195,7 @@ function views_revert_views() {
|
||||
|
||||
}
|
||||
|
||||
// final results output
|
||||
// Final results output.
|
||||
if ($i == 0) {
|
||||
drush_log(dt('No views were reverted.'), 'ok');
|
||||
}
|
||||
@@ -199,9 +205,10 @@ function views_revert_views() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverts all views
|
||||
* @param $views
|
||||
* All views in the system as provided by views_get_all_views().
|
||||
* Reverts all views.
|
||||
*
|
||||
* @param array $views
|
||||
* All views in the system as provided by views_get_all_views().
|
||||
*/
|
||||
function views_revert_allviews($views) {
|
||||
$i = 0;
|
||||
@@ -219,15 +226,17 @@ function views_revert_allviews($views) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Revert a specified view
|
||||
* @param $view
|
||||
* The view object to be reverted
|
||||
* Revert a specified view.
|
||||
*
|
||||
* Checks on wether or not the view is overridden is handled in views_revert_views_revert()
|
||||
* We perform a check here anyway in case someone somehow calls this function on their own...
|
||||
* Checks on wether or not the view is overridden is handled in
|
||||
* views_revert_views_revert(). We perform a check here anyway in case someone
|
||||
* somehow calls this function on their own...
|
||||
*
|
||||
* @param object $view
|
||||
* The view object to be reverted.
|
||||
*/
|
||||
function views_revert_view($view) {
|
||||
// check anyway just in case
|
||||
// Check anyway just in case.
|
||||
if ($view->type == t('Overridden')) {
|
||||
// Revert the view.
|
||||
$view->delete();
|
||||
@@ -269,7 +278,7 @@ function views_development_settings() {
|
||||
* Callback function for views-list command.
|
||||
*/
|
||||
function drush_views_list() {
|
||||
// Initialize stuf
|
||||
// Initialize stuff.
|
||||
$rows = array();
|
||||
$disabled_views = array();
|
||||
$enabled_views = array();
|
||||
@@ -281,19 +290,18 @@ function drush_views_list() {
|
||||
|
||||
$views = views_get_all_views();
|
||||
|
||||
// get the --name option
|
||||
// TODO : take into account the case off a comma-separated list of names
|
||||
// Get the --name option.
|
||||
// @todo Take into account the case off a comma-separated list of names.
|
||||
$name = drush_get_option_list('name');
|
||||
$with_name = !empty($name) ? TRUE : FALSE;
|
||||
|
||||
// get the --tags option
|
||||
// Get the --tags option.
|
||||
$tags = drush_get_option_list('tags');
|
||||
$with_tags = !empty($tags) ? TRUE : FALSE;
|
||||
|
||||
// get the --status option
|
||||
// store user input appart to reuse it after
|
||||
// Get the --status option. Store user input appart to reuse it after.
|
||||
$status_opt = drush_get_option_list('status');
|
||||
// use the same logic than $view->disabled
|
||||
// Use the same logic than $view->disabled.
|
||||
if (in_array('disabled', $status_opt)) {
|
||||
$status = TRUE;
|
||||
$with_status = TRUE;
|
||||
@@ -304,19 +312,19 @@ function drush_views_list() {
|
||||
}
|
||||
else {
|
||||
$status = NULL;
|
||||
// wrong or empty --status option
|
||||
// Wrong or empty --status option.
|
||||
$with_status = FALSE;
|
||||
}
|
||||
|
||||
// get the --type option
|
||||
// Get the --type option.
|
||||
$type = drush_get_option_list('type');
|
||||
// use the same logic than $view->type
|
||||
// Use the same logic than $view->type.
|
||||
$with_type = FALSE;
|
||||
if (in_array('normal', $type) || in_array('default', $type)|| in_array('overridden', $type)) {
|
||||
$with_type = TRUE;
|
||||
}
|
||||
|
||||
// set the table headers
|
||||
// Set the table headers.
|
||||
$header = array(
|
||||
dt('Machine name'),
|
||||
dt('Description'),
|
||||
@@ -325,10 +333,10 @@ function drush_views_list() {
|
||||
dt('Tag'),
|
||||
);
|
||||
|
||||
// setup a row for each view
|
||||
foreach($views as $id => $view){
|
||||
// if options were specified, check that first
|
||||
// mismatch push the loop to the next view
|
||||
// Setup a row for each view.
|
||||
foreach ($views as $id => $view) {
|
||||
// If options were specified, check that first mismatch push the loop to
|
||||
// the next view.
|
||||
if ($with_tags && !in_array($view->tag, $tags)) {
|
||||
continue;
|
||||
}
|
||||
@@ -343,25 +351,25 @@ function drush_views_list() {
|
||||
}
|
||||
|
||||
$row = array();
|
||||
// each row entry should be in the same order as the header
|
||||
// Each row entry should be in the same order as the header.
|
||||
$row[] = $view->name;
|
||||
$row[] = $view->description;
|
||||
$row[] = $view->type;
|
||||
$row[] = $view->disabled ? dt('Disabled') : dt('Enabled');
|
||||
$row[] = $view->tag;
|
||||
|
||||
// place the row in the appropiate array,
|
||||
// so we can have disabled views at the bottom
|
||||
if($view->disabled) {
|
||||
// Place the row in the appropiate array so we can have disabled views at
|
||||
// the bottom.
|
||||
if ($view->disabled) {
|
||||
$disabled_views[] = $row;
|
||||
}
|
||||
else{
|
||||
}
|
||||
else {
|
||||
$enabled_views[] = $row;
|
||||
}
|
||||
unset($row);
|
||||
|
||||
// gather some statistics
|
||||
switch($view->type) {
|
||||
// Gather some statistics.
|
||||
switch ($view->type) {
|
||||
case dt('Normal'):
|
||||
$indb++;
|
||||
break;
|
||||
@@ -379,11 +387,11 @@ function drush_views_list() {
|
||||
|
||||
$disabled = count($disabled_views);
|
||||
|
||||
// sort alphabeticaly
|
||||
// Sort alphabeticaly.
|
||||
asort($disabled_views);
|
||||
asort($enabled_views);
|
||||
|
||||
// if options were used
|
||||
// If options were used.
|
||||
$summary = "";
|
||||
if ($with_name || $with_tags || $with_status || $with_type) {
|
||||
$summary = "Views";
|
||||
@@ -412,23 +420,26 @@ function drush_views_list() {
|
||||
drush_print($summary . "\n");
|
||||
}
|
||||
|
||||
// print all rows as a table
|
||||
// Print all rows as a table.
|
||||
if ($total > 0) {
|
||||
$rows = array_merge($enabled_views, $disabled_views);
|
||||
// put the headers as first row
|
||||
// Put the headers as first row.
|
||||
array_unshift($rows, $header);
|
||||
|
||||
drush_print_table($rows, TRUE);
|
||||
}
|
||||
|
||||
// print the statistics messages
|
||||
// Print the statistics messages.
|
||||
drush_print(dt("A total of @total views were found in this Drupal installation:", array('@total' => $total)));
|
||||
drush_print(dt(" @indb views reside only in the database", array('@indb' => $indb )));
|
||||
drush_print(dt(" @indb views reside only in the database", array('@indb' => $indb)));
|
||||
drush_print(dt(" @over views are overridden", array('@over' => $overridden)));
|
||||
drush_print(dt(" @incode views are in their default state", array('@incode' => $incode)));
|
||||
drush_print(dt(" @dis views are disabled\n", array('@dis' => $disabled)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze all installed views.
|
||||
*/
|
||||
function drush_views_analyze() {
|
||||
views_include('analyze');
|
||||
$messages_count = 0;
|
||||
@@ -440,7 +451,7 @@ function drush_views_analyze() {
|
||||
drush_print($view_name);
|
||||
foreach ($messages as $message) {
|
||||
$messages_count++;
|
||||
drush_print($message['type'] .': '. $message['message'], 2);
|
||||
drush_print($message['type'] . ': ' . $message['message'], 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -448,7 +459,7 @@ function drush_views_analyze() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables views
|
||||
* Enables views.
|
||||
*/
|
||||
function drush_views_enable() {
|
||||
$viewnames = _convert_csv_to_array(func_get_args());
|
||||
@@ -460,7 +471,7 @@ function drush_views_enable() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables views
|
||||
* Disables views.
|
||||
*/
|
||||
function drush_views_disable() {
|
||||
$viewnames = _convert_csv_to_array(func_get_args());
|
||||
@@ -472,9 +483,12 @@ function drush_views_disable() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to enable / disable views
|
||||
* @param $viewnames: array of viewnames to process
|
||||
* @param $status: TRUE to disable or FALSE to enable the view
|
||||
* Helper function to enable / disable views.
|
||||
*
|
||||
* @param array $viewnames
|
||||
* Names of the views to process.
|
||||
* @param bool $status
|
||||
* TRUE to disable or FALSE to enable the view.
|
||||
*/
|
||||
function _views_drush_changestatus($viewnames = array(), $status = NULL) {
|
||||
if ($status !== NULL && !empty($viewnames)) {
|
||||
@@ -492,7 +506,7 @@ function _views_drush_changestatus($viewnames = array(), $status = NULL) {
|
||||
drush_set_error(dt("The view '!name' is already !processed", array('!name' => $viewname, '!processed' => $processed)));
|
||||
}
|
||||
}
|
||||
// If we made changes to views status, save them and clear caches
|
||||
// If we made changes to views status, save them and clear caches.
|
||||
if ($changed) {
|
||||
variable_set('views_defaults', $views_status);
|
||||
views_invalidate_cache();
|
||||
@@ -504,6 +518,9 @@ function _views_drush_changestatus($viewnames = array(), $status = NULL) {
|
||||
|
||||
/**
|
||||
* Adds a cache clear option for views.
|
||||
*
|
||||
* @param array $types
|
||||
* The list of cache types that are available.
|
||||
*/
|
||||
function views_drush_cache_clear(&$types) {
|
||||
$types['views'] = 'views_invalidate_cache';
|
||||
|
Reference in New Issue
Block a user