You are here

function flag_update_6200 in Flag 6.2

Same name and namespace in other branches
  1. 7.3 flag.install \flag_update_6200()
  2. 7.2 flag.install \flag_update_6200()

Convert role access to have separate "flag" and "unflag" permissions.

File

./flag.install, line 532
Flag module install/schema/update hooks.

Code

function flag_update_6200() {
  $ret = array();
  if (db_column_exists('flags', 'roles')) {
    $result = db_query('SELECT * FROM {flags}');
    while ($flag = db_fetch_object($result)) {
      $roles = array_filter(explode(',', $flag->roles));
      $options = unserialize($flag->options);
      $options['roles'] = array(
        'flag' => $roles,
        'unflag' => $roles,
      );
      db_query("UPDATE {flags} SET options = '%s' WHERE fid = %d", serialize($options), $flag->fid);
    }
    db_drop_field($ret, 'flags', 'roles');
  }
  return $ret;
}