contrib modules security updates
This commit is contained in:
@@ -16,10 +16,28 @@
|
||||
function features_drush_command() {
|
||||
$items = array();
|
||||
|
||||
// If Features is enabled display the configured default export path,
|
||||
// otherwise just show the default.
|
||||
if (defined('FEATURES_DEFAULT_EXPORT_PATH')) {
|
||||
$path = variable_get('features_default_export_path', FEATURES_DEFAULT_EXPORT_PATH);
|
||||
}
|
||||
else {
|
||||
$path = 'sites/all/modules';
|
||||
}
|
||||
|
||||
$items['features-list'] = array(
|
||||
'description' => "List all the available features for your site.",
|
||||
'options' => array(
|
||||
'status' => "Feature status, can be 'enabled', 'disabled' or 'all'",
|
||||
),
|
||||
'drupal dependencies' => array('features'),
|
||||
'aliases' => array('fl', 'features'),
|
||||
'outputformat' => array(
|
||||
'default' => 'table',
|
||||
'pipe-format' => 'list',
|
||||
'field-labels' => array('name' => 'Name', 'feature' => 'Feature', 'status' => 'Status', 'version' => 'Version', 'state' => 'State'),
|
||||
'output-data-type' => 'format-table',
|
||||
),
|
||||
);
|
||||
$items['features-export'] = array(
|
||||
'description' => "Export a feature from your site into a module.",
|
||||
@@ -28,9 +46,10 @@ function features_drush_command() {
|
||||
'components' => 'Patterns of components to include, see features-components for the format of patterns.'
|
||||
),
|
||||
'options' => array(
|
||||
'destination' => "Destination path (from Drupal root) of the exported feature. Defaults to 'sites/all/modules'",
|
||||
'destination' => "Destination path (from Drupal root) of the exported feature. Defaults to '" . $path . "'.",
|
||||
'version-set' => "Specify a version number for the feature.",
|
||||
'version-increment' => "Increment the feature's version number.",
|
||||
'ignore-conflicts' => "Ignore conflicts and export all components.",
|
||||
),
|
||||
'drupal dependencies' => array('features'),
|
||||
'aliases' => array('fe'),
|
||||
@@ -60,6 +79,9 @@ function features_drush_command() {
|
||||
'not-exported' => array(
|
||||
'description' => 'Show only components that have not been exported.',
|
||||
),
|
||||
'info-style' => array(
|
||||
'description' => 'Export components in format suitable for using in an info file.',
|
||||
),
|
||||
),
|
||||
'aliases' => array('fc'),
|
||||
);
|
||||
@@ -114,10 +136,26 @@ function features_drush_command() {
|
||||
'arguments' => array(
|
||||
'feature' => 'The feature in question.',
|
||||
),
|
||||
'options' => array(
|
||||
'ctypes' => 'Comma separated list of component types to limit the output to. Defaults to all types.',
|
||||
'lines' => 'Generate diffs with <n> lines of context instead of the usual two.',
|
||||
),
|
||||
'drupal dependencies' => array('features', 'diff'),
|
||||
'aliases' => array('fd'),
|
||||
);
|
||||
|
||||
$items['features-diff-all'] = array(
|
||||
'description' => "Show the code difference for all enabled features not in their default state.",
|
||||
'arguments' => array(
|
||||
'feature_exclude' => 'A space-delimited list of features to exclude from being reverted.',
|
||||
),
|
||||
'options' => array(
|
||||
'force' => "Bypass the confirmations. This is useful if you want to output all of the diffs to a log file.",
|
||||
),
|
||||
'drupal dependencies' => array('features', 'diff'),
|
||||
'aliases' => array('fda'),
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
@@ -125,11 +163,20 @@ function features_drush_command() {
|
||||
* Implements hook_drush_help().
|
||||
*/
|
||||
function features_drush_help($section) {
|
||||
// If Features is enabled display the configured default export path,
|
||||
// otherwise just show the default.
|
||||
if (defined('FEATURES_DEFAULT_EXPORT_PATH')) {
|
||||
$path = variable_get('features_default_export_path', FEATURES_DEFAULT_EXPORT_PATH);
|
||||
}
|
||||
else {
|
||||
$path = 'sites/all/modules';
|
||||
}
|
||||
|
||||
switch ($section) {
|
||||
case 'drush:features':
|
||||
return dt("List all the available features for your site.");
|
||||
case 'drush:features-export':
|
||||
return dt("Export a feature from your site into a module. If called with no arguments, display a list of available components. If called with a single argument, attempt to create a feature including the given component with the same name. The option '--destination=foo' may be used to specify the path (from Drupal root) where the feature should be created. The default destination is 'sites/all/modules'. The option '--version-set=foo' may be used to specify a version number for the feature or the option '--version-increment' may also to increment the feature's version number.");
|
||||
return dt("Export a feature from your site into a module. If called with no arguments, display a list of available components. If called with a single argument, attempt to create a feature including the given component with the same name. The option '--destination=foo' may be used to specify the path (from Drupal root) where the feature should be created. The default destination is '@path'. The option '--version-set=foo' may be used to specify a version number for the feature or the option '--version-increment' may also to increment the feature's version number.", array('@path' => $path));
|
||||
case 'drush:features-components':
|
||||
return dt("List feature components matching patterns. The listing may be limited to exported/not-exported components.
|
||||
|
||||
@@ -160,9 +207,19 @@ Lastly, a pattern without a colon is interpreted as having \":%\" appended, for
|
||||
* Get a list of all feature modules.
|
||||
*/
|
||||
function drush_features_list() {
|
||||
$status = drush_get_option('status') ? drush_get_option('status') : 'all';
|
||||
if (!in_array($status, array('enabled', 'disabled', 'all'))) {
|
||||
return drush_set_error('', dt('!status is not valid', array('!status' => $status)));
|
||||
}
|
||||
|
||||
module_load_include('inc', 'features', 'features.export');
|
||||
$rows = array(array(dt('Name'), dt('Feature'), dt('Status'), dt('Version'), dt('State')));
|
||||
foreach (features_get_features(NULL, TRUE) as $k => $m) {
|
||||
|
||||
// Sort the Features list before compiling the output.
|
||||
$features = features_get_features(NULL, TRUE);
|
||||
ksort($features);
|
||||
|
||||
$rows = array();
|
||||
foreach ($features as $k => $m) {
|
||||
switch (features_get_storage($m->name)) {
|
||||
case FEATURES_DEFAULT:
|
||||
case FEATURES_REBUILDABLE:
|
||||
@@ -175,15 +232,23 @@ function drush_features_list() {
|
||||
$storage = dt('Needs review');
|
||||
break;
|
||||
}
|
||||
$rows[] = array(
|
||||
$m->info['name'],
|
||||
$m->name,
|
||||
$m->status ? dt('Enabled') : dt('Disabled'),
|
||||
$m->info['version'],
|
||||
$storage
|
||||
);
|
||||
if (
|
||||
($m->status == 0 && ($status == 'all' || $status == 'disabled')) ||
|
||||
($m->status == 1 && ($status == 'all' || $status == 'enabled'))
|
||||
) {
|
||||
$rows[$k] = array(
|
||||
'name' => $m->info['name'],
|
||||
'feature' => $m->name,
|
||||
'status' => $m->status ? dt('Enabled') : dt('Disabled'),
|
||||
'version' => $m->info['version'],
|
||||
'state' => $storage
|
||||
);
|
||||
}
|
||||
}
|
||||
drush_print_table($rows, TRUE);
|
||||
if (version_compare(DRUSH_VERSION, '6.0', '<')) {
|
||||
drush_print_table($rows, TRUE);
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,6 +257,7 @@ function drush_features_list() {
|
||||
function drush_features_components() {
|
||||
$args = func_get_args();
|
||||
$components = _drush_features_component_list();
|
||||
ksort($components);
|
||||
// If no args supplied, prompt with a list.
|
||||
if (empty($args)) {
|
||||
$types = array_keys($components);
|
||||
@@ -212,10 +278,13 @@ function drush_features_components() {
|
||||
elseif (drush_get_option(array('not-exported', 'o'), NULL)) {
|
||||
$options['exported'] = FALSE;
|
||||
}
|
||||
if (drush_get_option(array('info-style', 'is'), NULL)) {
|
||||
$options['info style'] = TRUE;
|
||||
}
|
||||
|
||||
$filtered_components = _drush_features_component_filter($components, $args, $options);
|
||||
if ($filtered_components){
|
||||
_drush_features_component_print($filtered_components);
|
||||
_drush_features_component_print($filtered_components, $options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,7 +318,7 @@ function _drush_features_component_filter($all_components, $patterns = array(),
|
||||
// First filter on exported state.
|
||||
foreach ($all_components as $source => $components) {
|
||||
foreach ($components as $name => $title) {
|
||||
$exported = sizeof($components_map[$source][$name]) > 0;
|
||||
$exported = !empty($components_map[$source][$name]);
|
||||
if ($exported) {
|
||||
if ($options['exported']) {
|
||||
$pool[$source][$name] = $title;
|
||||
@@ -277,7 +346,13 @@ function _drush_features_component_filter($all_components, $patterns = array(),
|
||||
// Rewrite * to %. Let users use both as wildcard.
|
||||
$pattern = strtr($pattern, array('*' => '%'));
|
||||
$sources = array();
|
||||
list($source_pattern, $component_pattern) = explode(':', $pattern, 2);
|
||||
if (strpos($pattern, ':') !== FALSE) {
|
||||
list($source_pattern, $component_pattern) = explode(':', $pattern, 2);
|
||||
}
|
||||
else {
|
||||
$source_pattern = $pattern;
|
||||
$component_pattern = '';
|
||||
}
|
||||
// If source is empty, use a pattern.
|
||||
if ($source_pattern == '') {
|
||||
$source_pattern = '%';
|
||||
@@ -342,7 +417,7 @@ function _drush_features_component_filter($all_components, $patterns = array(),
|
||||
return drush_set_error('', dt('Ambiguous component "!component", matches !matches', array('!component' => $component_pattern, '!matches' => join(', ', $matches))));
|
||||
}
|
||||
}
|
||||
if (!is_array($selected[$source])) {
|
||||
if (empty($selected[$source])) {
|
||||
$selected[$source] = array();
|
||||
}
|
||||
$selected[$source] += array_intersect_key($pool[$source], array_flip($matches));
|
||||
@@ -363,7 +438,7 @@ function _drush_features_component_filter($all_components, $patterns = array(),
|
||||
if ($options['provided by'] && $options['exported'] ) {
|
||||
foreach ($selected as $source => $components) {
|
||||
foreach ($components as $name => $title) {
|
||||
$exported = sizeof($components_map[$source][$name]) > 0;
|
||||
$exported = !empty($components_map[$source][$name]);
|
||||
if ($exported) {
|
||||
$provided_by[$source . ':' . $name] = join(', ', $components_map[$source][$name]);
|
||||
}
|
||||
@@ -380,11 +455,17 @@ function _drush_features_component_filter($all_components, $patterns = array(),
|
||||
/**
|
||||
* Prints a list of filtered components.
|
||||
*/
|
||||
function _drush_features_component_print($filtered_components) {
|
||||
function _drush_features_component_print($filtered_components, $options = array()) {
|
||||
$rows = array(array(dt('Available sources')));
|
||||
foreach ($filtered_components['components'] as $source => $components) {
|
||||
foreach ($components as $name => $value) {
|
||||
$row = array($source .':'. $name);
|
||||
if (!empty($options['info style'])) {
|
||||
// Output as .info file style.
|
||||
$row = array('features[' . $source . '][] = "' . $name . '"');
|
||||
}
|
||||
else {
|
||||
$row = array($source .':'. $name);
|
||||
}
|
||||
if (isset($filtered_components['sources'][$source .':'. $name])) {
|
||||
$row[] = dt('Provided by') . ': ' . $filtered_components['sources'][$source .':'. $name];
|
||||
}
|
||||
@@ -406,9 +487,11 @@ function drush_features_export() {
|
||||
return drush_set_error('', 'No components supplied.');
|
||||
}
|
||||
$components = _drush_features_component_list();
|
||||
$options = array(
|
||||
'exported' => FALSE,
|
||||
);
|
||||
$options = array();
|
||||
|
||||
if (!drush_get_option('ignore-conflicts', FALSE)) {
|
||||
$options['exported'] = FALSE;
|
||||
}
|
||||
|
||||
$filtered_components = _drush_features_component_filter($components, $args, $options);
|
||||
$items = $filtered_components['components'];
|
||||
@@ -429,12 +512,15 @@ function drush_features_export() {
|
||||
}
|
||||
else {
|
||||
// Same logic as in _drush_features_export. Should be refactored.
|
||||
$destination = drush_get_option(array('destination'), 'sites/all/modules');
|
||||
$destination = drush_get_option(array('destination'), variable_get('features_default_export_path', FEATURES_DEFAULT_EXPORT_PATH));
|
||||
$directory = isset($directory) ? $directory : $destination . '/' . $module;
|
||||
drush_print(dt('Will create a new module in !dir', array('!dir' => $directory)));
|
||||
if (!drush_confirm(dt('Do you really want to continue?'))) {
|
||||
drush_die('Aborting.');
|
||||
}
|
||||
$export = _drush_features_generate_export($items, $module);
|
||||
_features_populate($items, $export[info], $export[name]);
|
||||
_drush_features_export($export['info'], $module, $directory);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -449,8 +535,8 @@ function drush_features_export() {
|
||||
* This is DEPRECATED, but keeping it around for a bit longer for user migration
|
||||
*/
|
||||
function drush_features_add() {
|
||||
drush_print(dt('features_add is DEPRECATED.'));
|
||||
drush_print(dt('Calling features_export instead.'));
|
||||
drush_print(dt('features-add is DEPRECATED.'));
|
||||
drush_print(dt('Calling features-export instead.'));
|
||||
drush_features_export();
|
||||
}
|
||||
|
||||
@@ -464,7 +550,7 @@ function drush_features_update() {
|
||||
if (($feature = features_load_feature($module, TRUE)) && module_exists($module)) {
|
||||
_drush_features_export($feature->info, $feature->name, dirname($feature->filename));
|
||||
}
|
||||
else if ($feature) {
|
||||
elseif ($feature) {
|
||||
_features_drush_set_error($module, 'FEATURES_FEATURE_NOT_ENABLED');
|
||||
}
|
||||
else {
|
||||
@@ -494,15 +580,20 @@ function drush_features_update_all() {
|
||||
$features_to_update[] = $module->name;
|
||||
}
|
||||
}
|
||||
drush_print(dt('The following modules will be updated: !modules', array('!modules' => implode(', ', $features_to_update))));
|
||||
if (drush_confirm(dt('Do you really want to continue?'))) {
|
||||
foreach ($features_to_update as $module_name) {
|
||||
drush_invoke_process(drush_sitealias_get_record('@self'), 'features-update', array($module_name));
|
||||
}
|
||||
}
|
||||
else {
|
||||
drush_die('Aborting.');
|
||||
$dt_args = array('!modules' => implode(', ', $features_to_update));
|
||||
drush_print(dt('The following modules will be updated: !modules', $dt_args));
|
||||
if (!drush_confirm(dt('Do you really want to continue?'))) {
|
||||
return drush_user_abort('Aborting.');
|
||||
}
|
||||
// If we got here, set affirmative to TRUE, so that the user doesn't have to
|
||||
// confirm each and every feature. Start off by storing the current value,
|
||||
// so we can set it back afteward.
|
||||
$skip_confirmation = drush_get_context('DRUSH_AFFIRMATIVE');
|
||||
drush_set_context('DRUSH_AFFIRMATIVE', TRUE);
|
||||
// Now update all the features.
|
||||
drush_invoke('features-update', $features_to_update);
|
||||
// Now set it back as it was, in case other commands are called after this.
|
||||
drush_set_context('DRUSH_AFFIRMATIVE', $skip_confirmation);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -515,12 +606,14 @@ function drush_features_update_all() {
|
||||
*/
|
||||
function _drush_features_export($info, $module_name = NULL, $directory = NULL) {
|
||||
$root = drush_get_option(array('r', 'root'), drush_locate_root());
|
||||
$skip_confirmation = drush_get_context('DRUSH_AFFIRMATIVE');
|
||||
if ($root) {
|
||||
$destination = drush_get_option(array('destination'), 'sites/all/modules');
|
||||
$destination = drush_get_option(array('destination'), variable_get('features_default_export_path', FEATURES_DEFAULT_EXPORT_PATH));
|
||||
$directory = isset($directory) ? $directory : $destination . '/' . $module_name;
|
||||
if (is_dir($directory)) {
|
||||
drush_print(dt('Module appears to already exist in !dir', array('!dir' => $directory)));
|
||||
if (!drush_confirm(dt('Do you really want to continue?'))) {
|
||||
// If we aren't skipping confirmation and the directory already exists,
|
||||
// prompt the user. This message most make sense for but fe and fu.
|
||||
if (!$skip_confirmation && !drush_confirm(dt('Module located at !dir will be updated. Do you want to continue?', array('!dir' => $directory)))) {
|
||||
drush_die('Aborting.');
|
||||
}
|
||||
}
|
||||
@@ -528,36 +621,40 @@ function _drush_features_export($info, $module_name = NULL, $directory = NULL) {
|
||||
drush_op('mkdir', $directory);
|
||||
}
|
||||
if (is_dir($directory)) {
|
||||
// Ensure that the export will be created in the English language.
|
||||
// The export language must be set before flushing caches as that can
|
||||
// result into translatables being statically cached.
|
||||
$language = _features_export_language();
|
||||
|
||||
drupal_flush_all_caches();
|
||||
module_load_include('inc', 'features', 'features.export');
|
||||
$export = features_populate($info, $module_name);
|
||||
if (!features_load_feature($module_name)) {
|
||||
$export['name'] = $module_name;
|
||||
}
|
||||
// Set the feature version if the --version-set or --version-increment option is passed.
|
||||
if ($version = drush_get_option(array('version-set'))) {
|
||||
preg_match('/^(?P<core>\d+\.x)-(?P<major>\d+)\.(?P<patch>\d+)-?(?P<extra>\w+)?$/', $version, $matches);
|
||||
if (!isset($matches['core'], $matches['major'])) {
|
||||
drush_die(dt('Please enter a valid version with core and major version number. Example: !example', array('!example' => '7.x-1.0')));
|
||||
}
|
||||
$export['version'] = $version;
|
||||
}
|
||||
else if ($version = drush_get_option(array('version-increment'))) {
|
||||
// Determine current version and increment it.
|
||||
$export_load = features_export_prepare($export, $module_name);
|
||||
$version = $export_load['version'];
|
||||
$version_explode = explode('.', $version);
|
||||
$version_minor = array_pop($version_explode);
|
||||
// Increment minor version number if numeric or not a dev release.
|
||||
if (is_numeric($version_minor) || strpos($version_minor, 'dev') !== (strlen($version_minor) - 3)) {
|
||||
++$version_minor;
|
||||
}
|
||||
array_push($version_explode, $version_minor);
|
||||
// Rebuild version string.
|
||||
$version = implode('.', $version_explode);
|
||||
$export['version'] = $version;
|
||||
}
|
||||
$export = _drush_features_generate_export($info, $module_name);
|
||||
$files = features_export_render($export, $module_name, TRUE);
|
||||
|
||||
// Restore the language
|
||||
_features_export_language($language);
|
||||
|
||||
// Copy any files if _files key is there.
|
||||
if (!empty($files['_files'])) {
|
||||
foreach ($files['_files'] as $file_name => $file_info) {
|
||||
// See if files are in a sub directory.
|
||||
if (strpos($file_name, '/')) {
|
||||
$file_directory = $directory . '/' . substr($file_name, 0, strrpos($file_name, '/'));
|
||||
if (!is_dir($file_directory)) {
|
||||
drush_op('mkdir', $file_directory);
|
||||
}
|
||||
}
|
||||
if (!empty($file_info['file_path'])) {
|
||||
drush_op('file_unmanaged_copy', $file_info['file_path'], "{$directory}/{$file_name}", FILE_EXISTS_REPLACE);
|
||||
}
|
||||
elseif (!empty($file_info['file_content'])) {
|
||||
drush_op('file_put_contents', "{$directory}/{$file_name}", $file_info['file_content']);
|
||||
}
|
||||
else {
|
||||
drush_log(dt("Entry for @file_name.in !module is invalid. ", array('!module' => $module_name, '@file_name' => $file_name)), 'ok');
|
||||
}
|
||||
}
|
||||
unset($files['_files']);
|
||||
}
|
||||
foreach ($files as $extension => $file_contents) {
|
||||
if (!in_array($extension, array('module', 'info'))) {
|
||||
$extension .= '.inc';
|
||||
@@ -575,6 +672,59 @@ function _drush_features_export($info, $module_name = NULL, $directory = NULL) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for _drush_feature_export.
|
||||
*
|
||||
* @param $info
|
||||
* The feature info associative array.
|
||||
* @param $module_name
|
||||
* Optional. The name for the exported module.
|
||||
*/
|
||||
function _drush_features_generate_export(&$info, &$module_name) {
|
||||
module_load_include('inc', 'features', 'features.export');
|
||||
$export = features_populate($info, $module_name);
|
||||
if (!features_load_feature($module_name)) {
|
||||
$export['name'] = $module_name;
|
||||
}
|
||||
// Set the feature version if the --version-set or --version-increment option is passed.
|
||||
if ($version = drush_get_option(array('version-set'))) {
|
||||
preg_match('/^(?P<core>\d+\.x)-(?P<major>\d+)\.(?P<patch>\d+)-?(?P<extra>\w+)?$/', $version, $matches);
|
||||
if (!isset($matches['core'], $matches['major'])) {
|
||||
drush_die(dt('Please enter a valid version with core and major version number. Example: !example', array('!example' => '7.x-1.0')));
|
||||
}
|
||||
$export['version'] = $version;
|
||||
}
|
||||
elseif ($version = drush_get_option(array('version-increment'))) {
|
||||
// Determine current version and increment it.
|
||||
$export_load = features_export_prepare($export, $module_name);
|
||||
$version = $export_load['version'];
|
||||
$version_explode = explode('.', $version);
|
||||
$version_minor = array_pop($version_explode);
|
||||
// Increment minor version number if numeric or not a dev release.
|
||||
if (is_numeric($version_minor) || strpos($version_minor, 'dev') !== (strlen($version_minor) - 3)) {
|
||||
// Check for prefixed versions (alpha, beta, rc).
|
||||
if (ctype_digit($version_minor)) {
|
||||
++$version_minor;
|
||||
}
|
||||
else {
|
||||
// Split version number parts.
|
||||
$pattern = '/([0-9]-[a-z]+([0-9]+))/';
|
||||
$matches = array();
|
||||
preg_match($pattern, $version_minor, $matches);
|
||||
$number = array_pop($matches);
|
||||
++$number;
|
||||
$pattern = '/[0-9]+$/';
|
||||
$version_minor = preg_replace($pattern, $number, $version_minor);
|
||||
}
|
||||
}
|
||||
array_push($version_explode, $version_minor);
|
||||
// Rebuild version string.
|
||||
$version = implode('.', $version_explode);
|
||||
$export['version'] = $version;
|
||||
}
|
||||
return $export;
|
||||
}
|
||||
|
||||
/**
|
||||
* Revert a feature to it's code definition.
|
||||
* Optionally accept a list of components to revert.
|
||||
@@ -586,11 +736,16 @@ function drush_features_revert() {
|
||||
|
||||
// Determine if revert should be forced.
|
||||
$force = drush_get_option('force');
|
||||
// Determine if -y was supplied. If so, we can filter out needless output
|
||||
// from this command.
|
||||
$skip_confirmation = drush_get_context('DRUSH_AFFIRMATIVE');
|
||||
|
||||
// Parse list of arguments.
|
||||
$modules = array();
|
||||
foreach ($args as $arg) {
|
||||
list($module, $component) = explode('.', $arg);
|
||||
$arg = explode('.', $arg);
|
||||
$module = array_shift($arg);
|
||||
$component = array_shift($arg);
|
||||
|
||||
if (isset($module)) {
|
||||
if (empty($component)) {
|
||||
@@ -608,6 +763,7 @@ function drush_features_revert() {
|
||||
|
||||
// Process modules.
|
||||
foreach ($modules as $module => $components_needed) {
|
||||
$dt_args['@module'] = $module;
|
||||
if (($feature = features_load_feature($module, TRUE)) && module_exists($module)) {
|
||||
|
||||
$components = array();
|
||||
@@ -623,7 +779,8 @@ function drush_features_revert() {
|
||||
else {
|
||||
$states = features_get_component_states(array($feature->name), FALSE);
|
||||
foreach ($states[$feature->name] as $component => $state) {
|
||||
if (in_array($state, array(FEATURES_OVERRIDDEN, FEATURES_NEEDS_REVIEW, FEATURES_REBUILDABLE)) && features_hook($component, 'features_revert')) {
|
||||
$revertable_states = array(FEATURES_OVERRIDDEN, FEATURES_NEEDS_REVIEW, FEATURES_REBUILDABLE);
|
||||
if (in_array($state, $revertable_states) && features_hook($component, 'features_revert')) {
|
||||
$components[] = $component;
|
||||
}
|
||||
}
|
||||
@@ -637,17 +794,24 @@ function drush_features_revert() {
|
||||
}
|
||||
else {
|
||||
foreach ($components as $component) {
|
||||
if (drush_confirm(dt('Do you really want to revert @component?', array('@component' => $component)))) {
|
||||
features_revert(array($module => array($component)));
|
||||
drush_log(dt('Reverted @component.', array('@component' => $component)), 'ok');
|
||||
$dt_args['@component'] = $component;
|
||||
$confirmation_message = 'Do you really want to revert @module.@component?';
|
||||
if ($skip_confirmation || drush_confirm(dt($confirmation_message, $dt_args))) {
|
||||
if (features_feature_is_locked($module, $component)) {
|
||||
drush_log(dt('Skipping locked @module.@component.', $dt_args), 'ok');
|
||||
}
|
||||
else {
|
||||
features_revert(array($module => array($component)));
|
||||
drush_log(dt('Reverted @module.@component.', $dt_args), 'ok');
|
||||
}
|
||||
}
|
||||
else {
|
||||
drush_log(dt('Skipping @component.', array('@component' => $component)), 'ok');
|
||||
drush_log(dt('Skipping @module.@component.', $dt_args), 'ok');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($feature) {
|
||||
elseif ($feature) {
|
||||
_features_drush_set_error($module, 'FEATURES_FEATURE_NOT_ENABLED');
|
||||
}
|
||||
else {
|
||||
@@ -656,7 +820,7 @@ function drush_features_revert() {
|
||||
}
|
||||
}
|
||||
else {
|
||||
drush_features_list();
|
||||
drush_print_table(drush_features_list());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -692,15 +856,13 @@ function drush_features_revert_all() {
|
||||
}
|
||||
|
||||
if ($features_to_revert) {
|
||||
drush_print(dt('The following modules will be reverted: !modules', array('!modules' => implode(', ', $features_to_revert))));
|
||||
if (drush_confirm(dt('Do you really want to continue?'))) {
|
||||
foreach ($features_to_revert as $module) {
|
||||
drush_invoke_process(drush_sitealias_get_record('@self'), 'features-revert', array($module), array('force' => $force, '#integrate' => TRUE));
|
||||
}
|
||||
}
|
||||
else {
|
||||
$dt_args = array('!modules' => implode(', ', $features_to_revert));
|
||||
drush_print(dt('The following modules will be reverted: !modules', $dt_args));
|
||||
// Confirm that the user would like to continue. If not, simply abort.
|
||||
if (!drush_confirm(dt('Do you really want to continue?'))) {
|
||||
return drush_user_abort('Aborting.');
|
||||
}
|
||||
drush_invoke('features-revert', $features_to_revert);
|
||||
}
|
||||
else {
|
||||
drush_log(dt('Current state already matches defaults, aborting.'), 'ok');
|
||||
@@ -712,10 +874,15 @@ function drush_features_revert_all() {
|
||||
*/
|
||||
function drush_features_diff() {
|
||||
if (!$args = func_get_args()) {
|
||||
drush_features_list();
|
||||
drush_print_table(drush_features_list());
|
||||
return;
|
||||
}
|
||||
$module = $args[0];
|
||||
$filter_ctypes = drush_get_option("ctypes");
|
||||
if ($filter_ctypes) {
|
||||
$filter_ctypes = explode(',', $filter_ctypes);
|
||||
}
|
||||
|
||||
$feature = features_load_feature($module);
|
||||
if (!module_exists($module)) {
|
||||
drush_log(dt('No such feature is enabled: ' . $module), 'error');
|
||||
@@ -733,11 +900,11 @@ function drush_features_diff() {
|
||||
if (drush_confirm(dt('It seems that the Diff module is not available. Would you like to download and enable it?'))) {
|
||||
// Download it if it's not already here.
|
||||
$project_info = drush_get_projects();
|
||||
if (empty($project_info['diff']) && !drush_invoke_process(drush_sitealias_get_record('@self'), 'dl', array('diff'), array('#integrate' => TRUE))) {
|
||||
if (empty($project_info['diff']) && !drush_invoke('dl', array('diff'))) {
|
||||
return drush_set_error(dt('Diff module could not be downloaded.'));
|
||||
}
|
||||
|
||||
if (!drush_invoke_process(drush_sitealias_get_record('@self'), 'en', array('diff'), array('#integrate' => TRUE))) {
|
||||
if (!drush_invoke('en', array('diff'))) {
|
||||
return drush_set_error(dt('Diff module could not be enabled.'));
|
||||
}
|
||||
}
|
||||
@@ -748,9 +915,12 @@ function drush_features_diff() {
|
||||
module_load_include('inc', 'diff', 'diff.engine');
|
||||
}
|
||||
|
||||
$lines = (int) drush_get_option('lines');
|
||||
$lines = $lines > 0 ? $lines : 2;
|
||||
|
||||
$formatter = new DiffFormatter();
|
||||
$formatter->leading_context_lines = 2;
|
||||
$formatter->trailing_context_lines = 2;
|
||||
$formatter->leading_context_lines = $lines;
|
||||
$formatter->trailing_context_lines = $lines;
|
||||
$formatter->show_header = FALSE;
|
||||
|
||||
if (drush_get_context('DRUSH_NOCOLOR')) {
|
||||
@@ -767,10 +937,13 @@ function drush_features_diff() {
|
||||
drush_print(sprintf($green, dt('Overrides: drush features-update will update the exported feature with the displayed overrides')));
|
||||
drush_print();
|
||||
|
||||
if ($filter_ctypes) {
|
||||
$overrides = array_intersect_key($overrides, array_flip($filter_ctypes));
|
||||
}
|
||||
foreach ($overrides as $component => $items) {
|
||||
$diff = new Diff(explode("\n", $items['default']), explode("\n", $items['normal']));
|
||||
drush_print();
|
||||
drush_print(dt("Component: !component", array('!component' => $component)));
|
||||
drush_print(dt("Component type: !component", array('!component' => $component)));
|
||||
$rows = explode("\n", $formatter->format($diff));
|
||||
foreach ($rows as $row) {
|
||||
if (strpos($row, '>') === 0) {
|
||||
@@ -786,6 +959,62 @@ function drush_features_diff() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Diff all enabled features that are not in their default state.
|
||||
*
|
||||
* @param ...
|
||||
* (Optional) A list of features to exclude from being reverted.
|
||||
*/
|
||||
function drush_features_diff_all() {
|
||||
module_load_include('inc', 'features', 'features.export');
|
||||
$features_to_exclude = func_get_args();
|
||||
|
||||
$features_to_revert = array();
|
||||
foreach (features_get_features(NULL, TRUE) as $module) {
|
||||
if ($module->status && !in_array($module->name, $features_to_exclude)) {
|
||||
switch (features_get_storage($module->name)) {
|
||||
case FEATURES_OVERRIDDEN:
|
||||
case FEATURES_NEEDS_REVIEW:
|
||||
case FEATURES_REBUILDABLE:
|
||||
$features_to_diff[] = $module->name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($features_to_diff) {
|
||||
|
||||
// Check if the user wants to apply the force option.
|
||||
$force = drush_get_option('force');
|
||||
|
||||
if($force) {
|
||||
foreach ($features_to_diff as $module) {
|
||||
|
||||
drush_print(dt('Diff for !module:', array('!module' => $module)));
|
||||
|
||||
drush_invoke_process(drush_sitealias_get_record('@self'), 'features-diff', array($module));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
drush_print(dt('A diff will be performed for the following modules: !modules',
|
||||
array('!modules' => implode(', ', $features_to_diff))
|
||||
));
|
||||
|
||||
if (drush_confirm(dt('Do you want to continue?'))) {
|
||||
foreach ($features_to_diff as $module) {
|
||||
if (drush_confirm(dt('Diff !module?', array('!module' => $module)))) {
|
||||
drush_invoke_process(drush_sitealias_get_record('@self'), 'features-diff', array($module));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return drush_user_abort('Aborting.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to call drush_set_error().
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user