entity_test.install 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the entity_test module.
  5. */
  6. /**
  7. * Implements hook_uninstall().
  8. */
  9. function entity_test_uninstall() {
  10. // Bypass entity_load() as we cannot use it here.
  11. $types = db_select('entity_test_type', 'et')
  12. ->fields('et')
  13. ->execute()
  14. ->fetchAllAssoc('name');
  15. foreach ($types as $name => $type) {
  16. field_attach_delete_bundle('entity_test', $name);
  17. }
  18. }
  19. /**
  20. * Implements hook_schema().
  21. */
  22. function entity_test_schema() {
  23. $schema['entity_test'] = array(
  24. 'description' => 'Stores entity_test items.',
  25. 'fields' => array(
  26. 'pid' => array(
  27. 'type' => 'serial',
  28. 'not null' => TRUE,
  29. 'description' => 'Primary Key: Unique entity_test item ID.',
  30. ),
  31. 'name' => array(
  32. 'description' => 'The name of the entity_test.',
  33. 'type' => 'varchar',
  34. 'length' => 32,
  35. 'not null' => TRUE,
  36. 'default' => '',
  37. ),
  38. 'uid' => array(
  39. 'type' => 'int',
  40. 'unsigned' => TRUE,
  41. 'not null' => FALSE,
  42. 'default' => NULL,
  43. 'description' => "The {users}.uid of the associated user.",
  44. ),
  45. ),
  46. 'indexes' => array(
  47. 'uid' => array('uid'),
  48. ),
  49. 'foreign keys' => array(
  50. 'uid' => array(
  51. 'table' => 'users',
  52. 'columns' => array('uid' => 'uid')
  53. ),
  54. 'name' => array(
  55. 'table' => 'entity_test_types',
  56. 'columns' => array('name' => 'name')
  57. ),
  58. ),
  59. 'primary key' => array('pid'),
  60. );
  61. $schema['entity_test_type'] = array(
  62. 'description' => 'Stores information about all defined entity_test types.',
  63. 'fields' => array(
  64. 'id' => array(
  65. 'type' => 'serial',
  66. 'not null' => TRUE,
  67. 'description' => 'Primary Key: Unique entity_test type ID.',
  68. ),
  69. 'name' => array(
  70. 'description' => 'The machine-readable name of this entity_test type.',
  71. 'type' => 'varchar',
  72. 'length' => 32,
  73. 'not null' => TRUE,
  74. ),
  75. 'label' => array(
  76. 'description' => 'The human-readable name of this entity_test type.',
  77. 'type' => 'varchar',
  78. 'length' => 255,
  79. 'not null' => TRUE,
  80. 'default' => '',
  81. ),
  82. 'weight' => array(
  83. 'type' => 'int',
  84. 'not null' => TRUE,
  85. 'default' => 0,
  86. 'size' => 'tiny',
  87. 'description' => 'The weight of this entity_test type in relation to others.',
  88. ),
  89. 'locked' => array(
  90. 'description' => 'A boolean indicating whether the administrator may delete this type.',
  91. 'type' => 'int',
  92. 'not null' => TRUE,
  93. 'default' => 0,
  94. 'size' => 'tiny',
  95. ),
  96. 'data' => array(
  97. 'type' => 'text',
  98. 'not null' => FALSE,
  99. 'size' => 'big',
  100. 'serialize' => TRUE,
  101. 'description' => 'A serialized array of additional data related to this entity_test type.',
  102. 'merge' => TRUE,
  103. ),
  104. 'status' => array(
  105. 'type' => 'int',
  106. 'not null' => TRUE,
  107. // Set the default to ENTITY_CUSTOM without using the constant as it is
  108. // not safe to use it at this point.
  109. 'default' => 0x01,
  110. 'size' => 'tiny',
  111. 'description' => 'The exportable status of the entity.',
  112. ),
  113. 'module' => array(
  114. 'description' => 'The name of the providing module if the entity has been defined in code.',
  115. 'type' => 'varchar',
  116. 'length' => 255,
  117. 'not null' => FALSE,
  118. ),
  119. ),
  120. 'primary key' => array('id'),
  121. 'unique keys' => array(
  122. 'name' => array('name'),
  123. ),
  124. );
  125. // Add schema for the revision-test-entity.
  126. $schema['entity_test2'] = $schema['entity_test'];
  127. $schema['entity_test2']['fields']['revision_id'] = array(
  128. 'type' => 'int',
  129. 'unsigned' => TRUE,
  130. 'not null' => FALSE,
  131. 'default' => NULL,
  132. 'description' => 'The ID of the entity\'s default revision.',
  133. );
  134. $schema['entity_test2']['fields']['title'] = array(
  135. 'type' => 'varchar',
  136. 'length' => 255,
  137. 'not null' => TRUE,
  138. 'default' => '',
  139. );
  140. $schema['entity_test2_revision'] = $schema['entity_test'];
  141. $schema['entity_test2_revision']['fields']['revision_id'] = array(
  142. 'type' => 'serial',
  143. 'not null' => TRUE,
  144. 'description' => 'Primary Key: Unique revision ID.',
  145. );
  146. $schema['entity_test2_revision']['fields']['pid'] = array(
  147. 'type' => 'int',
  148. 'unsigned' => TRUE,
  149. 'not null' => FALSE,
  150. 'default' => NULL,
  151. 'description' => 'The ID of the attached entity.',
  152. );
  153. $schema['entity_test2_revision']['fields']['title'] = array(
  154. 'type' => 'varchar',
  155. 'length' => 255,
  156. 'not null' => TRUE,
  157. 'default' => '',
  158. );
  159. $schema['entity_test2_revision']['primary key'] = array('revision_id');
  160. return $schema;
  161. }