You are here

function invite_update_9 in Invite 5

Same name and namespace in other branches
  1. 5.2 invite.install \invite_update_9()
  2. 6.2 invite.install \invite_update_9()
  3. 7.2 invite.install \invite_update_9()

Update limit and move some settings to the premissions table.

File

./invite.install, line 262

Code

function invite_update_9() {
  $ret = array();
  foreach (user_roles(0, 'send invitations') as $rid => $role) {
    $role_no_space = str_replace(' ', '_', $role);

    // INVITE_UNLIMITED_INVITES changed from 0 to -1
    if (variable_get('invite_maxnum_' . $role_no_space, 0) == 0) {
      variable_set('invite_maxnum_' . $role_no_space, -1);
    }

    // Convert settings that have been moved to the permissions table
    $perms = array();
    if (variable_get('invite_maxmultiple_' . $role_no_space, 1) != 1) {
      $perms[] = 'send mass invitations';
    }
    if (variable_get('invite_allow_join_delete', 0)) {
      $perms[] = 'withdraw accepted invitations';
    }
    _invite_add_permission($rid, implode(', ', $perms));
  }
  db_query("DELETE from {variable} WHERE name LIKE 'invite_maxmultiple_%%'");

  // Expiry periods changed
  $expiry = variable_get('invite_expiry', 30);
  switch ($expiry) {
    case 5:
      $expiry = 7;
      break;
    case 10:
      $expiry = 14;
      break;
    case 15:
      $expiry = 14;
      break;
    case 20:
      $expiry = 30;
      break;
    case 25:
      $expiry = 30;
      break;
    case 30:
      $expiry = 30;
      break;
    case 45:
      $expiry = 60;
      break;
    case 60:
      $expiry = 60;
      break;
  }
  variable_set('invite_expiry', $expiry);
  $ret[] = array(
    'query' => 'The access permissions have been updated by the invite module.',
    'success' => TRUE,
  );
  return $ret;
}