flag_lists.install 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. /**
  3. * @file
  4. * The Flag lists module install file.
  5. */
  6. /**
  7. * Implementation of hook_install().
  8. */
  9. function flag_lists_schema() {
  10. $schema = array();
  11. $schema['flag_lists_flags'] = array(
  12. 'fields' => array(
  13. 'fid' => array(
  14. 'type' => 'serial',
  15. 'size' => 'small',
  16. 'unsigned' => TRUE,
  17. 'not null' => TRUE,
  18. ),
  19. 'pfid' => array(
  20. 'type' => 'int',
  21. 'size' => 'small',
  22. 'unsigned' => TRUE,
  23. 'not null' => TRUE,
  24. ),
  25. 'uid' => array(
  26. 'type' => 'int',
  27. 'size' => 'small',
  28. 'unsigned' => TRUE,
  29. 'not null' => TRUE,
  30. ),
  31. 'entity_type' => array(
  32. 'type' => 'varchar',
  33. 'length' => '32',
  34. 'not null' => TRUE,
  35. 'default' => '',
  36. ),
  37. 'name' => array(
  38. 'type' => 'varchar',
  39. 'length' => '32',
  40. 'not null' => FALSE,
  41. 'default' => '',
  42. ),
  43. 'title' => array(
  44. 'type' => 'varchar',
  45. 'length' => '255',
  46. 'not null' => FALSE,
  47. 'default' => '',
  48. ),
  49. 'options' => array(
  50. 'type' => 'text',
  51. 'not null' => FALSE,
  52. ),
  53. ),
  54. 'primary key' => array('fid'),
  55. 'unique keys' => array(
  56. 'name' => array('name'),
  57. ),
  58. );
  59. $schema['flag_lists_content'] = array(
  60. 'fields' => array(
  61. 'fcid' => array(
  62. 'type' => 'serial',
  63. 'unsigned' => TRUE,
  64. 'not null' => TRUE,
  65. ),
  66. 'fid' => array(
  67. 'type' => 'int',
  68. 'size' => 'small',
  69. 'unsigned' => TRUE,
  70. 'not null' => TRUE,
  71. 'default' => 0,
  72. ),
  73. 'entity_type' => array(
  74. 'type' => 'varchar',
  75. 'length' => '32',
  76. 'not null' => TRUE,
  77. 'default' => '',
  78. ),
  79. 'entity_id' => array(
  80. 'type' => 'int',
  81. 'unsigned' => TRUE,
  82. 'not null' => TRUE,
  83. 'default' => 0,
  84. ),
  85. 'uid' => array(
  86. 'type' => 'int',
  87. 'unsigned' => TRUE,
  88. 'not null' => TRUE,
  89. 'default' => 0,
  90. ),
  91. 'sid' => array(
  92. 'type' => 'int',
  93. 'unsigned' => TRUE,
  94. 'not null' => TRUE,
  95. 'default' => 0,
  96. ),
  97. 'timestamp' => array(
  98. 'type' => 'int',
  99. 'unsigned' => TRUE,
  100. 'not null' => TRUE,
  101. 'default' => 0,
  102. 'disp-size' => 11,
  103. )
  104. ),
  105. 'primary key' => array('fcid'),
  106. 'unique keys' => array(
  107. 'fid_entity_id_uid_sid' => array('fid', 'entity_id', 'uid', 'sid'),
  108. ),
  109. 'indexes' => array(
  110. 'entity_type_entity_id' => array('entity_type', 'entity_id'),
  111. 'entity_type_uid_sid' => array('entity_type', 'uid', 'sid'),
  112. ),
  113. );
  114. $schema['flag_lists_counts'] = array(
  115. 'fields' => array(
  116. 'fid' => array(
  117. 'type' => 'int',
  118. 'size' => 'small',
  119. 'unsigned' => TRUE,
  120. 'not null' => TRUE,
  121. 'default' => 0,
  122. ),
  123. 'entity_type' => array(
  124. 'type' => 'varchar',
  125. 'length' => '32',
  126. 'not null' => TRUE,
  127. 'default' => '',
  128. ),
  129. 'entity_id' => array(
  130. 'type' => 'int',
  131. 'unsigned' => TRUE,
  132. 'not null' => TRUE,
  133. 'default' => 0,
  134. 'disp-width' => '10',
  135. ),
  136. 'count' => array(
  137. 'type' => 'int',
  138. 'unsigned' => TRUE,
  139. 'not null' => TRUE,
  140. 'default' => 0,
  141. 'disp-width' => '10',
  142. )
  143. ),
  144. 'primary key' => array('fid', 'entity_id'),
  145. 'indexes' => array(
  146. 'fid_entity_type' => array('fid', 'entity_type'),
  147. 'entity_type_entity_id' => array('entity_type', 'entity_id'),
  148. 'count' => array('count'),
  149. ),
  150. );
  151. $schema['flag_lists_types'] = array(
  152. 'fields' => array(
  153. 'name' => array(
  154. 'type' => 'varchar',
  155. 'length' => '32',
  156. 'not null' => TRUE,
  157. 'default' => '',
  158. ),
  159. 'type' => array(
  160. 'type' => 'varchar',
  161. 'length' => '32',
  162. 'not null' => FALSE,
  163. 'default' => '')
  164. ),
  165. 'primary key' => array('name', 'type'),
  166. 'indexes' => array(
  167. 'name' => array('name'),
  168. ),
  169. );
  170. return $schema;
  171. }
  172. /**
  173. * Implements hook_install().
  174. */
  175. function flag_lists_install() {
  176. // Set up our default template.
  177. db_insert('flag_lists_types')
  178. ->fields(array(
  179. 'name' => 'fl_template',
  180. ))
  181. ->execute();
  182. }
  183. /**
  184. * Implements hook_uninstall().
  185. */
  186. function flag_lists_uninstall() {
  187. // Remove our template flags.
  188. $query = db_select('flag_lists_types', 'fl');
  189. $query->leftJoin('flag', 'f', 'fl.name = f.name');
  190. $query->addField('fl', 'fid', 'fid');
  191. $query->distinct();
  192. $fids = $query->execute();
  193. foreach ($fids as $fid) {
  194. db_delete('flag')->condition('fid', $fid->fid);
  195. db_delete('flag_content')->condition('fid', $fid->fid);
  196. db_delete('flag_types')->condition('fid', $fid->fid);
  197. db_delete('flag_counts')->condition('fid', $fid->fid);
  198. }
  199. db_delete('variable')->condition('name', 'flag_lists%', 'LIKE');
  200. drupal_set_message(t('Flag lists has been uninstalled.'));
  201. }