panels_mini.install 5.1 KB

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