You are here

function content_access_update_6001 in Content Access 6

Upgrade from d5 to d6

File

./content_access.install, line 47

Code

function content_access_update_6001() {
  drupal_load('module', 'content_access');
  module_load_include('inc', 'content_access', 'content_access.admin');

  // Migrate old ca settings to new available d6 permissions
  $permissions = content_access_get_permissions_by_role();
  $settings = content_access_get_settings();
  foreach (node_get_types('names') as $type => $type_name) {
    foreach (array(
      'update',
      'delete',
    ) as $op) {

      // Set permission for roles that are allowed to access
      foreach (content_access_get_settings($op, $type) as $rid => $value) {
        if (is_numeric($rid)) {
          $permissions[$rid][content_access_get_permission_by_op($op, $type)] = TRUE;
        }
        else {
          if ($rid == 'author') {

            // CA 5.x let authors access, but only if they were authenticated. So we set the d6 permissions like this.
            $permissions[DRUPAL_AUTHENTICATED_RID][content_access_get_permission_by_op($op . '_own', $type)] = TRUE;
          }
        }
      }

      // Make sure to delete the old setting, so that the defaults (permissions) will be used.
      unset($settings[$op][$type]);
    }
  }
  content_access_save_permissions($permissions);
  content_access_set_settings($settings);

  // Rebuild node access for all nodes
  node_access_needs_rebuild(TRUE);
  return array();
}