You are here

function pm_permission_migrate_legacy_permissions in Drupal PM (Project Management) 7.3

Same name and namespace in other branches
  1. 8 includes/pm.permission.migrate.inc \pm_permission_migrate_legacy_permissions()

Handles migration of legacy permissions for a given sub-module.

1 call to pm_permission_migrate_legacy_permissions()
pm_permission_migrate_execute in includes/pm.permission.migrate.inc
Helper function to migrate permission defined by submodules.

File

includes/pm.permission.migrate.inc, line 202
Migration functions for the PM Permission module.

Code

function pm_permission_migrate_legacy_permissions($module_name) {

  // Enable Permission to be defined by pmpermission.
  // Handover legacy permission to pmpermission based implementations.
  $map = pm_permission_migrate_get_legacy_permission_map();
  $permissions = $map[$module_name];
  foreach ($permissions as $old => $new) {
    switch ($new) {
      case PMPERMISSION_OBSOLETE:
        drupal_set_message(t('Permission "@name" is obsolete and won\'t be migrated.', array(
          '@name' => $old,
        )), 'warning');
        break;
      case PMPERMISSION_CANNOT_BE_PORTED:
        drupal_set_message(t('Permission "@name" cannot be ported.', array(
          '@name' => $old,
        )), 'error');
        break;
      case PMPERMISSION_UNCHANGED:
        break;
      default:
        $rids = _pm_permission_migrate_get_all_roles_having_permission($old);
        $permission = array(
          // Revoke old permission (deletes the record) by setting to 0.
          $old => 0,
          $new => TRUE,
        );
        foreach ($rids as $rid => $role_name) {
          user_role_change_permissions($rid, $permission);
        }

        // All permission adjustment used by pmpermission module requires node
        // access to be rebuilt.
        node_access_needs_rebuild(TRUE);
        break;
    }
  }
}