You are here

function protected_node_update_6001 in Protected Node 6

Implementation of hook_update_N().

File

./protected_node.install, line 293

Code

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

  // we want an is_protected field so we can load it easily and
  // we can keep the other parameters even when we unprotect
  // a node (although it's not that important right now.)
  $field = array(
    'description' => t('A hint about the password on this node.'),
    'type' => 'text',
  );
  db_add_field($ret, 'protected_nodes', 'protected_node_hint', $field);
  $result = db_query('SELECT rid, perm FROM {permission}');
  while ($row = db_fetch_object($result)) {
    if (strpos($row->perm, 'edit protected ') !== FALSE) {
      $updated_perm = str_replace('edit protected content', 'edit any password', $row->perm);
      $updated_perm = preg_replace('/edit protected ([^,]+)/', 'edit \\1 password', $updated_perm);
      $sql = "UPDATE {permission} SET perm = '%s' WHERE rid = %d";
      $r = db_query($sql, $updated_perm, $row->rid);
      $ret[] = array(
        'success' => $r !== FALSE,
        'query' => check_plain($sql),
      );
    }
  }
  return $ret;
}