You are here

function access_scheme_features_rebuild in Access Control Kit 7

Implements hook_features_rebuild().

1 call to access_scheme_features_rebuild()
access_scheme_features_revert in ./access.features.inc
Implements hook_features_revert().

File

./access.features.inc, line 136
Features integration for the access control kit module.

Code

function access_scheme_features_rebuild($module_name) {
  $schemes = features_get_default('access_scheme', $module_name);
  if (!empty($schemes)) {
    foreach ($schemes as $scheme_machine_name => $scheme) {
      $scheme = (object) $scheme;
      $scheme->machine_name = $scheme_machine_name;

      // See if this scheme already exists in the database.
      $existing = access_scheme_machine_name_load($scheme->machine_name, TRUE);
      if (!empty($existing)) {
        $scheme->sid = $existing->sid;
      }

      // Match up the exported role names with their role IDs.
      $roles = array();
      foreach ($scheme->roles as $role_name) {
        $role = user_role_load_by_name($role_name);
        if ($role) {
          $roles[$role->rid] = $role->name;
        }
      }
      $scheme->roles = $roles;

      // Reattach the handlers.
      foreach ($scheme->handlers as $object_type => $handler) {
        entity_get_controller('access_scheme')
          ->attachHandler($scheme, $object_type, $handler['handler'], $handler['settings']);
      }
      access_scheme_save($scheme);
    }
  }
}