panels_mini.install 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /**
  3. * @file
  4. */
  5. /**
  6. * Implementation of hook_schema().
  7. */
  8. function panels_mini_schema() {
  9. // This should always point to our 'current' schema. This makes it relatively easy
  10. // to keep a record of schema as we make changes to it.
  11. return panels_mini_schema_1();
  12. }
  13. /**
  14. * Schema version 1 for Panels in D6.
  15. */
  16. function panels_mini_schema_1() {
  17. $schema = array();
  18. $schema['panels_mini'] = array(
  19. 'export' => array(
  20. 'identifier' => 'mini',
  21. 'load callback' => 'panels_mini_load',
  22. 'load all callback' => 'panels_mini_load_all',
  23. 'save callback' => 'panels_mini_save',
  24. 'delete callback' => 'panels_mini_delete',
  25. 'export callback' => 'panels_mini_export',
  26. 'api' => array(
  27. 'owner' => 'panels_mini',
  28. 'api' => 'panels_default',
  29. 'minimum_version' => 1,
  30. 'current_version' => 1,
  31. ),
  32. ),
  33. 'fields' => array(
  34. 'pid' => array(
  35. 'type' => 'serial',
  36. 'not null' => TRUE,
  37. 'no export' => TRUE,
  38. 'description' => 'The primary key for uniqueness.',
  39. ),
  40. 'name' => array(
  41. 'type' => 'varchar',
  42. 'length' => '255',
  43. 'description' => 'The unique name of the mini panel.',
  44. ),
  45. 'category' => array(
  46. 'type' => 'varchar',
  47. 'length' => '64',
  48. 'description' => 'The category this mini panel appears in on the add content pane.',
  49. ),
  50. 'did' => array(
  51. 'type' => 'int',
  52. 'no export' => TRUE,
  53. 'description' => 'The display ID of the panel.',
  54. ),
  55. 'admin_title' => array(
  56. 'type' => 'varchar',
  57. 'length' => '128',
  58. 'description' => 'The administrative title of the mini panel.',
  59. ),
  60. 'admin_description' => array(
  61. 'type' => 'text',
  62. 'size' => 'big',
  63. 'description' => 'Administrative title of this mini panel.',
  64. 'object default' => '',
  65. ),
  66. 'requiredcontexts' => array(
  67. 'type' => 'text',
  68. 'size' => 'big',
  69. 'serialize' => TRUE,
  70. 'object default' => array(),
  71. 'description' => 'An array of required contexts.',
  72. ),
  73. 'contexts' => array(
  74. 'type' => 'text',
  75. 'size' => 'big',
  76. 'serialize' => TRUE,
  77. 'object default' => array(),
  78. 'description' => 'An array of contexts embedded into the panel.',
  79. ),
  80. 'relationships' => array(
  81. 'type' => 'text',
  82. 'size' => 'big',
  83. 'serialize' => TRUE,
  84. 'object default' => array(),
  85. 'description' => 'An array of relationships embedded into the panel.',
  86. ),
  87. ),
  88. 'primary key' => array('pid'),
  89. 'unique keys' => array(
  90. 'name' => array('name'),
  91. ),
  92. );
  93. return $schema;
  94. }
  95. /**
  96. * Implementation of hook_uninstall().
  97. */
  98. function panels_mini_uninstall() {
  99. $panels_exists = db_table_exists('panels_display');
  100. $result = db_query("SELECT * FROM {panels_mini}");
  101. $deltas = array();
  102. foreach ($result as $panel_mini) {
  103. // Delete all associated displays.
  104. if (!function_exists('panels_delete_display')) {
  105. require_once drupal_get_path('module', 'panels') . '/panels.module';
  106. }
  107. if ($panels_exists) {
  108. panels_delete_display($panel_mini->did);
  109. }
  110. $deltas[] = $panel_mini->pid;
  111. }
  112. if (db_table_exists('block') && $deltas) {
  113. // Delete all configured blocks.
  114. db_delete('block')
  115. ->condition('module', 'panels_mini')
  116. ->condition('delta', $deltas)
  117. ->execute();
  118. }
  119. }
  120. /**
  121. * Implements hook_update_dependencies().
  122. */
  123. function panels_mini_update_dependencies() {
  124. // Update 7301 requires panels storage support.
  125. $dependencies['panels_mini'][7301] = array(
  126. 'panels' => 7305,
  127. );
  128. return $dependencies;
  129. }
  130. /**
  131. * Set the storage type and id on existing mini panels.
  132. */
  133. function panels_mini_update_7301() {
  134. if (!isset($sandbox['progress'])) {
  135. // Initialize batch update information.
  136. $sandbox['progress'] = (float) 0;
  137. $sandbox['current_did'] = -1;
  138. $sandbox['max'] = db_query("SELECT COUNT(pd.did)
  139. FROM {panels_display} pd
  140. JOIN {panels_mini} pm ON pm.did = pd.did
  141. WHERE pd.storage_type = ''")->fetchField();
  142. }
  143. // Set a limit of how many rows to process per batch.
  144. $limit = 1000;
  145. // Run the query.
  146. $result = db_query_range("SELECT pd.did, pm.name
  147. FROM {panels_display} pd
  148. JOIN {panels_mini} pm ON pm.did = pd.did
  149. WHERE pd.storage_type = '' AND pd.did > :current_did", 0, $limit, array(':current_did' => $sandbox['current_did']));
  150. foreach ($result as $row) {
  151. db_update('panels_display')
  152. ->fields(array(
  153. 'storage_type' => 'panels_mini',
  154. 'storage_id' => $row->name,
  155. ))
  156. ->condition('did', $row->did)
  157. ->execute();
  158. // Update our progress information.
  159. $sandbox['progress']++;
  160. $sandbox['current_did'] = $row->did;
  161. }
  162. // Set the "finished" status, to tell batch engine whether this function
  163. // needs to run again.
  164. $sandbox['#finished'] = ($sandbox['progress'] >= $sandbox['max']) ? TRUE : ($sandbox['progress'] / $sandbox['max']);
  165. if ($sandbox['#finished']) {
  166. return t('Added the storage type for panels_mini to relevant panels displays');
  167. }
  168. }