boxes.install 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the boxes module.
  5. *
  6. */
  7. /**
  8. * Implemenation of hook_schema().
  9. */
  10. function boxes_schema() {
  11. $schema = array();
  12. $schema['box'] = array(
  13. 'description' => 'Stores contents of custom-made blocks.',
  14. 'fields' => array(
  15. 'delta' => array(
  16. 'type' => 'varchar',
  17. 'length' => 32,
  18. 'not null' => TRUE,
  19. 'description' => "The block's {block}.delta.",
  20. ),
  21. 'plugin_key' => array(
  22. 'type' => 'varchar',
  23. 'length' => 64,
  24. 'not null' => TRUE,
  25. 'description' => "The plugin responsible for this block.",
  26. ),
  27. 'title' => array(
  28. 'type' => 'varchar',
  29. 'length' => 64,
  30. 'not null' => TRUE,
  31. 'description' => "Block title.",
  32. ),
  33. 'description' => array(
  34. 'type' => 'varchar',
  35. 'length' => 255,
  36. 'default' => '',
  37. 'description' => 'Block description.',
  38. ),
  39. 'options' => array(
  40. 'type' => 'text',
  41. 'not null' => FALSE,
  42. 'size' => 'big',
  43. 'serialize' => TRUE,
  44. 'description' => 'Block content configuration.',
  45. ),
  46. ),
  47. 'primary key' => array('delta'),
  48. 'export' => array(
  49. 'key' => 'delta',
  50. 'identifier' => 'box',
  51. 'api' => array(
  52. 'owner' => 'boxes',
  53. 'api' => 'box',
  54. 'minimum_version' => 1,
  55. 'current_version' => 1,
  56. ),
  57. ),
  58. );
  59. return $schema;
  60. }
  61. /**
  62. * Implements hook_uninstall().
  63. */
  64. function boxes_uninstall() {
  65. $result = db_query("SELECT bid FROM {block} WHERE module='boxes'");
  66. foreach ($result as $data) {
  67. db_query("DELETE FROM {block} WHERE bid = :bid", array(':bid' => $data->bid));
  68. }
  69. variable_del('boxes_edit_location');
  70. }
  71. /**
  72. * Make boxes content pluggable, move body/format into a serialized options
  73. * array, add plugin key field.
  74. */
  75. function boxes_update_6100() {
  76. $ret = array();
  77. $result = db_query("SELECT delta, body, format FROM {custom_block}");
  78. while ($box = db_fetch_object($result)) {
  79. $body = array(
  80. 'body' => $box->body,
  81. 'format' => $box->format,
  82. );
  83. $box->body = serialize($body);
  84. drupal_write_record('box', $box, 'delta');
  85. }
  86. $spec = array(
  87. 'type' => 'text',
  88. 'not null' => FALSE,
  89. 'size' => 'big',
  90. 'serialize' => TRUE,
  91. 'description' => 'Block content configuration.',
  92. );
  93. db_change_field('box', 'body', 'options', $spec);
  94. db_drop_field('box', 'format');
  95. $spec = array(
  96. 'type' => 'varchar',
  97. 'length' => 64,
  98. 'not null' => TRUE,
  99. 'description' => "The plugin responsible for this block.",
  100. );
  101. db_add_field('box', 'plugin_key', $spec);
  102. // TODO Please review the conversion of this statement to the D7 database API syntax.
  103. /* db_query("UPDATE {custom_block} SET plugin_key = 'simple'") */
  104. db_update('custom_block')
  105. ->fields(array(
  106. 'plugin_key' => 'simple',
  107. ))
  108. ->execute();
  109. // hook_update_N() no longer returns a $ret array. Instead, return
  110. // nothing or a translated string indicating the update ran successfully.
  111. // See http://drupal.org/node/224333#update_sql.
  112. return t('TODO Add a descriptive string here to show in the UI.') /* $ret */;
  113. }
  114. /**
  115. * If Spaces is installed update existing spaces overrides.
  116. */
  117. function boxes_update_6101() {
  118. $ret = array();
  119. if (module_exists('spaces')) {
  120. $result = db_query("SELECT * FROM {spaces_overrides} WHERE object_type = :object_type", array(':object_type' => 'boxes'));
  121. while ($row = db_fetch_object($result)) {
  122. $v = unserialize($row->value);
  123. $v->plugin_key = 'simple';
  124. $v->options = array(
  125. 'body' => $v->body,
  126. 'format' => $v->format,
  127. );
  128. unset($v->body);
  129. unset($v->format);
  130. $row->value = (array) $v;
  131. drupal_write_record('spaces_overrides', $row, array('type', 'id', 'object_type', 'object_id'));
  132. }
  133. $ret[] = array(
  134. 'success' => TRUE,
  135. 'query' => 'Updated Spaces overrides',
  136. );
  137. }
  138. // hook_update_N() no longer returns a $ret array. Instead, return
  139. // nothing or a translated string indicating the update ran successfully.
  140. // See http://drupal.org/node/224333#update_sql.
  141. return t('TODO Add a descriptive string here to show in the UI.') /* $ret */;
  142. }
  143. /**
  144. * Make the box.delta column definition match blocks.delta
  145. */
  146. function boxes_update_6102() {
  147. $ret = array();
  148. $result = db_query('SELECT delta FROM {custom_block} WHERE CHAR_LENGTH(delta) > :CHAR_LENGTH(delta)', array(':CHAR_LENGTH(delta)' => 32))->fetchField();
  149. if (empty($result)) {
  150. db_drop_primary_key('box');
  151. $spec = array(
  152. 'type' => 'varchar',
  153. 'length' => 32,
  154. 'not null' => TRUE,
  155. );
  156. $new_keys = array('primary key' => array('delta'));
  157. db_change_field('box', 'delta', 'delta', $spec, $new_keys);
  158. }
  159. else {
  160. $ret['#abort'] = array(
  161. 'success' => FALSE,
  162. 'query' => "Could not resize the `box.delta` field. Some entries are larger than 32 characters and must be manually truncated.",
  163. );
  164. }
  165. // hook_update_N() no longer returns a $ret array. Instead, return
  166. // nothing or a translated string indicating the update ran successfully.
  167. // See http://drupal.org/node/224333#update_sql.
  168. return t('TODO Add a descriptive string here to show in the UI.') /* $ret */;
  169. }
  170. /**
  171. * Ensure that Spaces overrides are stored as an object, not an array.
  172. */
  173. function boxes_update_6103() {
  174. $ret = array();
  175. if (module_exists('spaces')) {
  176. $result = db_query("SELECT * FROM {spaces_overrides} WHERE object_type = :object_type", array(':object_type' => 'boxes'));
  177. while ($row = db_fetch_object($result)) {
  178. $v = unserialize($row->value);
  179. $row->value = (object) $v;
  180. drupal_write_record('spaces_overrides', $row, array('type', 'id', 'object_type', 'object_id'));
  181. }
  182. $ret[] = array(
  183. 'success' => TRUE,
  184. 'query' => 'Updated Spaces overrides',
  185. );
  186. }
  187. // hook_update_N() no longer returns a $ret array. Instead, return
  188. // nothing or a translated string indicating the update ran successfully.
  189. // See http://drupal.org/node/224333#update_sql.
  190. return t('TODO Add a descriptive string here to show in the UI.') /* $ret */;
  191. }