| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615 |
- <?php
- /**
- * @file
- * Openlayers module - installation procedure.
- */
- /**
- * Implements hook_uninstall().
- */
- function openlayers_uninstall() {
- // Get module variables.
- global $conf;
- foreach (array_keys($conf) as $key) {
- // Find variables that have the module prefix.
- if (strpos($key, 'openlayers_') === 0) {
- variable_del($key);
- }
- }
- }
- /**
- * Implements hook_schema().
- */
- function openlayers_schema() {
- $schema = array();
- // Maps table (ctools extras).
- $schema['openlayers_maps'] = array(
- 'description' => 'Storage for User defined Openlayers maps.',
- 'export' => array(
- 'key' => 'machine_name',
- 'key name' => 'Machine name',
- 'primary key' => 'machine_name',
- 'identifier' => 'ol_map',
- 'default hook' => 'default_openlayers_maps',
- 'cache defaults' => TRUE,
- 'api' => array(
- 'owner' => 'openlayers',
- 'api' => 'default_openlayers_maps',
- 'minimum_version' => 1,
- 'current_version' => 1,
- ),
- ),
- 'fields' => array(
- 'machine_name' => array(
- 'description' => 'The primary identifier for the map.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- ),
- 'name' => array(
- 'description' => 'The title of the map.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- ),
- 'description' => array(
- 'description' => 'The description of the map.',
- 'type' => 'text',
- ),
- 'factory_service' => array(
- 'type' => 'text',
- 'description' => 'Map service.',
- ),
- 'options' => array(
- 'description' => 'The serialized map.',
- 'type' => 'text',
- 'serialize' => TRUE,
- ),
- ),
- 'primary key' => array('machine_name'),
- 'unique keys' => array(
- 'machine_name' => array('machine_name'),
- ),
- );
- // Layers table (ctools extras).
- $schema['openlayers_layers'] = array(
- 'description' => 'Storage for user defined Openlayers layers.',
- 'export' => array(
- 'admin_title' => 'machine_name',
- 'key' => 'machine_name',
- 'key name' => 'Machine name',
- 'primary key' => 'machine_name',
- 'identifier' => 'ol_layer',
- 'default hook' => 'default_openlayers_layers',
- 'cache defaults' => TRUE,
- 'api' => array(
- 'owner' => 'openlayers',
- 'api' => 'default_openlayers_layers',
- 'minimum_version' => 1,
- 'current_version' => 1,
- ),
- ),
- 'fields' => array(
- 'machine_name' => array(
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'Layer system name.',
- ),
- 'name' => array(
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'Layer name.',
- ),
- 'description' => array(
- 'type' => 'text',
- 'description' => 'Layer description.',
- ),
- 'factory_service' => array(
- 'type' => 'text',
- 'description' => 'Layer service.',
- ),
- 'options' => array(
- 'type' => 'text',
- 'description' => 'Layer options serialized.',
- 'serialize' => TRUE,
- ),
- ),
- 'primary key' => array('machine_name'),
- 'unique keys' => array(
- 'machine_name' => array('machine_name'),
- ),
- );
- // Sources table (ctools extras).
- $schema['openlayers_sources'] = array(
- 'description' => 'Storage for user defined Openlayers sources.',
- 'export' => array(
- 'admin_title' => 'machine_name',
- 'key' => 'machine_name',
- 'key name' => 'Machine name',
- 'primary key' => 'machine_name',
- 'identifier' => 'ol_source',
- 'default hook' => 'default_openlayers_sources',
- 'cache defaults' => TRUE,
- 'api' => array(
- 'owner' => 'openlayers',
- 'api' => 'default_openlayers_sources',
- 'minimum_version' => 1,
- 'current_version' => 1,
- ),
- ),
- 'fields' => array(
- 'machine_name' => array(
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'Source system name.',
- ),
- 'name' => array(
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'Source name.',
- ),
- 'description' => array(
- 'type' => 'text',
- 'description' => 'Source description.',
- ),
- 'factory_service' => array(
- 'type' => 'text',
- 'description' => 'Service class.',
- ),
- 'options' => array(
- 'type' => 'text',
- 'description' => 'Source options serialized.',
- 'serialize' => TRUE,
- ),
- ),
- 'primary key' => array('machine_name'),
- 'unique keys' => array(
- 'machine_name' => array('machine_name'),
- ),
- );
- // Controls table.
- $schema['openlayers_controls'] = array(
- 'description' => 'Storage for user defined Openlayers controls.',
- 'export' => array(
- 'admin_title' => 'machine_name',
- 'key' => 'machine_name',
- 'key name' => 'Machine name',
- 'primary key' => 'machine_name',
- 'identifier' => 'ol_control',
- 'default hook' => 'default_openlayers_controls',
- 'cache defaults' => TRUE,
- 'api' => array(
- 'owner' => 'openlayers',
- 'api' => 'default_openlayers_controls',
- 'minimum_version' => 1,
- 'current_version' => 1,
- ),
- ),
- 'fields' => array(
- 'machine_name' => array(
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'Control system name.',
- ),
- 'name' => array(
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'Control name.',
- ),
- 'description' => array(
- 'type' => 'text',
- 'description' => 'Control description.',
- ),
- 'factory_service' => array(
- 'type' => 'text',
- 'description' => 'Control service.',
- ),
- 'options' => array(
- 'type' => 'text',
- 'description' => 'Control options serialized.',
- 'serialize' => TRUE,
- ),
- ),
- 'primary key' => array('machine_name'),
- 'unique keys' => array(
- 'machine_name' => array('machine_name'),
- ),
- );
- // Interactions table.
- $schema['openlayers_interactions'] = array(
- 'description' => 'Storage for user defined Openlayers interactions.',
- 'export' => array(
- 'admin_title' => 'machine_name',
- 'key' => 'machine_name',
- 'key name' => 'Machine name',
- 'primary key' => 'machine_name',
- 'identifier' => 'ol_interaction',
- 'default hook' => 'default_openlayers_interactions',
- 'cache defaults' => TRUE,
- 'api' => array(
- 'owner' => 'openlayers',
- 'api' => 'default_openlayers_interactions',
- 'minimum_version' => 1,
- 'current_version' => 1,
- ),
- ),
- 'fields' => array(
- 'machine_name' => array(
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'Interaction system name.',
- ),
- 'name' => array(
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'Interaction name.',
- ),
- 'description' => array(
- 'type' => 'text',
- 'description' => 'Interaction description.',
- ),
- 'factory_service' => array(
- 'type' => 'text',
- 'description' => 'Interaction service.',
- ),
- 'options' => array(
- 'type' => 'text',
- 'description' => 'Interaction options serialized.',
- 'serialize' => TRUE,
- ),
- ),
- 'primary key' => array('machine_name'),
- 'unique keys' => array(
- 'machine_name' => array('machine_name'),
- ),
- );
- // Components table.
- $schema['openlayers_components'] = array(
- 'description' => 'Storage for user defined Openlayers components.',
- 'export' => array(
- 'admin_title' => 'machine_name',
- 'key' => 'machine_name',
- 'key name' => 'Machine name',
- 'primary key' => 'machine_name',
- 'identifier' => 'ol_component',
- 'default hook' => 'default_openlayers_components',
- 'cache defaults' => TRUE,
- 'api' => array(
- 'owner' => 'openlayers',
- 'api' => 'default_openlayers_components',
- 'minimum_version' => 1,
- 'current_version' => 1,
- ),
- ),
- 'fields' => array(
- 'machine_name' => array(
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'Component system name.',
- ),
- 'name' => array(
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'Component name.',
- ),
- 'description' => array(
- 'type' => 'text',
- 'description' => 'Component description.',
- ),
- 'factory_service' => array(
- 'type' => 'text',
- 'description' => 'Component service.',
- ),
- 'options' => array(
- 'type' => 'text',
- 'description' => 'Component options serialized.',
- 'serialize' => TRUE,
- ),
- ),
- 'primary key' => array('machine_name'),
- 'unique keys' => array(
- 'machine_name' => array('machine_name'),
- ),
- );
- // Projections table.
- $schema['openlayers_projections'] = array(
- 'description' => 'Storage for user defined Openlayers projections.',
- 'export' => array(
- 'admin_title' => 'machine_name',
- 'key' => 'machine_name',
- 'key name' => 'Machine name',
- 'primary key' => 'machine_name',
- 'identifier' => 'ol_projection',
- 'default hook' => 'default_openlayers_projections',
- 'cache defaults' => TRUE,
- 'api' => array(
- 'owner' => 'openlayers',
- 'api' => 'default_openlayers_projections',
- 'minimum_version' => 1,
- 'current_version' => 1,
- ),
- ),
- 'fields' => array(
- 'machine_name' => array(
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'Projection system name.',
- ),
- 'name' => array(
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'Projection name.',
- ),
- 'description' => array(
- 'type' => 'text',
- 'description' => 'Projection description.',
- ),
- 'definition' => array(
- 'type' => 'text',
- 'description' => 'Projection options definition.',
- ),
- ),
- 'primary key' => array('machine_name'),
- 'unique keys' => array(
- 'machine_name' => array('machine_name'),
- ),
- );
- // Styles table.
- $schema['openlayers_styles'] = array(
- 'description' => 'Storage for user defined Openlayers styles.',
- 'export' => array(
- 'admin_title' => 'machine_name',
- 'key' => 'machine_name',
- 'key name' => 'Machine name',
- 'primary key' => 'machine_name',
- 'identifier' => 'ol_style',
- 'default hook' => 'default_openlayers_styles',
- 'cache defaults' => TRUE,
- 'api' => array(
- 'owner' => 'openlayers',
- 'api' => 'default_openlayers_styles',
- 'minimum_version' => 1,
- 'current_version' => 1,
- ),
- ),
- 'fields' => array(
- 'machine_name' => array(
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'Style system name.',
- ),
- 'name' => array(
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'Style name.',
- ),
- 'description' => array(
- 'type' => 'text',
- 'description' => 'Style description.',
- ),
- 'factory_service' => array(
- 'type' => 'text',
- 'description' => 'Style service.',
- ),
- 'options' => array(
- 'type' => 'text',
- 'description' => 'Style options serialized.',
- 'serialize' => TRUE,
- ),
- ),
- 'primary key' => array('machine_name'),
- 'unique keys' => array(
- 'machine_name' => array('machine_name'),
- ),
- );
- return $schema;
- }
- /**
- * Implements hook__requirements().
- */
- function openlayers_requirements($phase) {
- $requirements = array();
- $t = get_t();
- if ($phase != 'install') {
- if (($library = libraries_detect('openlayers3')) && !empty($library['installed'])) {
- $requirements['openlayers3'] = array(
- 'title' => $t('Openlayers'),
- 'severity' => REQUIREMENT_OK,
- 'value' => $t('Openlayers %version installed at %path', array('%path' => $library['library path'], '%version' => $library['version'])),
- );
- }
- else {
- $requirements['openlayers3'] = array(
- 'title' => $t('Openlayers'),
- 'severity' => REQUIREMENT_ERROR,
- 'value' => $t('Openlayers library was not found. To install it, <a href="@url">download it manually</a> or use <em>drush dl-openlayers</em>. The library directory must be named <em>openlayers3</em> to be recognized by this module.', array('@url' => $library['download url'])),
- );
- }
- }
- return $requirements;
- }
- /**
- * Update to the 3.x version.
- */
- function openlayers_update_7350() {
- // Enable new dependencies.
- $dependencies = array(
- 'registry_autoload',
- 'service_container',
- );
- foreach ($dependencies as $module) {
- if (!module_exists($module)) {
- $enabled = module_enable(array($module));
- if (!$enabled) {
- throw new DrupalUpdateException('Could not enable ' . $module . ' module. Make sure it exists and try again.');
- }
- }
- }
- // Ensure update 7201 is done.
- if (db_table_exists('openlayers_map_presets')) {
- // Change table name.
- db_rename_table('openlayers_map_presets', 'openlayers_maps');
- // Set default map variable.
- variable_set('openlayers_default_map', variable_get('openlayers_default_preset', 'default'));
- variable_del('openlayers_default_preset');
- }
- $schema = openlayers_schema();
- // Create missing tables.
- foreach ($schema as $table => $table_schema) {
- if (!db_table_exists($table)) {
- db_create_table($table, $table_schema);
- }
- }
- // Add the machine name column - and deal with the title column.
- foreach ($schema as $table => $table_schema) {
- if (isset($table_schema['fields']['machine_name']) && db_field_exists($table, 'name') && !db_field_exists($table, 'machine_name')) {
- // Add field and index.
- db_add_field($table, 'machine_name', $table_schema['fields']['machine_name'], array('machine_name' => array('machine_name')));
- db_query('UPDATE {' . $table . '} SET machine_name = LOWER(name);');
- db_drop_primary_key($table);
- db_add_primary_key($table, array('machine_name'));
- db_drop_index($table, 'name');
- // If there's a title field this is the new content for name.
- if (db_field_exists($table, 'title')) {
- db_query('UPDATE {' . $table . '} SET name = title;');
- db_drop_field($table, 'title');
- }
- }
- // If there's a data field but none is defined in the schema drop it.
- // @TODO This leads to data loss! Can we do anything better?
- if (!isset($table_schema['data']) && db_field_exists($table, 'data')) {
- db_drop_field($table, 'data');
- }
- }
- // Create missing columns.
- foreach ($schema as $table => $table_schema) {
- foreach (array_keys($table_schema['fields']) as $field) {
- if (!db_field_exists($table, $field)) {
- db_add_field($table, $field, $table_schema['fields'][$field]);
- }
- }
- }
- // Drop extra projection columns.
- // @TODO This ALSO leads to data loss! Can we do anything better?
- $old_projection_columns = array(
- 'identifier',
- 'authority',
- 'code',
- 'definition',
- 'projectedextentleft',
- 'projectedextentbottom',
- 'projectedextentright',
- 'projectedextenttop',
- );
- foreach ($old_projection_columns as $column) {
- if (db_field_exists('openlayers_projections', $column)) {
- db_drop_field('openlayers_projections', $column);
- }
- }
- // Truncate the styles table to remove old OL 2.x styles.
- // @TODO Yes... more data loss...
- db_query('TRUNCATE {openlayers_styles}');
- }
- /**
- * Update factory_service property of each OL objects.
- */
- function openlayers_update_7360() {
- $tables = openlayers_schema();
- foreach ($tables as $table => $table_data) {
- if (!isset($table_data['fields']['factory_service'])) {
- continue;
- }
- $plugin_type = array_pop(explode('_', $table_data['export']['identifier']));
- $fs_before = 'openlayers.' . $plugin_type . '.';
- $fs_after = 'openlayers.' . drupal_ucfirst($plugin_type) . '.';
- db_update($table)
- ->expression('factory_service', 'REPLACE(factory_service, :before, :after)', array(':before' => $fs_before, ':after' => $fs_after))
- ->execute();
- }
- }
- /**
- * Update factory_service property of each OL objects to remove '.internal.'.
- */
- function openlayers_update_7370() {
- $tables = openlayers_schema();
- foreach ($tables as $table => $table_data) {
- if (!isset($table_data['fields']['factory_service'])) {
- continue;
- }
- $fs_before = '.internal.';
- $fs_after = ':';
- db_update($table)
- ->expression('factory_service', 'REPLACE(factory_service, :before, :after)', array(':before' => $fs_before, ':after' => $fs_after))
- ->execute();
- }
- }
- /**
- * Make sure that the submodule service_container_symfony from
- * module service_container is properly enabled.
- */
- function openlayers_update_7380() {
- if (!module_exists('service_container_symfony')) {
- $enabled = module_enable(array('service_container_symfony'));
- if (!$enabled) {
- throw new DrupalUpdateException('Unable to enable the module service_container_symfony from service_container.');
- }
- }
- }
- /**
- * Make sure that the submodule service_container_annotation_discovery
- * from module service_container is properly enabled.
- */
- function openlayers_update_7390() {
- if (!module_exists('service_container_annotation_discovery')) {
- $enabled = module_enable(array('service_container_annotation_discovery'));
- if (!$enabled) {
- throw new DrupalUpdateException('Unable to enable the module service_container_annotation_discovery from service_container.');
- }
- }
- }
|