You are here

function farm_access_sync_perms in farmOS 7

Synchronize all available farm permissions farm roles.

4 calls to farm_access_sync_perms()
farm_access_enable in modules/farm/farm_access/farm_access.install
Synchronize all available farm role permissions.
farm_access_flush_caches in modules/farm/farm_access/farm_access.module
Implements hook_flush_caches().
farm_access_modules_enabled in modules/farm/farm_access/farm_access.module
Implements hook_modules_enabled().
farm_access_permissions_form_submit in modules/farm/farm_access/farm_access.module
Submit function for the core permissions form.

File

modules/farm/farm_access/farm_access.module, line 256
Farm Access module.

Code

function farm_access_sync_perms() {

  // Get a list of farm roles.
  $roles = farm_access_roles();

  // Iterate through the available roles.
  foreach ($roles as $name => $role) {

    // Compare current perms to available perms.
    $compare = farm_access_compare_perms($name);

    // Start with a blank array of changes.
    $changes = array();

    // Add perms.
    if (!empty($compare['add'])) {
      foreach ($compare['add'] as $perm) {
        $changes[$perm] = TRUE;
      }
    }

    // Remove perms.
    if (!empty($compare['remove'])) {
      foreach ($compare['remove'] as $perm) {
        $changes[$perm] = FALSE;
      }
    }

    // If there are changes to be made...
    if (!empty($changes)) {

      // Load the role.
      $role = user_role_load_by_name($role['name']);

      // If the role does not exist, bail.
      if (empty($role)) {
        return;
      }

      // Apply the changes.
      user_role_change_permissions($role->rid, $changes);
    }
  }
}