You are here

function publishcontent_update_6001 in Publish Content 6

File

./publishcontent.install, line 3

Code

function publishcontent_update_6001() {
  $ret = $node_types = array();
  $query = 'SELECT pid, perm FROM {permission}';
  $result = db_query($query);
  $update_sql = 'UPDATE {permission} SET perm = "%s" WHERE pid = %d';
  while ($row = db_fetch_array($result)) {
    $old_perm = $row['perm'];
    $subjects = array(
      '*all*',
    );
    $replacements = array(
      'any',
    );
    foreach (node_get_types() as $type) {
      $subjects[] = 'publish ' . check_plain($type->type) . ' content';
      $subjects[] = 'unpublish ' . check_plain($type->type) . ' content';
      $replacements[] = 'publish any ' . check_plain($type->type) . ' content';
      $replacements[] = 'unpublish any ' . check_plain($type->type) . ' content';
    }
    $new_perm = str_replace($subjects, $replacements, $row['perm']);
    $ret[] = array(
      'success' => db_query($update_sql, $new_perm, $row['pid']),
      'query' => t('Updated permission set @set', array(
        '@set' => $row['pid'],
      )),
    );
  }
  variable_set('menu_rebuild_needed', TRUE);
  return $ret;
}