You are here

function rules_update_7200 in Rules 7.2

Upgrade from Rules 6.x-1.x to 7.x.

File

./rules.install, line 218
Rules - Installation file.

Code

function rules_update_7200() {

  // Create the new db tables first.
  $schema['rules_config'] = array(
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'The internal identifier for any configuration.',
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'description' => 'The name of the configuration.',
      ),
      'label' => array(
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'description' => 'The label of the configuration.',
        'default' => 'unlabeled',
      ),
      'plugin' => array(
        'type' => 'varchar',
        'length' => 127,
        'not null' => TRUE,
        'description' => 'The name of the plugin of this configuration.',
      ),
      'active' => array(
        'description' => 'Boolean indicating whether the configuration is active. Usage depends on how the using module makes use of it.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 1,
      ),
      'weight' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
        'description' => 'Weight of the configuration. Usage depends on how the using module makes use of it.',
      ),
      'status' => array(
        'type' => 'int',
        'not null' => TRUE,
        // Set the default to ENTITY_CUSTOM without using the constant as it is
        // not safe to use it at this point.
        'default' => 0x1,
        'size' => 'tiny',
        'description' => 'The exportable status of the entity.',
      ),
      'module' => array(
        'description' => 'The name of the providing module if the entity has been defined in code.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
      'data' => array(
        'type' => 'blob',
        'size' => 'big',
        'not null' => FALSE,
        'serialize' => TRUE,
        'description' => 'Everything else, serialized.',
      ),
    ),
    'primary key' => array(
      'id',
    ),
    'unique keys' => array(
      'name' => array(
        'name',
      ),
    ),
  );
  $schema['rules_trigger'] = array(
    'fields' => array(
      'id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'The primary identifier of the configuration.',
      ),
      'event' => array(
        'type' => 'varchar',
        'length' => '127',
        'not null' => TRUE,
        'default' => '',
        'description' => 'The name of the event on which the configuration should be triggered.',
      ),
    ),
    'primary key' => array(
      'id',
      'event',
    ),
    'foreign keys' => array(
      'table' => 'rules_config',
      'columns' => array(
        'id' => 'id',
      ),
    ),
  );
  db_create_table('rules_config', $schema['rules_config']);
  db_create_table('rules_trigger', $schema['rules_trigger']);

  // The cache table already exists, but changed. So re-create it.
  db_drop_table('cache_rules');
  $schema['cache_rules'] = drupal_get_schema_unprocessed('system', 'cache');
  $schema['cache_rules']['description'] = 'Cache table for the rules engine to store configured items.';
  db_create_table('cache_rules', $schema['cache_rules']);

  // Remove deprecated variables.
  variable_del('rules_inactive_sets');
  variable_del('rules_show_fixed');
  variable_del('rules_hide_token_message');
  variable_del('rules_counter');
  return t('The database tables for Rules 2.x have been created. The old tables from Rules 1.x are still available and contain your rules, which are not updated yet.');
}