function features_get_component_states in Features 7.2
Same name and namespace in other branches
- 6 features.export.inc \features_get_component_states()
- 7 features.export.inc \features_get_component_states()
Retrieve an array of features/components and their current states.
Parameters
string[] $features: (optional) Machine names of feature modules. If empty, states for all features will be returned.
bool $rebuild_only: (optional) If TRUE, only rebuildable components are returned.
bool $reset: (optional) If TRUE, relevant caches will be reset before fetching.
Return value
int[][] Component states by module and component. Format: $[$module][$component] = $state where $state will be one of the states listed below.
See also
6 calls to features_get_component_states()
- drush_features_revert in ./
features.drush.inc - Drush command callback for 'features-revert'.
- FeaturesUserTestCase::test in tests/
features.test - Run test.
- features_admin_components in ./
features.admin.inc - Form builder for 'admin/structure/features/%feature'.
- features_detect_overrides in ./
features.export.inc - Detect differences between DB and code components of a feature.
- features_get_storage in ./
features.export.inc - Gets a summary storage state for a feature.
File
- ./
features.export.inc, line 1336 - Contains functions that export configuration into feature modules.
Code
function features_get_component_states($features = array(), $rebuild_only = TRUE, $reset = FALSE) {
// Ensure that the export will be created in the English language.
$language = _features_export_language();
if ($reset) {
drupal_static_reset(__FUNCTION__);
}
$cache =& drupal_static(__FUNCTION__, array());
$all_features = features_get_features();
$features = !empty($features) ? $features : array_keys($all_features);
// Retrieve only rebuildable components if requested.
features_include();
$components = array_keys(features_get_components(NULL, NULL, $reset));
if ($rebuild_only) {
foreach ($components as $k => $component) {
if (!features_hook($component, 'features_rebuild')) {
unset($components[$k]);
}
}
}
foreach ($features as $feature) {
$cache[$feature] = isset($cache[$feature]) ? $cache[$feature] : array();
if (module_exists($feature) && !empty($all_features[$feature]->components)) {
foreach (array_intersect($all_features[$feature]->components, $components) as $component) {
if (!isset($cache[$feature][$component])) {
$normal = features_get_signature('normal', $feature, $component, $reset);
$default = features_get_signature('default', $feature, $component, $reset);
$codecache = features_get_signature('cache', $feature, $component, $reset);
$semaphore = features_semaphore('get', $component);
// DB and code states match, there is nothing more to check.
if ($normal == $default) {
$cache[$feature][$component] = FEATURES_DEFAULT;
// Stale semaphores can be deleted.
features_semaphore('del', $component);
// Update code cache if it is stale, clear out semaphore if it is
// stale.
if ($default != $codecache) {
features_set_signature($feature, $component, $default, __FUNCTION__ . '(): $normal === $default');
}
}
elseif (!features_hook($component, 'features_rebuild')) {
$cache[$feature][$component] = FEATURES_OVERRIDDEN;
}
else {
if (empty($semaphore)) {
// Exception for dependencies. Dependencies are always
// rebuildable.
if ($component === 'dependencies') {
$cache[$feature][$component] = FEATURES_REBUILDABLE;
}
else {
// Code has not changed, but DB does not match. User has DB
// overrides.
if ($codecache == $default) {
$cache[$feature][$component] = FEATURES_OVERRIDDEN;
}
elseif (empty($codecache) || $codecache == $normal) {
$cache[$feature][$component] = FEATURES_REBUILDABLE;
}
elseif ($codecache != $default) {
$cache[$feature][$component] = FEATURES_NEEDS_REVIEW;
}
}
}
else {
// Semaphore is still within processing horizon. Do nothing.
if (REQUEST_TIME - $semaphore < FEATURES_SEMAPHORE_TIMEOUT) {
$cache[$feature][$component] = FEATURES_REBUILDING;
}
else {
$cache[$feature][$component] = FEATURES_REBUILDABLE;
}
}
}
}
}
}
}
// Filter cached components on the way out to ensure that even if we have
// cached more data than has been requested, the return value only reflects
// the requested features/components.
$return = $cache;
$return = array_intersect_key($return, array_flip($features));
foreach ($return as $k => $v) {
$return[$k] = array_intersect_key($return[$k], array_flip($components));
}
_features_export_language($language);
return $return;
}