You are here

function user_relationships_update_7006 in User Relationships 7

Add machine name field.

File

./user_relationships.install, line 209
User Relationships API Module installation file.

Code

function user_relationships_update_7006() {
  if (!db_field_exists('user_relationship_types', 'machine_name')) {
    $field = array(
      'type' => 'varchar',
      'length' => 255,
      'default' => '',
    );
    db_add_field('user_relationship_types', 'machine_name', $field);

    // Set the machine name.
    db_update('user_relationship_types')
      ->expression('machine_name', 'rtid')
      ->execute();

    // Update any old permissions.
    drupal_static_reset('user_relationships_types_load');
    $types = user_relationships_types_load();
    foreach ($types as $type) {
      $permissions = array(
        // Old => new.
        'can have ' . $type->name . ' relationships' => 'can have ' . $type->machine_name . ' relationships',
        'maintain ' . $type->name . ' relationships' => 'maintain ' . $type->machine_name . ' relationships',
        'can request ' . $type->name . ' relationships' => 'can request ' . $type->machine_name . ' relationships',
        'delete ' . $type->name . ' relationships' => 'delete ' . $type->machine_name . ' relationships',
      );
      foreach ($permissions as $old => $new) {
        db_update('role_permission')
          ->fields(array(
          'permission' => $new,
        ))
          ->condition('permission', $old)
          ->execute();
      }
    }
  }
}