diff --git a/features.admin.inc b/features.admin.inc index fd996c5..f1bbe5a 100644 --- a/features.admin.inc +++ b/features.admin.inc @@ -332,7 +332,7 @@ function features_admin_form($form, $form_state) { $modules = array_filter(features_get_modules(), 'features_filter_hidden'); $features = array_filter(features_get_features(), 'features_filter_hidden'); $conflicts = features_get_conflicts(); - + foreach ($modules as $key => $module) { if ($module->status && !empty($module->info['dependencies'])) { foreach ($module->info['dependencies'] as $dependent) { @@ -346,7 +346,7 @@ function features_admin_form($form, $form_state) { if ( empty($features) ) { $form['no_features'] = array( '#markup' => t('No Features were found. Please use the !create_link link to create - a new Feature module, or upload an existing Feature to your modules directory.', + a new Feature module, or upload an existing Feature to your modules directory.', array('!create_link' => l(t('Create Feature'), 'admin/structure/features/create'))), ); return $form ; @@ -461,7 +461,9 @@ function features_admin_form($form, $form_state) { // Add in recreate link $form[$package]['actions'][$name] = array( - '#markup' => l(t('Recreate'), "admin/structure/features/{$name}/recreate", array('attributes' => array('class' => array('admin-update')))), + '#markup' => + l(t('Recreate'), "admin/structure/features/{$name}/recreate", array('attributes' => array('class' => array('admin-update')))) + . ' ' . l(t('Persist'), "admin/structure/features/{$name}/persist", array('attributes' => array('class' => array('admin-update')))), ); } } @@ -523,7 +525,7 @@ function features_admin_components($form, $form_state, $feature) { $form['#conflicts'] = $conflicts; $review = $revert = FALSE; - + // Iterate over components and retrieve status for display $states = features_get_component_states(array($feature->name), FALSE); $form['revert']['#tree'] = TRUE; @@ -549,7 +551,7 @@ function features_admin_components($form, $form_state, $feature) { else { $path = NULL; } - + $storage = FEATURES_DEFAULT; if (array_key_exists($component, $states[$feature->name])) { $storage = $states[$feature->name][$component]; @@ -778,7 +780,7 @@ function features_feature_diff($feature, $component = NULL) { module_load_include('inc', 'diff', 'diff.engine'); $formatter = new DrupalDiffFormatter(); - + $rows = array(); foreach ($overrides as $component => $items) { $rows[] = array(array('data' => $component, 'colspan' => 4, 'header' => TRUE)); @@ -875,3 +877,97 @@ function features_autocomplete_packages($search_string) { $matched_packages = array_unique($matched_packages); drupal_json_output($matched_packages); } + +/** + * Save the feature into database (and thus make it overridden). + */ +function features_persist($feature) { + $module = $feature->name; + $check = create_function('$table,$id,$value', 'return db_select($table, "t")->condition($id, $value)->fields("t")->execute()->fetchColumn();'); + $hook = FALSE; + + if (module_exists($module) && $feature->info['features']) { + $components = $feature->info['features']; + foreach ($components as $type => $items) { + switch ($type) { + case 'image': + module_load_include('inc', $module, $module . '.features'); + $hook = $module . '_image_default_styles'; + $styles = $hook(); + foreach ($items as $item) { + if (!$check('image_styles', 'name', $styles[$item]['name'])) { + $is = image_style_save($styles[$item]); + foreach ($styles[$item]['effects'] as $effect) { + $effect['isid'] = $is['isid']; + image_effect_save($effect); + } + drupal_set_message(t("Image style '@style' saved.", array('@style' => $styles[$item]['name']))); + } + else { + drupal_set_message(t("Image style '@style' skipped.", array('@style' => $styles[$item]['name'])), 'warning'); + } + } + break; + + case 'page_manager_handlers': + ctools_include('plugins'); + module_load_include('inc', $module, $module . '.pages_default'); + $hook = $module . '_default_page_manager_handlers'; + $handlers = $hook(); + foreach ($items as $item) { + if (!$check('page_manager_handlers', 'name', $handlers[$item]->name)) { + page_manager_save_task_handler($handlers[$item]); + drupal_set_message(t("Page handler '@handler' saved.", array('@handler' => $handlers[$item]->conf['title']))); + } + else { + drupal_set_message(t("Page handler '@handler' skpped.", array('@handler' => $handlers[$item]->conf['title'])), 'warning'); + } + } + break; + + case 'page_manager_pages': + ctools_include('plugins'); + module_load_include('inc', $module, $module . '.pages_default'); + page_manager_get_tasks(); + $hook = $module . '_default_page_manager_pages'; + $handlers = $hook(); + foreach ($items as $item) { + if (!$check('page_manager_pages', 'name', $handlers[$item]->name)) { + page_manager_page_save($handlers[$item]); + drupal_set_message(t("Page '@page' saved.", array('@page' => $handlers[$item]->admin_title))); + } + else { + drupal_set_message(t("Page '@page' skipped.", array('@page' => $handlers[$item]->admin_title)), 'warning'); + } + } + break; + + case 'views_view': + module_load_include('inc', $module, $module . '.views_default'); + $hook = $module . '_views_default_views'; + $views = $hook(); + foreach ($items as $item) { + if (!$check('views_view', 'name', $views[$item]->name)) { + views_save_view($views[$item]); + drupal_set_message(t("View '@view' saved.", array('@view' => $views[$item]->human_name))); + } + else { + drupal_set_message(t("View '@view' skipped.", array('@view' => $views[$item]->human_name)), 'warning'); + } + } + break; + + default: + break; + } + } + if (!$hook) { + drupal_set_message(t('Nothing to persist. Only images, pages and views can be persisted.')); + } + } + else { + drupal_set_message(t('The feature is not enabled.')); + } + + drupal_goto('admin/structure/features'); +} diff --git a/features.module b/features.module index 14ba7f7..765c8d0 100644 --- a/features.module +++ b/features.module @@ -137,6 +137,17 @@ function features_menu() { 'file' => "features.admin.inc", 'weight' => 11, ); + $items['admin/structure/features/%feature/persist'] = array( + 'title' => 'Persist', + 'description' => 'Persist a feature into database.', + 'page callback' => 'features_persist', + 'page arguments' => array(3), + 'load arguments' => array(3, TRUE), + 'access callback' => 'user_access', + 'access arguments' => array('administer features'), + 'type' => MENU_CALLBACK, + 'file' => "features.admin.inc", + ); if (module_exists('diff')) { $items['admin/structure/features/%feature/diff'] = array( 'title' => 'Review overrides',