Index: panels.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/panels/panels.install,v
retrieving revision 1.4.2.4
diff -u -p -r1.4.2.4 panels.install
--- panels.install	30 Mar 2009 19:15:08 -0000	1.4.2.4
+++ panels.install	1 Apr 2009 20:20:42 -0000
@@ -1,218 +1,326 @@
-<?php
-// $Id: panels.install,v 1.4.2.4 2009/03/30 19:15:08 merlinofchaos Exp $
-
-/**
- * Implementation of hook_schema().
- */
-function panels_schema() {
-  // This should always point to our 'current' schema. This makes it relatively easy
-  // to keep a record of schema as we make changes to it.
-  return panels_schema_1();
-}
-
-/**
- * Schema version 1 for Panels in D6.
- *
- * Schema v1 is now LOCKED; any changes should be done via panels_schema_2.
- */
-function panels_schema_1() {
-  $schema = array();
-
-  $schema['panels_display'] = array(
-    'export' => array(
-      'object' => 'panels_display',
-      'can disable' => FALSE,
-      'identifier' => 'display',
-    ),
-    'fields' => array(
-      'did' => array(
-        'type' => 'serial',
-        'not null' => TRUE,
-        'no export' => TRUE,
-      ),
-      'layout' => array(
-        'type' => 'varchar',
-        'length' => '32',
-        'default' => '',
-      ),
-      'layout_settings' => array(
-        'type' => 'text',
-        'size' => 'big',
-        'serialize' => TRUE,
-        'object default' => array(),
-      ),
-      'panel_settings' => array(
-        'type' => 'text',
-        'size' => 'big',
-        'serialize' => TRUE,
-        'object default' => array(),
-      ),
-      'cache' => array(
-        'type' => 'text',
-        'serialize' => TRUE,
-        'object default' => array(),
-      ),
-      'title' => array(
-        'type' => 'varchar',
-        'length' => '255',
-        'default' => '',
-      ),
-      'hide_title' => array(
-        'type' => 'int',
-        'size' => 'tiny',
-        'default' => 0,
-      ),
-    ),
-    'primary key' => array('did'),
-  );
-
-  $schema['panels_pane'] = array(
-    'export' => array(
-      'can disable' => FALSE,
-      'identifier' => 'pane',
-    ),
-    'fields' => array(
-      'pid' => array(
-        'type' => 'serial',
-        'not null' => TRUE,
-      ),
-      'did' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'default' => 0,
-      ),
-      'panel' => array(
-        'type' => 'varchar',
-        'length' => '32',
-        'default' => '',
-      ),
-      'type' => array(
-        'type' => 'varchar',
-        'length' => '32',
-        'default' => '',
-      ),
-      'subtype' => array(
-        'type' => 'varchar',
-        'length' => '64',
-        'default' => '',
-      ),
-      'shown' => array(
-        'type' => 'int',
-        'size' => 'tiny',
-        'default' => 1,
-      ),
-      'access' => array(
-        'type' => 'text',
-        'size' => 'big',
-        'serialize' => TRUE,
-        'object default' => array(),
-      ),
-      'configuration' => array(
-        'type' => 'text',
-        'size' => 'big',
-        'serialize' => TRUE,
-        'object default' => array(),
-      ),
-      'cache' => array(
-        'type' => 'text',
-        'size' => 'big',
-        'serialize' => TRUE,
-        'object default' => array(),
-      ),
-      'style' => array(
-        'type' => 'text',
-        'size' => 'big',
-        'serialize' => TRUE,
-        'object default' => array(),
-      ),
-      'css' => array(
-        'type' => 'text',
-        'size' => 'big',
-        'serialize' => TRUE,
-        'object default' => array(),
-      ),
-      'extras' => array(
-        'type' => 'text',
-        'size' => 'big',
-        'serialize' => TRUE,
-        'object default' => array(),
-      ),
-      'position' => array(
-        'type' => 'int',
-        'size' => 'small',
-        'default' => 0,
-      ),
-    ),
-    'primary key' => array('pid'),
-    'indexes' => array(
-      'did_idx' => array('did')
-    ),
-  );
-
-  return $schema;
-}
-
-/**
- * Implementation of hook_install().
- */
-function panels_install() {
-  drupal_install_schema('panels');
-}
-
-/**
- * Implementation of hook_uninstall().
- */
-function panels_uninstall() {
-  drupal_uninstall_schema('panels');
-}
-
-/**
- * Update from 6.x v2.
- */
-function panels_update_6290() {
-  // This is currently commented out because we failed to establish proper
-  // baselines in previous versions and we want to re-establish this in alpha3.
-  // It will return.
-
-  $ret = array();
-/*
-  // Fetch schema version 1.
-  $schema = panels_schema_1();
-
-  // @TODO: We probably should detect if these are already serial from previous installations. Not sure how.
-
-  // update pid and did to be serial
-  db_drop_primary_key($ret, 'panels_pane');
-  db_change_field($ret, 'panels_pane', 'pid', 'pid', $schema['panels_pane']['fields']['pid'], array('primary key' => array('pid')));
-
-  db_drop_primary_key($ret, 'panels_display');
-  db_change_field($ret, 'panels_display', 'did', 'did', $schema['panels_display']['fields']['did'], array('primary key' => array('did')));
-
-  // Update size of pane 'access' field.
-  db_change_field($ret, 'panels_pane', 'access', 'access', $schema['panels_pane']['fields']['access']);
-
-  // Add some new fields
-  db_add_field($ret, 'panels_pane', 'style', $schema['panels_pane']['fields']['style']);
-  db_add_field($ret, 'panels_pane', 'css', $schema['panels_pane']['fields']['css']);
-  db_add_field($ret, 'panels_pane', 'extras', $schema['panels_pane']['fields']['extras']);
-  // update contents of various fields:
-  // access
-    // @TODO:
-
-  // style
-  // css
-  // extras
-  // configuration
-
-  // Remove panels_object_cache table
-  db_drop_table($ret, 'panels_object_cache');
- */
-  return $ret;
-}
-
-/**
- * Establish a baseline schema version for 6.x-3.x
- */
-function panels_update_6300() {
-  return array();
-}
+<?php
+// $Id: panels.install,v 1.4.2.4 2009/03/30 19:15:08 merlinofchaos Exp $
+
+/**
+ * Implementation of hook_schema().
+ */
+function panels_schema() {
+  // This should always point to our 'current' schema. This makes it relatively easy
+  // to keep a record of schema as we make changes to it.
+  return panels_schema_1();
+}
+
+/**
+ * Schema version 1 for Panels in D6.
+ *
+ * Schema v1 is now LOCKED; any changes should be done via panels_schema_2.
+ */
+function panels_schema_1() {
+  $schema = array();
+
+  $schema['panels_display'] = array(
+    'export' => array(
+      'object' => 'panels_display',
+      'can disable' => FALSE,
+      'identifier' => 'display',
+    ),
+    'fields' => array(
+      'did' => array(
+        'type' => 'serial',
+        'not null' => TRUE,
+        'no export' => TRUE,
+      ),
+      'layout' => array(
+        'type' => 'varchar',
+        'length' => '32',
+        'default' => '',
+      ),
+      'layout_settings' => array(
+        'type' => 'text',
+        'size' => 'big',
+        'serialize' => TRUE,
+        'object default' => array(),
+        'initial ' => array(),
+      ),
+      'panel_settings' => array(
+        'type' => 'text',
+        'size' => 'big',
+        'serialize' => TRUE,
+        'object default' => array(),
+        'initial ' => array(),
+      ),
+      'cache' => array(
+        'type' => 'text',
+        'serialize' => TRUE,
+        'object default' => array(),
+        'initial ' => array(),
+      ),
+      'title' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'default' => '',
+      ),
+      'hide_title' => array(
+        'type' => 'int',
+        'size' => 'tiny',
+        'default' => 0,
+      ),
+    ),
+    'primary key' => array('did'),
+  );
+
+  $schema['panels_pane'] = array(
+    'export' => array(
+      'can disable' => FALSE,
+      'identifier' => 'pane',
+    ),
+    'fields' => array(
+      'pid' => array(
+        'type' => 'serial',
+        'not null' => TRUE,
+      ),
+      'did' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'panel' => array(
+        'type' => 'varchar',
+        'length' => '32',
+        'default' => '',
+      ),
+      'type' => array(
+        'type' => 'varchar',
+        'length' => '32',
+        'default' => '',
+      ),
+      'subtype' => array(
+        'type' => 'varchar',
+        'length' => '64',
+        'default' => '',
+      ),
+      'shown' => array(
+        'type' => 'int',
+        'size' => 'tiny',
+        'default' => 1,
+      ),
+      'access' => array(
+        'type' => 'text',
+        'size' => 'big',
+        'serialize' => TRUE,
+        'object default' => array(),
+        'initial ' => array(),
+      ),
+      'configuration' => array(
+        'type' => 'text',
+        'size' => 'big',
+        'serialize' => TRUE,
+        'object default' => array(),
+        'initial ' => array(),
+      ),
+      'cache' => array(
+        'type' => 'text',
+        'size' => 'big',
+        'serialize' => TRUE,
+        'object default' => array(),
+        'initial ' => array(),
+      ),
+      'style' => array(
+        'type' => 'text',
+        'size' => 'big',
+        'serialize' => TRUE,
+        'object default' => array(),
+        'initial ' => array(),
+      ),
+      'css' => array(
+        'type' => 'text',
+        'size' => 'big',
+        'serialize' => TRUE,
+        'object default' => array(),
+        'initial ' => array(),
+      ),
+      'extras' => array(
+        'type' => 'text',
+        'size' => 'big',
+        'serialize' => TRUE,
+        'object default' => array(),
+        'initial ' => array(),
+      ),
+      'position' => array(
+        'type' => 'int',
+        'size' => 'small',
+        'default' => 0,
+      ),
+    ),
+    'primary key' => array('pid'),
+    'indexes' => array(
+      'did_idx' => array('did')
+    ),
+  );
+
+  return $schema;
+}
+
+/**
+ * Implementation of hook_install().
+ */
+function panels_install() {
+  drupal_install_schema('panels');
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function panels_uninstall() {
+  drupal_uninstall_schema('panels');
+}
+
+/**
+ * Update from 6.x v2.
+ */
+function panels_update_6290() {
+  // This is currently commented out because we failed to establish proper
+  // baselines in previous versions and we want to re-establish this in alpha3.
+  // It will return.
+
+  $ret = array();
+/*
+  // Fetch schema version 1.
+  $schema = panels_schema_1();
+
+  // @TODO: We probably should detect if these are already serial from previous installations. Not sure how.
+  // Update size of pane 'access' field.
+  db_change_field($ret, 'panels_pane', 'access', 'access', $schema['panels_pane']['fields']['access']);
+
+  // update pid and did to be serial
+  db_drop_primary_key($ret, 'panels_pane');
+  db_change_field($ret, 'panels_pane', 'pid', 'pid', $schema['panels_pane']['fields']['pid'], array('primary key' => array('pid')));
+
+  db_drop_primary_key($ret, 'panels_display');
+  db_change_field($ret, 'panels_display', 'did', 'did', $schema['panels_display']['fields']['did'], array('primary key' => array('did')));
+
+  // Update size of pane 'access' field.
+  db_change_field($ret, 'panels_pane', 'access', 'access', $schema['panels_pane']['fields']['access']);
+
+  // Remove panels_object_cache table
+  db_drop_table($ret, 'panels_object_cache');
+ */
+  return $ret;
+}
+
+/**
+ * Special update function for the alpha2 to alpha3 transition after
+ * I messed it up.
+ */
+function panels_update_6291() {
+  $ret = array();
+  // Fetch schema version 1.
+  $schema = panels_schema_1();
+
+
+  // Add some new fields
+  db_add_field($ret, 'panels_pane', 'style', $schema['panels_pane']['fields']['style']);
+  db_add_field($ret, 'panels_pane', 'css', $schema['panels_pane']['fields']['css']);
+  db_add_field($ret, 'panels_pane', 'extras', $schema['panels_pane']['fields']['extras']);
+
+  return $ret;
+}
+
+/**
+ * Update panels pane fields using batch API.
+ */
+function panels_update_6292(&$sandbox) {
+  $ret = array();
+
+  if (!isset($sandbox['progress'])) {
+    $sandbox['progress'] = 0;
+    // We'll -1 to disregard the uid 0...
+    $sandbox['max'] = db_result(db_query('SELECT COUNT(*) FROM {panels_pane}'));
+  }
+
+  // configuration
+  $result = db_query_range("SELECT pid, access, configuration FROM {panels_pane} ORDER BY pid ASC", $sandbox['progress'], 20);
+  while ($pane = db_fetch_object($result)) {
+    // access
+    if (!empty($pane->access)) {
+      $rids = explode(', ', $pane->access);
+      // For safety, eliminate any non-numeric rids, as we occasionally had
+      // problems with nulls and such getting in here:
+      foreach ($rids as $id => $rid) {
+        if (!is_numeric($rid)) {
+          unset($rids[$id]);
+        }
+      }
+
+      if (empty($rids)) {
+        $pane->access = array();
+      }
+      else {
+        // The old access style was just a role based system, so let's convert
+        // it to that.
+        $pane->access = array(
+          'plugins' => array(
+            array(
+              'name' => 'role',
+              'context' => 'logged-in-user',
+              'settings' => array(
+                'rids' => array_values($rids),
+              )
+            ),
+          ),
+        );
+      }
+    }
+    else {
+      $pane->access = array();
+    }
+
+    // Move style from configuration.
+    $pane->configuration = unserialize($pane->configuration);
+    $pane->style = array();
+    if (!empty($pane->configuration['style'])) {
+      $pane->style['style'] = $pane->configuration['style'];
+      unset($pane->configuration['style']);
+    }
+
+    $pane->css = array();
+    // Move css configuration from configuration
+    if (isset($pane->configuration['css_id'])) {
+      $pane->css['css_id'] = $pane->configuration['css_id'];
+      unset($pane->configuration['css_id']);
+    }
+
+    if (isset($pane->configuration['css_class'])) {
+      $pane->css['css_class'] = $pane->configuration['css_class'];
+      unset($pane->configuration['css_class']);
+    }
+
+    // Make sure extras is an array. This isn't used by anything in Panels
+    // yet, so an empty array is just fine.
+    $pane->extras = array();
+    db_query("UPDATE {panels_pane} SET " .
+      "access = '%s', css = '%s', style = '%s', configuration = '%s', extras = '%s'" .
+      " WHERE pid = %d",
+      serialize($pane->access), 
+      serialize($pane->css),
+      serialize($pane->style),
+      serialize($pane->configuration),
+      serialize($pane->extras),
+      $pane->pid);
+
+    $sandbox['progress']++;
+  }
+
+  $ret['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
+  if ($ret['#finished'] === 1) {
+    $ret[] = array('success' => TRUE, 'query' => t('Panel panes were updated'));
+  }
+  return $ret;
+}
+
+/**
+ * Establish a baseline schema version for 6.x-3.x
+ */
+function panels_update_6300() {
+  return array();
+}
