You are here

function openlayers_update_7208 in Openlayers 7.2

Ensure projections carry an authority code.

File

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

Code

function openlayers_update_7208() {

  // Commit 95108d3fa82c34fc5dc5e6e159263232a891a27a introduced authority codes
  // for layers and maps but did not migrate existing data.
  foreach (openlayers_layers_load(TRUE) as $key => $layer) {
    $projections = array();
    foreach ($layer->data['projection'] as $projection) {
      if (mb_strpos($projection, 'EPSG:') === FALSE) {
        $projections[] = 'EPSG:' . $projection;
      }
      else {
        $projections[] = $projection;
      }
    }
    $layer->data['projection'] = $projections;
    ctools_export_crud_save('openlayers_layers', $layer);
  }
  foreach (openlayers_maps(TRUE) as $key => $map) {
    foreach (array(
      'projection',
      'displayProjection',
    ) as $projectionKey) {
      $projection = $map->data[$projectionKey];
      if (mb_strpos($projection, 'EPSG:') === FALSE) {
        $projection = 'EPSG:' . $projection;
      }
      else {
        $projection = $projection;
      }
      $map->data[$projectionKey] = $projection;
    }
    ctools_export_crud_save('openlayers_maps', $map);
  }
}