history.install 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * @file
  4. * Installation functions for History module.
  5. */
  6. use Drupal\Core\Database\Database;
  7. /**
  8. * Implements hook_schema().
  9. */
  10. function history_schema() {
  11. $schema['history'] = [
  12. 'description' => 'A record of which {users} have read which {node}s.',
  13. 'fields' => [
  14. 'uid' => [
  15. 'description' => 'The {users}.uid that read the {node} nid.',
  16. 'type' => 'int',
  17. 'not null' => TRUE,
  18. 'default' => 0,
  19. ],
  20. 'nid' => [
  21. 'description' => 'The {node}.nid that was read.',
  22. 'type' => 'int',
  23. 'unsigned' => TRUE,
  24. 'not null' => TRUE,
  25. 'default' => 0,
  26. ],
  27. 'timestamp' => [
  28. 'description' => 'The Unix timestamp at which the read occurred.',
  29. 'type' => 'int',
  30. 'not null' => TRUE,
  31. 'default' => 0,
  32. ],
  33. ],
  34. 'primary key' => ['uid', 'nid'],
  35. 'indexes' => [
  36. 'nid' => ['nid'],
  37. ],
  38. ];
  39. return $schema;
  40. }
  41. /**
  42. * Change {history}.nid to an unsigned int in order to match {node}.nid.
  43. */
  44. function history_update_8101() {
  45. $schema = Database::getConnection()->schema();
  46. $schema->dropPrimaryKey('history');
  47. $schema->dropIndex('history', 'nid');
  48. $schema->changeField('history', 'nid', 'nid', [
  49. 'description' => 'The {node}.nid that was read.',
  50. 'type' => 'int',
  51. 'unsigned' => TRUE,
  52. 'not null' => TRUE,
  53. 'default' => 0,
  54. ]);
  55. $schema->addPrimaryKey('history', ['uid', 'nid']);
  56. $spec = [
  57. 'description' => 'A record of which {users} have read which {node}s.',
  58. 'fields' => [
  59. 'uid' => [
  60. 'description' => 'The {users}.uid that read the {node} nid.',
  61. 'type' => 'int',
  62. 'not null' => TRUE,
  63. 'default' => 0,
  64. ],
  65. 'nid' => [
  66. 'description' => 'The {node}.nid that was read.',
  67. 'type' => 'int',
  68. 'unsigned' => TRUE,
  69. 'not null' => TRUE,
  70. 'default' => 0,
  71. ],
  72. 'timestamp' => [
  73. 'description' => 'The Unix timestamp at which the read occurred.',
  74. 'type' => 'int',
  75. 'not null' => TRUE,
  76. 'default' => 0,
  77. ],
  78. ],
  79. 'primary key' => ['uid', 'nid'],
  80. 'indexes' => [
  81. 'nid' => ['nid'],
  82. ],
  83. ];
  84. $schema->addIndex('history', 'nid', ['nid'], $spec);
  85. }