function ldap_servers_features_revert in LDAP integration 6
Implementation of hook_features_revert(). [component_hook]
This is called when a feature is "reverted" via the UI. It will delete all existing servers not defined by the feature, update existing servers to match the feature defaults, and add in any server defined in the feature that don't exist.
File
- ./
ldapauth.features.inc, line 101 - Feature related functions.
Code
function ldap_servers_features_revert($module) {
module_load_include('inc', 'ldapauth', 'includes/ldap.core');
$default_servers = module_invoke($module, 'default_ldap_servers');
$servers = ldapauth_server_load_all(TRUE);
$existing_servers = array();
// Update any existing servers in feature and delete those not in the feature.
foreach ($servers as $server) {
$machine_name = $server->machine_name;
$existing_servers[$machine_name] = $machine_name;
if (isset($default_servers[$machine_name])) {
// Update servers
$default_servers[$machine_name]['sid'] = $server->sid;
ldapauth_server_save($default_servers[$machine_name], TRUE);
}
else {
// Delete server
ldapauth_server_delete($server, TRUE);
}
}
// Add any servers in the feature that don't exist.
foreach ($default_servers as $server) {
if (!isset($existing_servers[$server['machine_name']])) {
// Add in default server not in DB
unset($server['sid']);
ldapauth_server_save($server, TRUE);
}
}
}