You are here

function signup_update_4 in Signup 5

Same name and namespace in other branches
  1. 5.2 signup.install \signup_update_4()
  2. 6.2 signup.install \signup_update_4()
  3. 6 signup.install \signup_update_4()

Rename the signup permissions. See http://drupal.org/node/69283 for details. Also, remove the 'signup_user_view' setting in favor of a permission. See http://drupal.org/node/69367 for details.

File

./signup.install, line 163

Code

function signup_update_4() {
  $ret = array();

  // Setup arrays holding regexps to match and the corresponding
  // strings to replace them with, for use with preg_replace().
  $old_perms = array(
    '/allow signups/',
    '/admin signups/',
    '/admin own signups/',
  );
  $new_perms = array(
    'sign up for content',
    'administer all signups',
    'administer signups for own content',
  );

  // Now, loop over all the roles, and do the necessary transformations.
  $query = db_query("SELECT rid, perm FROM {permission} ORDER BY rid");
  while ($role = db_fetch_object($query)) {
    $fixed_perm = preg_replace($old_perms, $new_perms, $role->perm);
    if ($role->rid == 2 && variable_get('signup_user_view', 0)) {

      // The setting is currently enabled, so add the new permission to
      // the "authenticated user" role as a reasonable default.
      if (!strpos($fixed_perm, 'view all signups')) {
        $fixed_perm .= ', view all signups';
        drupal_set_message(t('The old %signup_user_view setting was enabled on your site, so the %view_all_signups permission has been added to the %authenticated_user role. Please consider customizing what roles have this permission on the !access_control page.', array(
          '%signup_user_view' => t('Users can view signups'),
          '%view_all_signups' => 'view all signups',
          '%authenticated_user' => 'Authenticated user',
          '!access_control' => l(t('Access control'), '/admin/user/access'),
        )));
      }
    }
    $ret[] = update_sql("UPDATE {permission} SET perm = '{$fixed_perm}' WHERE rid = {$role->rid}");
  }

  // Remove the stale setting from the {variable} table in the DB.
  variable_del('signup_user_view');
  drupal_set_message(t('The %signup_user_view setting has been removed.', array(
    '%signup_user_view' => t('Users can view signups'),
  )));
  return $ret;
}