You are here

function _openlayers_upgrade_1xto2x in Openlayers 6.2

Function to handle upgrading from 1.x to 2.x

Return value

Valid return array for Drupal update functions

1 call to _openlayers_upgrade_1xto2x()
openlayers_update_6200 in ./openlayers.install
Implementation of hook_update_N().

File

./openlayers.install, line 231
This file holds the functions for the installing and enabling of the openlayers module.

Code

function _openlayers_upgrade_1xto2x() {
  $ret = array();

  // Add simple note
  $ret[] = array(
    'success' => TRUE,
    'query' => 'Upgrading OpenLayers from 1.x to 2.x',
  );

  // Update preset table
  db_drop_field($ret, 'openlayers_map_presets', 'preset_id');
  db_change_field($ret, 'openlayers_map_presets', 'preset_name', 'name', array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
  ), array(
    'primary key' => array(
      'name',
    ),
  ));
  db_change_field($ret, 'openlayers_map_presets', 'preset_title', 'title', array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
  ), array());
  db_change_field($ret, 'openlayers_map_presets', 'preset_description', 'description', array(
    'type' => 'text',
    'not null' => TRUE,
  ), array());
  db_change_field($ret, 'openlayers_map_presets', 'preset_data', 'data', array(
    'type' => 'text',
    'not null' => TRUE,
  ), array());

  // Add new tables
  $schema = drupal_get_schema_unprocessed('openlayers');
  foreach ($schema as $name => $table) {
    if (!db_table_exists($name)) {
      db_create_table($ret, $name, $table);
    }
  }

  // The only thing we can really do in the upgrade process
  // is to attempt to automate the conversion of the
  // changes in the map preset/array to the new version,
  // and we can only do this for presets in the database,
  // so get all the presets currently in the database.
  $results = db_query("SELECT * FROM {openlayers_map_presets}");
  while ($row = db_fetch_array($results)) {
    $new_map = unserialize($row['data']);

    // Process map parts.
    _openlayers_upgrade_1xto2x_convert_general($new_map, $ret);
    _openlayers_upgrade_1xto2x_convert_layers($new_map, $ret);
    _openlayers_upgrade_1xto2x_convert_behaviors($new_map, $ret);
    _openlayers_upgrade_1xto2x_convert_styles($new_map, $ret);

    // Save new Map back into the database.
    $result = db_query("UPDATE {openlayers_map_presets} SET data='%s' WHERE name='%s'", serialize($new_map), $row['name']);

    // Debug map array
    // $ret[] = array('success' => TRUE, 'query' => '<pre>' . var_export($new_map, TRUE) . '</pre>');
    // Add some output to user.
    $ret[] = array(
      'success' => $result,
      'query' => 'Updated preset: ' . $row['name'] . '. Please ensure to read handbook pages on Drupal.org for manual changes when upgrading.',
      'rows' => 1,
    );
  }
  return $ret;
}