There's one function (features_revert()) to do anything between revert 1 component in 1 feature and revert all components in all features. There's no function that reverts all components in 1 feature. I miss that. Is that something to add?

I'm currently using this in update hooks a lot:

<?php
function features_revert_module($module) {
	if (($feature = feature_load($module, TRUE)) && module_exists($module)) {
		$components = array();
		foreach (array_keys($feature->info['features']) as $component) {
			if (features_hook($component, 'features_revert')) {
				$components[] = $component;
			}
		}
		features_revert(array($module => $components));
	}
}
?>

Idea?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gavin.hughes’s picture

I Just used this function for the same scenario and thought it would make a worthy addition. Thanks!

FreekyMage’s picture

I also used this a couple of times, very handy!

johnennew’s picture

Status: Active » Needs review
FileSize
846 bytes

I've been using this for a while now - here is the patch attached.

As stated already, this means you can do the following in your install file hook_update_N functions...

/**
 * Revert all features in myfeature.
 */
function mymodule_update_7001() {
  features_revert_module('myfeature');
}
mpotter’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev

Moving this to 2.x to get it to pass testing (no reason it shouldn't pass though)

mpotter’s picture

Status: Needs review » Fixed

Actually, just going to commit this (293fda6). I use this function all the time in my own projects and have been meaning to add it to Features for a while.

Somebody want to write a documentation patch?

johnennew’s picture

Where would the documentation go? Attached is a note at the end of API.txt if it helps.

rudiedirkx’s picture

Any change this getting into 1.x? I don't like 2.x.

johnennew’s picture

Version: 7.x-2.x-dev » 7.x-1.x-dev
Status: Fixed » Needs review
FileSize
846 bytes

Backport patch for 7.x-1.x is attached. I've tested this out on a basic D7 install and appears to work fine.

alexweber’s picture

Shouldn't this go in 7.x-2.x-dev and get backported to 7.x-1.x-dev?

johnennew’s picture

It has hasn't it? mpotter committed in #5

hefox’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Status: Needs review » Fixed

TMK, there's no plans to backport items to 1.x branch (unless it's a security issue). Use 2.x, it's much better

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

color coding

scott.whittaker’s picture

Issue summary: View changes

This doesn't seem to be present in 7.x-2.0-beta2

GuyPaddock’s picture

core44’s picture

generalredneck’s picture

Throwing in a true permalink
https://git.drupalcode.org/project/features/-/blob/bab2d219b10092c74c35a...

/**
 * Revert a single features module.
 *
 * @param string $module
 *   A features module machine name. This module must be a
 *   features module and enabled.
 */
function features_revert_module($module)