variable_store.install 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @file
  4. * Variable API module install file
  5. */
  6. /**
  7. * Implements hook_install()
  8. */
  9. function variable_store_install() {
  10. // Set module weight for it to run before most modules and initialize variable realms
  11. db_query("UPDATE {system} SET weight = -1000 WHERE name = 'variable_store' AND type = 'module'");
  12. }
  13. /**
  14. * Implementation of hook_schema().
  15. */
  16. function variable_store_schema() {
  17. $schema['variable_store'] = array(
  18. 'description' => 'Named variable/value pairs created by modules using Variable API database storage. All variables are cached in memory at the start of every Drupal request so developers should not be careless about what is stored here.',
  19. 'fields' => array(
  20. 'realm' => array(
  21. 'description' => 'The realm domain of this variable.',
  22. 'type' => 'varchar',
  23. 'length' => 50,
  24. 'not null' => TRUE,
  25. 'default' => ''),
  26. 'realm_key' => array(
  27. 'description' => 'The realm key of this variable.',
  28. 'type' => 'varchar',
  29. 'length' => 50,
  30. 'not null' => TRUE,
  31. 'default' => ''),
  32. 'name' => array(
  33. 'description' => 'The name of the variable.',
  34. 'type' => 'varchar',
  35. 'length' => 128,
  36. 'not null' => TRUE,
  37. 'default' => ''),
  38. 'value' => array(
  39. 'description' => 'The value of the variable.',
  40. 'type' => 'text',
  41. 'not null' => TRUE,
  42. 'size' => 'big'),
  43. 'serialized' => array(
  44. 'description' => 'A flag to indicate whether content is serialized (1) or not (0).',
  45. 'type' => 'int',
  46. 'size' => 'small',
  47. 'not null' => TRUE,
  48. 'default' => 1),
  49. ),
  50. 'primary key' => array('realm', 'realm_key', 'name'),
  51. 'indexes' => array('realm_value' => array('realm', 'realm_key')),
  52. );
  53. return $schema;
  54. }
  55. /**
  56. * Reduce realm key field length so it can be used on the primary key
  57. */
  58. function variable_store_update_7000() {
  59. $schema = variable_store_schema();
  60. db_change_field('variable_store', 'realm_key', 'realm_key', $schema['variable_store']['fields']['realm_key']);
  61. }