panels_node.install 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. /**
  3. * Implementation of hook_schema().
  4. */
  5. function panels_node_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_node_schema_1();
  9. }
  10. /**
  11. * Schema version 1 for Panels in D6.
  12. */
  13. function panels_node_schema_1() {
  14. $schema = array();
  15. $schema['panels_node'] = array(
  16. 'fields' => array(
  17. 'nid' => array(
  18. 'type' => 'int',
  19. 'not null' => TRUE,
  20. 'default' => 0,
  21. ),
  22. 'css_id' => array(
  23. 'type' => 'varchar',
  24. 'length' => '255',
  25. ),
  26. 'did' => array(
  27. 'type' => 'int',
  28. 'not null' => TRUE,
  29. ),
  30. 'pipeline' => array(
  31. 'type' => 'varchar',
  32. 'length' => '255',
  33. ),
  34. ),
  35. 'primary key' => array('did'),
  36. );
  37. return $schema;
  38. }
  39. /**
  40. * Implementation of hook_install().
  41. */
  42. function panels_node_install() {
  43. db_query("UPDATE {system} SET weight = 11 WHERE name = 'panels_node'");
  44. }
  45. /**
  46. * Implementation of hook_uninstall().
  47. */
  48. function panels_node_uninstall() {
  49. db_query("DELETE FROM {node} WHERE type = 'panel'");
  50. drupal_uninstall_schema('panels_node');
  51. }
  52. /**
  53. * Implements hook_update_dependencies().
  54. */
  55. function panels_node_update_dependencies() {
  56. // Update 7301 requires panels storage support
  57. $dependencies['panels_node'][7301] = array(
  58. 'panels' => 7305,
  59. );
  60. return $dependencies;
  61. }
  62. /**
  63. * Implementation of hook_update to handle adding a pipeline
  64. */
  65. function panels_node_update_6001() {
  66. $ret = array();
  67. $field = array(
  68. 'type' => 'varchar',
  69. 'length' => '255',
  70. );
  71. db_add_field('panels_node', 'pipeline', $field);
  72. return $ret;
  73. }
  74. /**
  75. * Migrate legacy Drupal 6 permissions to Drupal 7.
  76. */
  77. function panels_node_update_7301() {
  78. $permissions = array(
  79. 'create panel-nodes' => 'create panel content',
  80. 'edit any panel-nodes' => 'edit any panel content',
  81. 'edit own panel-nodes' => 'edit own panel content',
  82. 'delete any panel-nodes' => 'delete any panel content',
  83. 'delete own panel-nodes' => 'delete own panel content',
  84. );
  85. foreach ($permissions as $legacy_permission => $new_permission) {
  86. $query = db_select('role_permission', 'p')
  87. ->fields('p', array('rid'))
  88. ->condition('permission', $legacy_permission);
  89. $rids = $query->execute()->fetchCol();
  90. foreach ($rids as $rid) {
  91. // Insert the new permission if it doesn't already exist.
  92. db_merge('role_permission')
  93. ->key(array(
  94. 'rid' => $rid,
  95. 'permission' => $new_permission,
  96. ))
  97. ->insertFields(array(
  98. 'rid' => $rid,
  99. 'permission' => $new_permission,
  100. 'module' => 'node',
  101. ))
  102. ->execute();
  103. }
  104. // Delete the legacy permission.
  105. db_delete('role_permission')
  106. ->condition('permission', $legacy_permission)
  107. ->execute();
  108. }
  109. }
  110. /**
  111. * Set the storage type and id on existing panels nodes.
  112. */
  113. function panels_node_update_7302() {
  114. if (!isset($sandbox['progress'])) {
  115. // Initialize batch update information.
  116. $sandbox['progress'] = (float)0;
  117. $sandbox['current_did'] = -1;
  118. $sandbox['max'] = db_query("SELECT COUNT(pd.did)
  119. FROM {panels_display} pd
  120. JOIN {panels_node} pn ON pn.did = pd.did
  121. WHERE pd.storage_type = ''")->fetchField();
  122. }
  123. // Set a limit of how many rows to process per batch.
  124. $limit = 1000;
  125. // Run the query
  126. $result = db_query_range("SELECT pd.did, pn.nid
  127. FROM {panels_display} pd
  128. JOIN {panels_node} pn ON pn.did = pd.did
  129. WHERE pd.storage_type = '' AND pd.did > :current_did", 0, $limit, array(':current_did' => $sandbox['current_did']));
  130. foreach ($result as $row) {
  131. db_update('panels_display')
  132. ->fields(array(
  133. 'storage_type' => 'panels_node',
  134. 'storage_id' => $row->nid,
  135. ))
  136. ->condition('did', $row->did)
  137. ->execute();
  138. // Update our progress information.
  139. $sandbox['progress']++;
  140. $sandbox['current_did'] = $row->did;
  141. }
  142. // Set the "finished" status, to tell batch engine whether this function
  143. // needs to run again.
  144. $sandbox['#finished'] = ($sandbox['progress'] >= $sandbox['max']) ? TRUE : ($sandbox['progress'] / $sandbox['max']);
  145. if ($sandbox['#finished']) {
  146. return t('Added the storage type for panels_node to relevant panels displays');
  147. }
  148. }