You are here

function flag_update_6200 in Flag 7.2

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

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

File

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

Code

function flag_update_6200() {
  if (db_field_exists('flags', 'roles')) {
    $result = db_select('flags', 'f')
      ->fields('f')
      ->execute();
    foreach ($result as $flag) {
      $roles = array_filter(explode(',', $flag->roles));
      $options = unserialize($flag->options);
      $options['roles'] = array(
        'flag' => $roles,
        'unflag' => $roles,
      );
      db_update('flags')
        ->fields(array(
        'options' => serialize($options),
      ))
        ->condition('fid', $flag->fid)
        ->execute();
    }
    db_drop_field('flags', 'roles');
  }
}