wing.install 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. /**
  3. * @file
  4. * Install file for W.NG
  5. */
  6. /**
  7. * Helper for entity exportability.
  8. *
  9. * May not use entity_exportable_schema_fields() directly.
  10. *
  11. * @see entity_exportable_schema_fields()
  12. */
  13. function _wing_exportable_schema_fields($entity) {
  14. $t = get_t();
  15. $arg = array('@entity' => $entity);
  16. $ret = array(
  17. 'machine_name' => array(
  18. 'description' => $t('The machine name of the @entity.', $arg),
  19. 'type' => 'varchar',
  20. 'length' => 255,
  21. 'not null' => TRUE,
  22. 'default' => '',
  23. ),
  24. 'title' => array(
  25. 'description' => $t('The human name of the @entity.', $arg),
  26. 'type' => 'varchar',
  27. 'length' => 255,
  28. 'not null' => TRUE,
  29. 'default' => '',
  30. ),
  31. 'created' => array(
  32. 'description' => $t('The Unix timestamp when the @entity was created.', $arg),
  33. 'type' => 'int',
  34. 'not null' => TRUE,
  35. 'default' => 0,
  36. ),
  37. 'changed' => array(
  38. 'description' => t('The Unix timestamp when the @entity was most recently saved.', $arg),
  39. 'type' => 'int',
  40. 'not null' => TRUE,
  41. 'default' => 0,
  42. ),
  43. 'status' => array(
  44. 'description' => $t('The exportable status of the @entity.', $arg),
  45. 'type' => 'int',
  46. 'not null' => TRUE,
  47. // Set the default to ENTITY_CUSTOM without using the constant as it is
  48. // not safe to use it at this point.
  49. 'default' => 0x01,
  50. 'size' => 'tiny',
  51. ),
  52. 'module' => array(
  53. 'description' => $t('The name of the providing module if the @entity has been defined in code.', $arg),
  54. 'type' => 'varchar',
  55. 'length' => 255,
  56. 'not null' => FALSE,
  57. ),
  58. );
  59. return $ret;
  60. }
  61. function wing_field_schema($field) {
  62. $schema = array(
  63. 'columns' => array(
  64. 'rid' => array(
  65. 'description' => 'The id of the role performing the transition.',
  66. 'type' => 'int',
  67. 'unsigned' => TRUE,
  68. 'not null' => TRUE,
  69. ),
  70. 'sid' => array(
  71. 'description' => 'The id of the state at the end of the transition.',
  72. 'type' => 'int',
  73. 'unsigned' => TRUE,
  74. 'not null' => TRUE,
  75. ),
  76. ),
  77. 'indexes' => array(
  78. 'target_id' => array('rid', 'sid'),
  79. ),
  80. 'foreign keys' => array(
  81. 'role' => array(
  82. 'table' => 'role',
  83. 'columns' => array('rid' => 'rid'),
  84. ),
  85. 'next_state' => array(
  86. 'table' => 'wing_state',
  87. 'columns' => array('sid' => 'sid'),
  88. ),
  89. ),
  90. );
  91. return $schema;
  92. }
  93. /**
  94. * Implements hook_schema().
  95. *
  96. * - wing_state
  97. * - wing_workflow
  98. */
  99. function wing_schema() {
  100. $schema = array(
  101. 'wing_state' => array(
  102. 'description' => 'The base table for Wing State entities',
  103. 'fields' => array(
  104. 'sid' => array(
  105. 'type' => 'serial',
  106. 'unsigned' => TRUE,
  107. 'not null' => TRUE,
  108. ),
  109. 'workflow' => array(
  110. 'description' => 'The {wing_workflow}.machine_name of this state.',
  111. 'type' => 'varchar',
  112. 'length' => 32,
  113. 'not null' => TRUE,
  114. 'default' => '',
  115. ),
  116. ) + _wing_exportable_schema_fields('wing_state'),
  117. 'primary key' => array('sid'),
  118. 'indexes' => array(
  119. 'workflow' => array('workflow'),
  120. ),
  121. 'unique keys' => array('machine_name' => array('machine_name')),
  122. 'foreign keys' => array(
  123. 'workflow' => array(
  124. 'table' => 'wing_workflow',
  125. 'columns' => array('workflow' => 'wid'),
  126. ),
  127. ),
  128. ),
  129. 'wing_workflow' => array(
  130. 'description' => 'The base table for Wing Workflow entities',
  131. 'fields' => array(
  132. 'wid' => array(
  133. 'type' => 'serial',
  134. 'unsigned' => TRUE,
  135. 'not null' => TRUE,
  136. ),
  137. ) + _wing_exportable_schema_fields('wing_workflow'),
  138. 'primary key' => array('wid'),
  139. 'unique keys' => array('machine_name' => array('machine_name')),
  140. ),
  141. );
  142. return $schema;
  143. }
  144. /**
  145. * Implements hook_uninstall().
  146. *
  147. * @see entity_test_uninstall() {
  148. */
  149. function wing_uninstall() {
  150. // FIXME: provide correct values.
  151. $wing_state_types = array();
  152. foreach ($wing_state_types as $name => $type) {
  153. field_attach_delete_bundle('entity_test', $name);
  154. }
  155. }