You are here

function better_formats_update_6110 in Better Formats 6

Same name and namespace in other branches
  1. 6.2 better_formats.install \better_formats_update_6110()

Update from 1.0 to 1.1.

File

./better_formats.install, line 127
Installs the better_formats module.

Code

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

  // Insert block format defaults.
  $roles = user_roles();
  $sql = "INSERT INTO {better_formats_defaults}\n            VALUES (%d, '%s', %d, %d, %d)";
  foreach ($roles as $rid => $role) {
    $result = db_query($sql, $rid, 'block', 0, 1, 25);
    $ret[] = array(
      'success' => $result !== FALSE,
      'query' => check_plain($sql),
    );
  }

  // Split show format selection permission.
  // Get permissions by role.
  $sql = "SELECT *\n          FROM {permission}";
  $result = db_query($sql);
  $row_perms = array();
  while ($row = db_fetch_object($result)) {
    $role_perms[$row->rid] = $row;
  }
  if (!empty($role_perms)) {

    // Add perms to core roles (anonymous user, authenticated user).
    foreach ($role_perms as $perms) {

      // Only enable spit permissions if previous was enabled.
      $replace = ', show format selection for nodes, show format selection for comments, show format selection for blocks,';
      $perms->perm = str_replace(', show format selection,', $replace, $perms->perm);
      $sql = "UPDATE {permission}\n              SET perm = '%s'\n              WHERE pid = %d";
      $result = db_query($sql, $perms->perm, $perms->pid);
      $ret[] = array(
        'success' => $result !== FALSE,
        'query' => check_plain($sql),
      );
    }

    // Clear the cache.
    cache_clear_all();
  }
  return $ret;
}