delta.install 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. /**
  3. * @file
  4. * Contains install, update, and uninstall functions for Skinr.
  5. */
  6. /**
  7. * Implementats hook_schema().
  8. */
  9. function delta_schema() {
  10. $schema['delta'] = array(
  11. 'description' => t('Stores theme-settings templates that allow overriding the theme settings used based on various contexts.'),
  12. 'export' => array(
  13. 'key' => 'machine_name',
  14. 'key name' => 'name',
  15. 'primary key' => 'machine_name',
  16. 'identifier' => 'delta',
  17. 'default hook' => 'delta_default_templates',
  18. 'status' => 'delta_status',
  19. 'api' => array(
  20. 'owner' => 'delta',
  21. 'api' => 'delta',
  22. 'minimum_version' => 3,
  23. 'current_version' => 3,
  24. ),
  25. 'export callback' => 'delta_export',
  26. ),
  27. 'fields' => array(
  28. 'machine_name' => array(
  29. 'description' => 'The system name of this theme settings template.',
  30. 'type' => 'varchar',
  31. 'length' => 32,
  32. 'not null' => TRUE,
  33. ),
  34. 'name' => array(
  35. 'description' => 'The friendly name of this theme settings template.',
  36. 'type' => 'varchar',
  37. 'length' => 128,
  38. 'not null' => TRUE,
  39. ),
  40. 'description' => array(
  41. 'description' => 'A brief description of this theme settings template.',
  42. 'type' => 'text',
  43. 'size' => 'medium',
  44. 'not null' => TRUE,
  45. ),
  46. 'theme' => array(
  47. 'description' => 'The theme for which this theme settings template is relevant.',
  48. 'type' => 'varchar',
  49. 'length' => 128,
  50. 'not null' => TRUE,
  51. ),
  52. 'mode' => array(
  53. 'description' => 'The mode that this template operrates in.',
  54. 'type' => 'varchar',
  55. 'length' => 32,
  56. 'not null' => TRUE,
  57. ),
  58. 'parent' => array(
  59. 'description' => 'The system name of the parent of this theme settings template.',
  60. 'type' => 'varchar',
  61. 'length' => 32,
  62. 'not null' => TRUE,
  63. ),
  64. 'settings' => array(
  65. 'description' => 'Serialized data which is a copy of the theme settings array stored in the system table based on these overrides',
  66. 'type' => 'blob',
  67. 'size' => 'big',
  68. 'not null' => FALSE,
  69. 'serialize' => TRUE,
  70. ),
  71. ),
  72. 'primary key' => array('machine_name'),
  73. );
  74. return $schema;
  75. }
  76. /**
  77. * Rename the delta_theme_settings table to delta only and adjust it to be compatible with Delta 3.x.
  78. */
  79. function delta_update_7301(&$sandbox) {
  80. if (!isset($sandbox['progress'])) {
  81. $sandbox['#finished'] = 0;
  82. $sandbox['progress'] = 0;
  83. $sandbox['max'] = db_select('delta_theme_settings', 'dt')->countQuery()->execute()->fetchField();
  84. foreach (array('tid', 'theme', 'system_name') as $item) {
  85. db_drop_index('delta_theme_settings', $item);
  86. }
  87. db_drop_field('delta_theme_settings', 'tid');
  88. db_change_field('delta_theme_settings', 'data', 'settings', array(
  89. 'description' => 'Serialized data which is a copy of the theme settings array stored in the system table based on these overrides',
  90. 'type' => 'blob',
  91. 'size' => 'big',
  92. 'not null' => FALSE,
  93. 'serialize' => TRUE,
  94. ));
  95. db_change_field('delta_theme_settings', 'system_name', 'machine_name', array(
  96. 'description' => 'The system name of this theme settings template.',
  97. 'type' => 'varchar',
  98. 'length' => 32,
  99. 'not null' => TRUE,
  100. ), array(
  101. 'primary key' => array('machine_name'),
  102. ));
  103. db_change_field('delta_theme_settings', 'theme', 'theme', array(
  104. 'description' => 'The theme for which this theme settings template is relevant.',
  105. 'type' => 'varchar',
  106. 'length' => 128,
  107. 'not null' => TRUE,
  108. ));
  109. db_change_field('delta_theme_settings', 'name', 'name', array(
  110. 'description' => 'The friendly name of this theme settings template.',
  111. 'type' => 'varchar',
  112. 'length' => 128,
  113. 'not null' => TRUE,
  114. ));
  115. db_add_field('delta_theme_settings', 'mode', array(
  116. 'description' => 'The mode that this template operrates in.',
  117. 'type' => 'varchar',
  118. 'length' => 32,
  119. 'not null' => TRUE,
  120. 'initial' => 'override',
  121. ));
  122. db_rename_table('delta_theme_settings', 'delta');
  123. }
  124. $templates = db_select('delta', 'd')
  125. ->fields('d', array('machine_name'))
  126. ->orderBy('machine_name')
  127. ->range($sandbox['progress'], 10)
  128. ->execute()
  129. ->fetchCol();
  130. foreach ($templates as $name) {
  131. $key = 'theme_delta_' . $name . '_settings';
  132. $settings = variable_get($key, array());
  133. variable_del($key);
  134. unset($settings['delta_template']);
  135. db_update('delta')
  136. ->fields(array('settings' => serialize($settings)))
  137. ->condition('machine_name', $name)
  138. ->execute();
  139. $sandbox['progress']++;
  140. }
  141. $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
  142. if ($sandbox['#finished'] >= 1) {
  143. return t("The Delta module's database table has been updated successfully and can now be used with Delta 3.x.");
  144. }
  145. }
  146. /**
  147. * Add a description field to the Delta database table.
  148. */
  149. function delta_update_7302(&$sandbox) {
  150. db_add_field('delta', 'description', array(
  151. 'description' => 'A brief description of this theme settings template.',
  152. 'type' => 'text',
  153. 'size' => 'medium',
  154. 'not null' => TRUE,
  155. 'initial' => '',
  156. ));
  157. return t("Successfully added a description field to the Delta database table.");
  158. }
  159. /**
  160. * Add a parent field to the Delta database table.
  161. */
  162. function delta_update_7303(&$sandbox) {
  163. db_add_field('delta', 'parent', array(
  164. 'description' => 'The system name of the parent of this theme settings template.',
  165. 'type' => 'varchar',
  166. 'length' => 32,
  167. 'not null' => TRUE,
  168. 'initial' => '',
  169. ));
  170. return t("Successfully added a parent field to the Delta database table.");
  171. }
  172. /**
  173. * Add keys to the settings arrays.
  174. */
  175. function delta_update_7304(&$sandbox) {
  176. if (!isset($sandbox['progress'])) {
  177. $sandbox['#finished'] = 0;
  178. $sandbox['progress'] = 0;
  179. $sandbox['max'] = db_select('delta', 'dt')->countQuery()->execute()->fetchField();
  180. }
  181. $templates = db_select('delta', 'd')
  182. ->fields('d', array('machine_name', 'settings', 'theme'))
  183. ->orderBy('machine_name')
  184. ->range($sandbox['progress'], 10)
  185. ->execute();
  186. foreach ($templates as $item) {
  187. $settings = array('theme_' . $item->theme . '_settings' => unserialize($item->settings));
  188. db_update('delta')
  189. ->fields(array('settings' => serialize($settings)))
  190. ->condition('machine_name', $item->machine_name)
  191. ->execute();
  192. $sandbox['progress']++;
  193. }
  194. $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
  195. if ($sandbox['#finished'] >= 1) {
  196. cache_clear_all();
  197. return t("The Delta template settings have been successfully updated.");
  198. }
  199. }