diff --git a/features.api.php b/features.api.php index 8094846..4195406 100644 --- a/features.api.php +++ b/features.api.php @@ -158,7 +158,7 @@ function hook_features_export_render($module_name, $data, $export = NULL) { $code[] = " \$mycomponents['{$name}'] = " . features_var_export(mycomponent_load($name)) .";"; } $code[] = "return \$mycomponents;"; - $code = implode("\n", $mycomponents); + $code = implode("\n", $code); return array('mycomponent_defaults' => $code); } @@ -227,6 +227,18 @@ function hook_features_export_alter(&$export, $module_name) { } /** + * TODO + */ +function hook_features_consolidate($data, &$export, $module_name) { + // The following is the simplest implementation of a straight object export + // with no further export processors called. + foreach ($data as $component) { + $export['mycomponent'][$component] = $component; + } + return array(); +} + +/** * Alter the pipe array for a given component. This hook should be implemented * with the name of the component type in place of `component` in the function * name, e.g. `features_pipe_views_alter()` will alter the pipe for the Views diff --git a/features.drush.inc b/features.drush.inc index 52e39f0..cdefd5f 100644 --- a/features.drush.inc +++ b/features.drush.inc @@ -29,6 +29,19 @@ function features_drush_command() { 'drupal dependencies' => array('features'), 'aliases' => array('fe'), ); + $items['features-consolidate'] = array( + 'description' => "Consolidate a feature to the database.", + 'drupal dependencies' => array('features'), + 'aliases' => array('fc'), + ); + $items['features-consolidate-all'] = array( + 'description' => "Consolidate all features to the database.", + 'drupal dependencies' => array('features'), + 'options' => array( + 'exclude' => "A comma-separated list of features to exclude from consolidate.", + ), + 'aliases' => array('fca'), + ); $items['features-update'] = array( 'description' => "Update a feature module on your site.", 'arguments' => array( @@ -88,6 +101,10 @@ function features_drush_help($section) { 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."); + case 'drush:features-consolidate': + return dt("Consolidate a feature to the database."); + case 'drush:features-consolidate-all': + return dt("Consolidate all features to the database."); case 'drush:features-update': return dt("Update a feature module on your site."); case 'drush:features-update-all': @@ -170,6 +187,58 @@ function drush_features_export() { } /** + * Consolidate a feature to the database. + */ +function drush_features_consolidate() { + if ($args = func_get_args()) { + foreach ($args as $module) { + if (($feature = feature_load($module, TRUE)) && module_exists($module)) { + drush_log(dt("Consolidating features for module !module", array('!module' => $module)), 'notice'); + _drush_features_consolidate($feature->info['features'], $module); + } + else if ($feature) { + _features_drush_set_error($module, 'FEATURES_FEATURE_NOT_ENABLED'); + } + else { + _features_drush_set_error($module); + } + } + } + else { + // By default just show contexts that are available. + $rows = array(array(dt('Available features'))); + foreach (features_get_features(NULL, TRUE) as $name => $info) { + $rows[] = array($name); + } + drush_print_table($rows, TRUE); + } +} + +/** + * Consolidate all features to the database. + */ +function drush_features_consolidate_all() { + $features_to_consolidate = array(); + $features_to_exclude = _convert_csv_to_array(drush_get_option('exclude')); + + $features = features_get_features(); + foreach ($features as $module) { + if ($module->status && !in_array($module->name, $features_to_exclude)) { + $features_to_consolidate[] = $module->name; + } + } + drush_print(dt('The following modules will be consolidated: !modules', array('!modules' => implode(', ', $features_to_consolidate)))); + if (drush_confirm(dt('Do you really want to continue?'))) { + foreach ($features_to_consolidate as $module_name) { + drush_invoke_process('@self', 'features-consolidate', array($module_name)); + } + } + else { + return drush_user_abort(); + } +} + +/** * Update an existing feature module. */ function drush_features_update() { @@ -266,6 +335,17 @@ function _drush_features_export($stub, $dependencies, $module_name = NULL, $dire } /** + * Consolidate a feature to the database. + */ +function _drush_features_consolidate($features = array(), $module_name = '') { + features_include(); + foreach ($features as $component => $items) { + drush_log(dt("Running consolidate for component !component", array('!component' => $component)), 'notice'); + features_invoke($component, 'features_consolidate', $items, $module_name); + } +} + +/** * Revert a feature to it's code definition. */ function drush_features_revert() { @@ -312,7 +392,7 @@ function drush_features_revert() { } } } - else if ($feature) { + elseif ($feature) { _features_drush_set_error($module, 'FEATURES_FEATURE_NOT_ENABLED'); } else { diff --git a/includes/features.context.inc b/includes/features.context.inc index ba9d45f..59fd16e 100644 --- a/includes/features.context.inc +++ b/includes/features.context.inc @@ -229,3 +229,14 @@ function context_features_revert($module = NULL) { function context_features_identifier_2($object) { return isset($object->namespace, $object->attribute, $object->value) ? "{$object->namespace}-{$object->attribute}-{$object->value}" : FALSE; } + +/** + * Implementation of hook_features_consolidate(). + */ +function context_features_consolidate($items = array(), $module_name = '') { + foreach ($items as $context_name) { + if ($context = context_load($context_name)) { + context_save($context); + } + } +} diff --git a/includes/features.imagecache.inc b/includes/features.imagecache.inc index daacd6f..9713d72 100644 --- a/includes/features.imagecache.inc +++ b/includes/features.imagecache.inc @@ -89,3 +89,23 @@ function _imagecache_features_preset_sanitize(&$preset) { } } } + +/** + * Implementation of hook_features_consolidate(). + */ +function imagecache_features_consolidate($items = array(), $module_name = '') { + foreach ($items as $preset_name) { + $preset = imagecache_preset_by_name($preset_name, TRUE); + // Presets + if (!is_numeric($preset['presetid'])) { + $preset = imagecache_preset_save($preset); + // Actions + if (is_numeric($preset['presetid'])) { + foreach ($preset['actions'] as $action) { + $action['presetid'] = $preset['presetid']; + imagecache_action_save($action); + } + } + } + } +} diff --git a/includes/features.node.inc b/includes/features.node.inc index 5aa0b87..88e8eca 100644 --- a/includes/features.node.inc +++ b/includes/features.node.inc @@ -159,3 +159,14 @@ function node_features_revert($module = NULL) { menu_rebuild(); } } + +/** + * Implementation of hook_features_consolidate(). + */ +function node_features_consolidate($items = array(), $module_name = '') { + // Delegate responsibility to node module + foreach ($items as $node_type) { + drush_log(dt("Reset node_type !node_type", array('!node_type' => $node_type)), 'notice'); + db_query("UPDATE {node_type} SET module = 'node', modified = 1 WHERE type = '%s' AND module = 'features'", array($node_type)); + } +} diff --git a/includes/features.views.inc b/includes/features.views.inc index 071b86d..247cf84 100644 --- a/includes/features.views.inc +++ b/includes/features.views.inc @@ -264,3 +264,13 @@ function views_features_revert($module) { menu_rebuild(); } } + +/** + * Implementation of hook_features_consolidate(). + */ +function views_features_consolidate($items = array(), $module_name = '') { + foreach ($items as $view_name) { + $view = views_get_view($view_name); + $view->save(); + } +}