entity_test.install 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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('users' => 'uid'),
  51. 'name' => array('entity_test_types' => 'name'),
  52. ),
  53. 'primary key' => array('pid'),
  54. );
  55. $schema['entity_test_type'] = array(
  56. 'description' => 'Stores information about all defined entity_test types.',
  57. 'fields' => array(
  58. 'id' => array(
  59. 'type' => 'serial',
  60. 'not null' => TRUE,
  61. 'description' => 'Primary Key: Unique entity_test type ID.',
  62. ),
  63. 'name' => array(
  64. 'description' => 'The machine-readable name of this entity_test type.',
  65. 'type' => 'varchar',
  66. 'length' => 32,
  67. 'not null' => TRUE,
  68. ),
  69. 'label' => array(
  70. 'description' => 'The human-readable name of this entity_test type.',
  71. 'type' => 'varchar',
  72. 'length' => 255,
  73. 'not null' => TRUE,
  74. 'default' => '',
  75. ),
  76. 'weight' => array(
  77. 'type' => 'int',
  78. 'not null' => TRUE,
  79. 'default' => 0,
  80. 'size' => 'tiny',
  81. 'description' => 'The weight of this entity_test type in relation to others.',
  82. ),
  83. 'locked' => array(
  84. 'description' => 'A boolean indicating whether the administrator may delete this type.',
  85. 'type' => 'int',
  86. 'not null' => TRUE,
  87. 'default' => 0,
  88. 'size' => 'tiny',
  89. ),
  90. 'data' => array(
  91. 'type' => 'text',
  92. 'not null' => FALSE,
  93. 'size' => 'big',
  94. 'serialize' => TRUE,
  95. 'description' => 'A serialized array of additional data related to this entity_test type.',
  96. 'merge' => TRUE,
  97. ),
  98. 'status' => array(
  99. 'type' => 'int',
  100. 'not null' => TRUE,
  101. // Set the default to ENTITY_CUSTOM without using the constant as it is
  102. // not safe to use it at this point.
  103. 'default' => 0x01,
  104. 'size' => 'tiny',
  105. 'description' => 'The exportable status of the entity.',
  106. ),
  107. 'module' => array(
  108. 'description' => 'The name of the providing module if the entity has been defined in code.',
  109. 'type' => 'varchar',
  110. 'length' => 255,
  111. 'not null' => FALSE,
  112. ),
  113. ),
  114. 'primary key' => array('id'),
  115. 'unique keys' => array(
  116. 'name' => array('name'),
  117. ),
  118. );
  119. // Add schema for the revision-test-entity.
  120. $schema['entity_test2'] = $schema['entity_test'];
  121. $schema['entity_test2']['fields']['revision_id'] = array(
  122. 'type' => 'int',
  123. 'unsigned' => TRUE,
  124. 'not null' => FALSE,
  125. 'default' => NULL,
  126. 'description' => 'The ID of the entity\'s default revision.',
  127. );
  128. $schema['entity_test2']['fields']['title'] = array(
  129. 'type' => 'varchar',
  130. 'length' => 255,
  131. 'not null' => TRUE,
  132. 'default' => '',
  133. );
  134. $schema['entity_test2_revision'] = $schema['entity_test'];
  135. $schema['entity_test2_revision']['fields']['revision_id'] = array(
  136. 'type' => 'serial',
  137. 'not null' => TRUE,
  138. 'description' => 'Primary Key: Unique revision ID.',
  139. );
  140. $schema['entity_test2_revision']['fields']['pid'] = array(
  141. 'type' => 'int',
  142. 'unsigned' => TRUE,
  143. 'not null' => FALSE,
  144. 'default' => NULL,
  145. 'description' => 'The ID of the attached entity.',
  146. );
  147. $schema['entity_test2_revision']['fields']['title'] = array(
  148. 'type' => 'varchar',
  149. 'length' => 255,
  150. 'not null' => TRUE,
  151. 'default' => '',
  152. );
  153. $schema['entity_test2_revision']['primary key'] = array('revision_id');
  154. return $schema;
  155. }