function configuration_save in Configuration Management 7
Save changes to track configuration.
Parameters
$configs The $config array to be saved. The array is keyed by component with: the value being another array keyed by configuration name and value either being a boolean or the configuration name of any parents. $configs = array( component-name => array( config-name => dependency array or boolean ) );
2 calls to configuration_save()
File
- ./
configuration.module, line 539 - Module file for the configuration module, which enables the capture and management of configuration in Drupal.
Code
function configuration_save($configs) {
configuration_include();
module_load_include('inc', 'configuration', 'configuration.export');
$current_config = configuration_get_configuration();
// Check to see if there is anything in datastore that would be lost
if (!configuration_check_changed(CONFIGURATION_DATASTORE_ONLY, array_keys($configs), $current_config)) {
return FALSE;
}
try {
$transaction = db_transaction();
$saved = array();
foreach ($configs as $component => $config) {
foreach ($config as $name => $on) {
if ($on) {
// Using the $on state for dual purpose. When configuration_save is
// called with dependencies from the $pipe, $on will hold the
// dependencies. If this is called from the standard management
// screen, $on is a boolean and we need to set empty dependencies.
$deps = is_numeric($on) || $on == '' ? array(
'parent' => '',
'modules' => '',
) : $on;
$function = "configuration_hash_{$component}";
$hash = $function($name);
$record = array(
'name' => $name,
'owner' => $component,
'status' => CONFIGURATION_IN_SYNC,
'hash' => $hash,
'parent' => $deps['parent'],
'dependencies' => $deps['modules'],
);
// Track what configurations we have saved
if (!isset($saved[$component])) {
$saved[$component] = TRUE;
}
// If this is an update, set the primary key
$pk = isset($current_config[$component][$name]) ? array(
'name',
) : array();
drupal_write_record('config_export', $record, $pk);
$configs[$component][$name] = $name;
}
else {
unset($configs[$component][$name]);
}
}
if (isset($saved[$component])) {
drupal_set_message(t('Tracking configurations for %config have been saved.', array(
'%config' => $component,
)));
}
}
cache_clear_all('config_export', 'cache');
} catch (Exception $e) {
$transaction
->rollback();
watchdog_exception('configuration', $e);
throw $e;
}
// Write the new configuration to disk.
configuration_write_exports(array_keys($saved));
}