dblog.install 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the dblog module.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function dblog_schema() {
  10. $schema['watchdog'] = array(
  11. 'description' => 'Table that contains logs of all system events.',
  12. 'fields' => array(
  13. 'wid' => array(
  14. 'type' => 'serial',
  15. 'not null' => TRUE,
  16. 'description' => 'Primary Key: Unique watchdog event ID.',
  17. ),
  18. 'uid' => array(
  19. 'type' => 'int',
  20. 'not null' => TRUE,
  21. 'default' => 0,
  22. 'description' => 'The {users}.uid of the user who triggered the event.',
  23. ),
  24. 'type' => array(
  25. 'type' => 'varchar',
  26. 'length' => 64,
  27. 'not null' => TRUE,
  28. 'default' => '',
  29. 'description' => 'Type of log message, for example "user" or "page not found."',
  30. ),
  31. 'message' => array(
  32. 'type' => 'text',
  33. 'not null' => TRUE,
  34. 'size' => 'big',
  35. 'description' => 'Text of log message to be passed into the t() function.',
  36. ),
  37. 'variables' => array(
  38. 'type' => 'blob',
  39. 'not null' => TRUE,
  40. 'size' => 'big',
  41. 'description' => 'Serialized array of variables that match the message string and that is passed into the t() function.',
  42. ),
  43. 'severity' => array(
  44. 'type' => 'int',
  45. 'unsigned' => TRUE,
  46. 'not null' => TRUE,
  47. 'default' => 0,
  48. 'size' => 'tiny',
  49. 'description' => 'The severity level of the event; ranges from 0 (Emergency) to 7 (Debug)',
  50. ),
  51. 'link' => array(
  52. 'type' => 'varchar',
  53. 'length' => 255,
  54. 'not null' => FALSE,
  55. 'default' => '',
  56. 'description' => 'Link to view the result of the event.',
  57. ),
  58. 'location' => array(
  59. 'type' => 'text',
  60. 'not null' => TRUE,
  61. 'description' => 'URL of the origin of the event.',
  62. ),
  63. 'referer' => array(
  64. 'type' => 'text',
  65. 'not null' => FALSE,
  66. 'description' => 'URL of referring page.',
  67. ),
  68. 'hostname' => array(
  69. 'type' => 'varchar',
  70. 'length' => 128,
  71. 'not null' => TRUE,
  72. 'default' => '',
  73. 'description' => 'Hostname of the user who triggered the event.',
  74. ),
  75. 'timestamp' => array(
  76. 'type' => 'int',
  77. 'not null' => TRUE,
  78. 'default' => 0,
  79. 'description' => 'Unix timestamp of when event occurred.',
  80. ),
  81. ),
  82. 'primary key' => array('wid'),
  83. 'indexes' => array(
  84. 'type' => array('type'),
  85. 'uid' => array('uid'),
  86. 'severity' => array('severity'),
  87. ),
  88. );
  89. return $schema;
  90. }
  91. /**
  92. * Implements hook_uninstall().
  93. */
  94. function dblog_uninstall() {
  95. variable_del('dblog_row_limit');
  96. }
  97. /**
  98. * @addtogroup updates-6.x-to-7.x
  99. * @{
  100. */
  101. /**
  102. * Update the {watchdog} table.
  103. */
  104. function dblog_update_7001() {
  105. // Allow NULL values for links.
  106. db_change_field('watchdog', 'link', 'link', array(
  107. 'type' => 'varchar',
  108. 'length' => 255,
  109. 'not null' => FALSE,
  110. 'default' => '',
  111. 'description' => 'Link to view the result of the event.',
  112. ));
  113. // Add an index on uid.
  114. db_add_index('watchdog', 'uid', array('uid'));
  115. // Allow longer type values.
  116. db_change_field('watchdog', 'type', 'type', array(
  117. 'type' => 'varchar',
  118. 'length' => 64,
  119. 'not null' => TRUE,
  120. 'default' => '',
  121. 'description' => 'Type of log message, for example "user" or "page not found."',
  122. ));
  123. // Convert the variables field (that stores serialized variables) from text to blob.
  124. db_change_field('watchdog', 'variables', 'variables', array(
  125. 'type' => 'blob',
  126. 'not null' => TRUE,
  127. 'size' => 'big',
  128. 'description' => 'Serialized array of variables that match the message string and that is passed into the t() function.',
  129. ));
  130. }
  131. /**
  132. * @} End of "addtogroup updates-6.x-to-7.x".
  133. */
  134. /**
  135. * @addtogroup updates-7.x-extra
  136. * @{
  137. */
  138. /**
  139. * Add an index to the severity column in the watchdog database table.
  140. */
  141. function dblog_update_7002() {
  142. db_add_index('watchdog', 'severity', array('severity'));
  143. }
  144. /**
  145. * Account for possible legacy systems where dblog was not installed.
  146. */
  147. function dblog_update_7003() {
  148. if (!db_table_exists('watchdog')) {
  149. db_create_table('watchdog', drupal_get_schema_unprocessed('dblog', 'watchdog'));
  150. }
  151. }
  152. /**
  153. * @} End of "addtogroup updates-7.x-extra".
  154. */