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?

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!

ceng’s picture

Status: Active » Needs review
FileSize
846 bytes
None View

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?

ceng’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.

ceng’s picture

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

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?

ceng’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