123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528 |
- <?php
- /**
- * @file Rules - Installation file.
- */
- /**
- * Implements hook_enable().
- */
- function rules_enable() {
- // Enable evaluation of Rules right after enabling the module.
- rules_event_invocation_enabled(TRUE);
- }
- /**
- * Implements hook_install().
- */
- function rules_install() {
- module_load_include('inc', 'rules', 'modules/events');
- // Set the modules' weight to 20, see
- // http://drupal.org/node/445084#comment-1533280 for the reasoning.
- db_query("UPDATE {system} SET weight = 20 WHERE name = 'rules'");
- }
- /**
- * Implements hook_uninstall().
- */
- function rules_uninstall() {
- variable_del('rules_event_whitelist');
- variable_del('rules_debug');
- }
- /**
- * Implements hook_schema().
- */
- function rules_schema() {
- $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' => '64',
- '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' => 0x01,
- 'size' => 'tiny',
- 'description' => 'The exportable status of the entity.',
- ),
- 'dirty' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'size' => 'tiny',
- 'description' => 'Dirty configurations fail the integrity check, e.g. due to missing dependencies.',
- ),
- 'module' => array(
- 'description' => 'The name of the providing module if the entity has been defined in code.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => FALSE,
- ),
- 'owner' => array(
- 'description' => 'The name of the module via which the rule has been configured.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => 'rules',
- ),
- 'access_exposed' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'size' => 'tiny',
- 'description' => 'Whether to use a permission to control access for using components.',
- ),
- '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'),
- ),
- 'indexes' => array(
- 'plugin' => array('plugin'),
- ),
- );
- $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'),
- ),
- );
- $schema['rules_tags'] = array(
- 'fields' => array(
- 'id' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'description' => 'The primary identifier of the configuration.',
- ),
- 'tag' => array(
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => TRUE,
- 'description' => 'The tag string associated with this configuration',
- ),
- ),
- 'primary key' => array('id', 'tag'),
- 'foreign keys' => array(
- 'table' => 'rules_config',
- 'columns' => array('id' => 'id'),
- ),
- );
- $schema['rules_dependencies'] = array(
- 'fields' => array(
- 'id' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'description' => 'The primary identifier of the configuration.',
- ),
- 'module' => array(
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => TRUE,
- 'description' => 'The name of the module that is required for the configuration.',
- ),
- ),
- 'primary key' => array('id', 'module'),
- 'indexes' => array(
- 'module' => array('module'),
- ),
- 'foreign keys' => array(
- 'table' => 'rules_config',
- 'columns' => array('id' => 'id'),
- ),
- );
- $schema['cache_rules'] = drupal_get_schema_unprocessed('system', 'cache');
- $schema['cache_rules']['description'] = 'Cache table for the rules engine to store configured items.';
- return $schema;
- }
- /**
- * Upgrade from Rules 6.x-1.x to 7.x.
- */
- 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' => 0x01,
- '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.');
- }
- /**
- * Add in the exportable entity db columns as required by the entity API.
- */
- function rules_update_7201() {
- // Previously this was update 7200, so check whether we need to run it really.
- // The update has been moved as 7200 needs to be the 6.x-7.x upgrade.
- if (!db_field_exists('rules_config', 'status')) {
- db_add_field('rules_config', 'status', array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => ENTITY_CUSTOM,
- 'size' => 'tiny',
- 'description' => 'The exportable status of the entity.',
- ));
- // The module column did already exist before.
- }
- }
- /**
- * Add an index for the rules configuration plugin column.
- */
- function rules_update_7202() {
- db_add_index('rules_config', 'plugin', array('plugin'));
- }
- /**
- * Fix the length of the rules_config.name column.
- */
- function rules_update_7203() {
- db_drop_unique_key('rules_config', 'name');
- $keys = array(
- 'unique keys' => array(
- 'name' => array('name'),
- ),
- );
- db_change_field('rules_config', 'name', 'name', array(
- 'type' => 'varchar',
- 'length' => '64',
- 'not null' => TRUE,
- 'description' => 'The name of the configuration.',
- ), $keys);
- }
- /**
- * Add a table for rules-config tags.
- */
- function rules_update_7204() {
- if (!db_table_exists('rules_tags')) {
- $schema['rules_tags'] = array(
- 'fields' => array(
- 'id' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'description' => 'The primary identifier of the configuration.',
- ),
- 'tag' => array(
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => TRUE,
- 'description' => 'The tag string associated with this configuration',
- ),
- ),
- 'primary key' => array('id', 'tag'),
- 'foreign keys' => array(
- 'table' => 'rules_config',
- 'columns' => array('id' => 'id'),
- ),
- );
- db_create_table('rules_tags', $schema['rules_tags']);
- }
- }
- /**
- * Add the rules_dependencies table and the rules_config.dirty column.
- */
- function rules_update_7205() {
- if (!db_table_exists('rules_dependencies')) {
- $schema['rules_dependencies'] = array(
- 'fields' => array(
- 'id' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'description' => 'The primary identifier of the configuration.',
- ),
- 'module' => array(
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => TRUE,
- 'description' => 'The name of the module that is required for the configuration.',
- ),
- ),
- 'primary key' => array('id', 'module'),
- 'indexes' => array(
- 'module' => array('module'),
- ),
- 'foreign keys' => array(
- 'table' => 'rules_config',
- 'columns' => array('id' => 'id'),
- ),
- );
- db_create_table('rules_dependencies', $schema['rules_dependencies']);
- }
- if (!db_field_exists('rules_config', 'dirty')) {
- db_add_field('rules_config', 'dirty', array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'size' => 'tiny',
- ));
- }
- }
- /**
- * Flush all caches.
- */
- function rules_update_7206() {
- // The update system is going to flush all caches anyway, so nothing to do.
- }
- /**
- * Flush all caches.
- */
- function rules_update_7207() {
- // The update system is going to flush all caches anyway, so nothing to do.
- }
- /**
- * Flush all caches to update the data_is_empty condition info.
- */
- function rules_update_7208() {
- // The update system is going to flush all caches anyway, so nothing to do.
- }
- /**
- * Creates a flag that enables a permission for using components.
- */
- function rules_update_7209() {
- // Create a access exposed flag column.
- db_add_field('rules_config', 'access_exposed', array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'size' => 'tiny',
- 'description' => 'Whether to use a permission to control access for using components.',
- ));
- }
- /**
- * Deletes the unused rules_empty_sets variable.
- */
- function rules_update_7210() {
- variable_del('rules_empty_sets');
- }
- /**
- * Creates the "owner" column.
- */
- function rules_update_7211() {
- // Create a owner column.
- if (!db_field_exists('rules_config', 'owner')) {
- db_add_field('rules_config', 'owner', array(
- 'description' => 'The name of the module via which the rule has been configured.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => 'rules',
- ));
- }
- }
- /**
- * Make sure registry gets rebuilt to avoid upgrade troubles.
- */
- function rules_update_7212() {
- // Make sure module information gets refreshed and registry is rebuilt.
- drupal_static_reset('system_rebuild_module_data');
- registry_rebuild();
- }
- /**
- * Recover the "owner" property for broken configurations.
- */
- function rules_update_7213() {
- $rows= db_select('rules_config', 'c')
- ->fields('c')
- ->condition('status', ENTITY_OVERRIDDEN)
- ->condition('owner', 'rules', '<>')
- ->execute()
- ->fetchAllAssoc('id');
- foreach ($rows as $id => $row) {
- if ($row->module == $row->owner) {
- db_update('rules_config')
- ->condition('id', $id)
- ->fields(array('owner' => 'rules'))
- ->execute();
- }
- }
- }
- /**
- * Switch out the rules_event_whitelist variable for a cache equivalent.
- */
- function rules_update_7214() {
- // Set new event_whitelist cache cid.
- rules_set_cache('rules_event_whitelist', variable_get('rules_event_whitelist', array()));
- // Delete old conf variable.
- variable_del('rules_event_whitelist');
- // Avoid any missing class errors.
- registry_rebuild();
- // Clear and rebuild Rules caches.
- // See: rules_admin_settings_cache_rebuild_submit.
- rules_clear_cache();
- rules_get_cache();
- _rules_rebuild_component_cache();
- RulesEventSet::rebuildEventCache();
- }
|