openlayers.install 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. <?php
  2. /**
  3. * @file
  4. * Openlayers module - installation procedure.
  5. */
  6. /**
  7. * Implements hook_uninstall().
  8. */
  9. function openlayers_uninstall() {
  10. // Get module variables.
  11. global $conf;
  12. foreach (array_keys($conf) as $key) {
  13. // Find variables that have the module prefix.
  14. if (strpos($key, 'openlayers_') === 0) {
  15. variable_del($key);
  16. }
  17. }
  18. }
  19. /**
  20. * Implements hook_schema().
  21. */
  22. function openlayers_schema() {
  23. $schema = array();
  24. // Maps table (ctools extras).
  25. $schema['openlayers_maps'] = array(
  26. 'description' => 'Storage for User defined Openlayers maps.',
  27. 'export' => array(
  28. 'key' => 'machine_name',
  29. 'key name' => 'Machine name',
  30. 'primary key' => 'machine_name',
  31. 'identifier' => 'ol_map',
  32. 'default hook' => 'default_openlayers_maps',
  33. 'cache defaults' => TRUE,
  34. 'api' => array(
  35. 'owner' => 'openlayers',
  36. 'api' => 'default_openlayers_maps',
  37. 'minimum_version' => 1,
  38. 'current_version' => 1,
  39. ),
  40. ),
  41. 'fields' => array(
  42. 'machine_name' => array(
  43. 'description' => 'The primary identifier for the map.',
  44. 'type' => 'varchar',
  45. 'length' => 255,
  46. 'not null' => TRUE,
  47. 'default' => '',
  48. ),
  49. 'name' => array(
  50. 'description' => 'The title of the map.',
  51. 'type' => 'varchar',
  52. 'length' => 255,
  53. 'not null' => TRUE,
  54. ),
  55. 'description' => array(
  56. 'description' => 'The description of the map.',
  57. 'type' => 'text',
  58. ),
  59. 'factory_service' => array(
  60. 'type' => 'text',
  61. 'description' => 'Map service.',
  62. ),
  63. 'options' => array(
  64. 'description' => 'The serialized map.',
  65. 'type' => 'text',
  66. 'serialize' => TRUE,
  67. ),
  68. ),
  69. 'primary key' => array('machine_name'),
  70. 'unique keys' => array(
  71. 'machine_name' => array('machine_name'),
  72. ),
  73. );
  74. // Layers table (ctools extras).
  75. $schema['openlayers_layers'] = array(
  76. 'description' => 'Storage for user defined Openlayers layers.',
  77. 'export' => array(
  78. 'admin_title' => 'machine_name',
  79. 'key' => 'machine_name',
  80. 'key name' => 'Machine name',
  81. 'primary key' => 'machine_name',
  82. 'identifier' => 'ol_layer',
  83. 'default hook' => 'default_openlayers_layers',
  84. 'cache defaults' => TRUE,
  85. 'api' => array(
  86. 'owner' => 'openlayers',
  87. 'api' => 'default_openlayers_layers',
  88. 'minimum_version' => 1,
  89. 'current_version' => 1,
  90. ),
  91. ),
  92. 'fields' => array(
  93. 'machine_name' => array(
  94. 'type' => 'varchar',
  95. 'length' => '255',
  96. 'not null' => TRUE,
  97. 'default' => '',
  98. 'description' => 'Layer system name.',
  99. ),
  100. 'name' => array(
  101. 'type' => 'varchar',
  102. 'length' => '255',
  103. 'not null' => TRUE,
  104. 'default' => '',
  105. 'description' => 'Layer name.',
  106. ),
  107. 'description' => array(
  108. 'type' => 'text',
  109. 'description' => 'Layer description.',
  110. ),
  111. 'factory_service' => array(
  112. 'type' => 'text',
  113. 'description' => 'Layer service.',
  114. ),
  115. 'options' => array(
  116. 'type' => 'text',
  117. 'description' => 'Layer options serialized.',
  118. 'serialize' => TRUE,
  119. ),
  120. ),
  121. 'primary key' => array('machine_name'),
  122. 'unique keys' => array(
  123. 'machine_name' => array('machine_name'),
  124. ),
  125. );
  126. // Sources table (ctools extras).
  127. $schema['openlayers_sources'] = array(
  128. 'description' => 'Storage for user defined Openlayers sources.',
  129. 'export' => array(
  130. 'admin_title' => 'machine_name',
  131. 'key' => 'machine_name',
  132. 'key name' => 'Machine name',
  133. 'primary key' => 'machine_name',
  134. 'identifier' => 'ol_source',
  135. 'default hook' => 'default_openlayers_sources',
  136. 'cache defaults' => TRUE,
  137. 'api' => array(
  138. 'owner' => 'openlayers',
  139. 'api' => 'default_openlayers_sources',
  140. 'minimum_version' => 1,
  141. 'current_version' => 1,
  142. ),
  143. ),
  144. 'fields' => array(
  145. 'machine_name' => array(
  146. 'type' => 'varchar',
  147. 'length' => '255',
  148. 'not null' => TRUE,
  149. 'default' => '',
  150. 'description' => 'Source system name.',
  151. ),
  152. 'name' => array(
  153. 'type' => 'varchar',
  154. 'length' => '255',
  155. 'not null' => TRUE,
  156. 'default' => '',
  157. 'description' => 'Source name.',
  158. ),
  159. 'description' => array(
  160. 'type' => 'text',
  161. 'description' => 'Source description.',
  162. ),
  163. 'factory_service' => array(
  164. 'type' => 'text',
  165. 'description' => 'Service class.',
  166. ),
  167. 'options' => array(
  168. 'type' => 'text',
  169. 'description' => 'Source options serialized.',
  170. 'serialize' => TRUE,
  171. ),
  172. ),
  173. 'primary key' => array('machine_name'),
  174. 'unique keys' => array(
  175. 'machine_name' => array('machine_name'),
  176. ),
  177. );
  178. // Controls table.
  179. $schema['openlayers_controls'] = array(
  180. 'description' => 'Storage for user defined Openlayers controls.',
  181. 'export' => array(
  182. 'admin_title' => 'machine_name',
  183. 'key' => 'machine_name',
  184. 'key name' => 'Machine name',
  185. 'primary key' => 'machine_name',
  186. 'identifier' => 'ol_control',
  187. 'default hook' => 'default_openlayers_controls',
  188. 'cache defaults' => TRUE,
  189. 'api' => array(
  190. 'owner' => 'openlayers',
  191. 'api' => 'default_openlayers_controls',
  192. 'minimum_version' => 1,
  193. 'current_version' => 1,
  194. ),
  195. ),
  196. 'fields' => array(
  197. 'machine_name' => array(
  198. 'type' => 'varchar',
  199. 'length' => '255',
  200. 'not null' => TRUE,
  201. 'default' => '',
  202. 'description' => 'Control system name.',
  203. ),
  204. 'name' => array(
  205. 'type' => 'varchar',
  206. 'length' => '255',
  207. 'not null' => TRUE,
  208. 'default' => '',
  209. 'description' => 'Control name.',
  210. ),
  211. 'description' => array(
  212. 'type' => 'text',
  213. 'description' => 'Control description.',
  214. ),
  215. 'factory_service' => array(
  216. 'type' => 'text',
  217. 'description' => 'Control service.',
  218. ),
  219. 'options' => array(
  220. 'type' => 'text',
  221. 'description' => 'Control options serialized.',
  222. 'serialize' => TRUE,
  223. ),
  224. ),
  225. 'primary key' => array('machine_name'),
  226. 'unique keys' => array(
  227. 'machine_name' => array('machine_name'),
  228. ),
  229. );
  230. // Interactions table.
  231. $schema['openlayers_interactions'] = array(
  232. 'description' => 'Storage for user defined Openlayers interactions.',
  233. 'export' => array(
  234. 'admin_title' => 'machine_name',
  235. 'key' => 'machine_name',
  236. 'key name' => 'Machine name',
  237. 'primary key' => 'machine_name',
  238. 'identifier' => 'ol_interaction',
  239. 'default hook' => 'default_openlayers_interactions',
  240. 'cache defaults' => TRUE,
  241. 'api' => array(
  242. 'owner' => 'openlayers',
  243. 'api' => 'default_openlayers_interactions',
  244. 'minimum_version' => 1,
  245. 'current_version' => 1,
  246. ),
  247. ),
  248. 'fields' => array(
  249. 'machine_name' => array(
  250. 'type' => 'varchar',
  251. 'length' => '255',
  252. 'not null' => TRUE,
  253. 'default' => '',
  254. 'description' => 'Interaction system name.',
  255. ),
  256. 'name' => array(
  257. 'type' => 'varchar',
  258. 'length' => '255',
  259. 'not null' => TRUE,
  260. 'default' => '',
  261. 'description' => 'Interaction name.',
  262. ),
  263. 'description' => array(
  264. 'type' => 'text',
  265. 'description' => 'Interaction description.',
  266. ),
  267. 'factory_service' => array(
  268. 'type' => 'text',
  269. 'description' => 'Interaction service.',
  270. ),
  271. 'options' => array(
  272. 'type' => 'text',
  273. 'description' => 'Interaction options serialized.',
  274. 'serialize' => TRUE,
  275. ),
  276. ),
  277. 'primary key' => array('machine_name'),
  278. 'unique keys' => array(
  279. 'machine_name' => array('machine_name'),
  280. ),
  281. );
  282. // Components table.
  283. $schema['openlayers_components'] = array(
  284. 'description' => 'Storage for user defined Openlayers components.',
  285. 'export' => array(
  286. 'admin_title' => 'machine_name',
  287. 'key' => 'machine_name',
  288. 'key name' => 'Machine name',
  289. 'primary key' => 'machine_name',
  290. 'identifier' => 'ol_component',
  291. 'default hook' => 'default_openlayers_components',
  292. 'cache defaults' => TRUE,
  293. 'api' => array(
  294. 'owner' => 'openlayers',
  295. 'api' => 'default_openlayers_components',
  296. 'minimum_version' => 1,
  297. 'current_version' => 1,
  298. ),
  299. ),
  300. 'fields' => array(
  301. 'machine_name' => array(
  302. 'type' => 'varchar',
  303. 'length' => '255',
  304. 'not null' => TRUE,
  305. 'default' => '',
  306. 'description' => 'Component system name.',
  307. ),
  308. 'name' => array(
  309. 'type' => 'varchar',
  310. 'length' => '255',
  311. 'not null' => TRUE,
  312. 'default' => '',
  313. 'description' => 'Component name.',
  314. ),
  315. 'description' => array(
  316. 'type' => 'text',
  317. 'description' => 'Component description.',
  318. ),
  319. 'factory_service' => array(
  320. 'type' => 'text',
  321. 'description' => 'Component service.',
  322. ),
  323. 'options' => array(
  324. 'type' => 'text',
  325. 'description' => 'Component options serialized.',
  326. 'serialize' => TRUE,
  327. ),
  328. ),
  329. 'primary key' => array('machine_name'),
  330. 'unique keys' => array(
  331. 'machine_name' => array('machine_name'),
  332. ),
  333. );
  334. // Projections table.
  335. $schema['openlayers_projections'] = array(
  336. 'description' => 'Storage for user defined Openlayers projections.',
  337. 'export' => array(
  338. 'admin_title' => 'machine_name',
  339. 'key' => 'machine_name',
  340. 'key name' => 'Machine name',
  341. 'primary key' => 'machine_name',
  342. 'identifier' => 'ol_projection',
  343. 'default hook' => 'default_openlayers_projections',
  344. 'cache defaults' => TRUE,
  345. 'api' => array(
  346. 'owner' => 'openlayers',
  347. 'api' => 'default_openlayers_projections',
  348. 'minimum_version' => 1,
  349. 'current_version' => 1,
  350. ),
  351. ),
  352. 'fields' => array(
  353. 'machine_name' => array(
  354. 'type' => 'varchar',
  355. 'length' => '255',
  356. 'not null' => TRUE,
  357. 'default' => '',
  358. 'description' => 'Projection system name.',
  359. ),
  360. 'name' => array(
  361. 'type' => 'varchar',
  362. 'length' => '255',
  363. 'not null' => TRUE,
  364. 'default' => '',
  365. 'description' => 'Projection name.',
  366. ),
  367. 'description' => array(
  368. 'type' => 'text',
  369. 'description' => 'Projection description.',
  370. ),
  371. 'definition' => array(
  372. 'type' => 'text',
  373. 'description' => 'Projection options definition.',
  374. ),
  375. ),
  376. 'primary key' => array('machine_name'),
  377. 'unique keys' => array(
  378. 'machine_name' => array('machine_name'),
  379. ),
  380. );
  381. // Styles table.
  382. $schema['openlayers_styles'] = array(
  383. 'description' => 'Storage for user defined Openlayers styles.',
  384. 'export' => array(
  385. 'admin_title' => 'machine_name',
  386. 'key' => 'machine_name',
  387. 'key name' => 'Machine name',
  388. 'primary key' => 'machine_name',
  389. 'identifier' => 'ol_style',
  390. 'default hook' => 'default_openlayers_styles',
  391. 'cache defaults' => TRUE,
  392. 'api' => array(
  393. 'owner' => 'openlayers',
  394. 'api' => 'default_openlayers_styles',
  395. 'minimum_version' => 1,
  396. 'current_version' => 1,
  397. ),
  398. ),
  399. 'fields' => array(
  400. 'machine_name' => array(
  401. 'type' => 'varchar',
  402. 'length' => '255',
  403. 'not null' => TRUE,
  404. 'default' => '',
  405. 'description' => 'Style system name.',
  406. ),
  407. 'name' => array(
  408. 'type' => 'varchar',
  409. 'length' => '255',
  410. 'not null' => TRUE,
  411. 'default' => '',
  412. 'description' => 'Style name.',
  413. ),
  414. 'description' => array(
  415. 'type' => 'text',
  416. 'description' => 'Style description.',
  417. ),
  418. 'factory_service' => array(
  419. 'type' => 'text',
  420. 'description' => 'Style service.',
  421. ),
  422. 'options' => array(
  423. 'type' => 'text',
  424. 'description' => 'Style options serialized.',
  425. 'serialize' => TRUE,
  426. ),
  427. ),
  428. 'primary key' => array('machine_name'),
  429. 'unique keys' => array(
  430. 'machine_name' => array('machine_name'),
  431. ),
  432. );
  433. return $schema;
  434. }
  435. /**
  436. * Implements hook__requirements().
  437. */
  438. function openlayers_requirements($phase) {
  439. $requirements = array();
  440. $t = get_t();
  441. if ($phase != 'install') {
  442. if (($library = libraries_detect('openlayers3')) && !empty($library['installed'])) {
  443. $requirements['openlayers3'] = array(
  444. 'title' => $t('Openlayers'),
  445. 'severity' => REQUIREMENT_OK,
  446. 'value' => $t('Openlayers %version installed at %path', array('%path' => $library['library path'], '%version' => $library['version'])),
  447. );
  448. }
  449. else {
  450. $requirements['openlayers3'] = array(
  451. 'title' => $t('Openlayers'),
  452. 'severity' => REQUIREMENT_ERROR,
  453. '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'])),
  454. );
  455. }
  456. }
  457. return $requirements;
  458. }
  459. /**
  460. * Update to the 3.x version.
  461. */
  462. function openlayers_update_7350() {
  463. // Enable new dependencies.
  464. $dependencies = array(
  465. 'registry_autoload',
  466. 'service_container',
  467. );
  468. foreach ($dependencies as $module) {
  469. if (!module_exists($module)) {
  470. $enabled = module_enable(array($module));
  471. if (!$enabled) {
  472. throw new DrupalUpdateException('Could not enable ' . $module . ' module. Make sure it exists and try again.');
  473. }
  474. }
  475. }
  476. // Ensure update 7201 is done.
  477. if (db_table_exists('openlayers_map_presets')) {
  478. // Change table name.
  479. db_rename_table('openlayers_map_presets', 'openlayers_maps');
  480. // Set default map variable.
  481. variable_set('openlayers_default_map', variable_get('openlayers_default_preset', 'default'));
  482. variable_del('openlayers_default_preset');
  483. }
  484. $schema = openlayers_schema();
  485. // Create missing tables.
  486. foreach ($schema as $table => $table_schema) {
  487. if (!db_table_exists($table)) {
  488. db_create_table($table, $table_schema);
  489. }
  490. }
  491. // Add the machine name column - and deal with the title column.
  492. foreach ($schema as $table => $table_schema) {
  493. if (isset($table_schema['fields']['machine_name']) && db_field_exists($table, 'name') && !db_field_exists($table, 'machine_name')) {
  494. // Add field and index.
  495. db_add_field($table, 'machine_name', $table_schema['fields']['machine_name'], array('machine_name' => array('machine_name')));
  496. db_query('UPDATE {' . $table . '} SET machine_name = LOWER(name);');
  497. db_drop_primary_key($table);
  498. db_add_primary_key($table, array('machine_name'));
  499. db_drop_index($table, 'name');
  500. // If there's a title field this is the new content for name.
  501. if (db_field_exists($table, 'title')) {
  502. db_query('UPDATE {' . $table . '} SET name = title;');
  503. db_drop_field($table, 'title');
  504. }
  505. }
  506. // If there's a data field but none is defined in the schema drop it.
  507. // @TODO This leads to data loss! Can we do anything better?
  508. if (!isset($table_schema['data']) && db_field_exists($table, 'data')) {
  509. db_drop_field($table, 'data');
  510. }
  511. }
  512. // Create missing columns.
  513. foreach ($schema as $table => $table_schema) {
  514. foreach (array_keys($table_schema['fields']) as $field) {
  515. if (!db_field_exists($table, $field)) {
  516. db_add_field($table, $field, $table_schema['fields'][$field]);
  517. }
  518. }
  519. }
  520. // Drop extra projection columns.
  521. // @TODO This ALSO leads to data loss! Can we do anything better?
  522. $old_projection_columns = array(
  523. 'identifier',
  524. 'authority',
  525. 'code',
  526. 'definition',
  527. 'projectedextentleft',
  528. 'projectedextentbottom',
  529. 'projectedextentright',
  530. 'projectedextenttop',
  531. );
  532. foreach ($old_projection_columns as $column) {
  533. if (db_field_exists('openlayers_projections', $column)) {
  534. db_drop_field('openlayers_projections', $column);
  535. }
  536. }
  537. // Truncate the styles table to remove old OL 2.x styles.
  538. // @TODO Yes... more data loss...
  539. db_query('TRUNCATE {openlayers_styles}');
  540. }
  541. /**
  542. * Update factory_service property of each OL objects.
  543. */
  544. function openlayers_update_7360() {
  545. $tables = openlayers_schema();
  546. foreach ($tables as $table => $table_data) {
  547. if (!isset($table_data['fields']['factory_service'])) {
  548. continue;
  549. }
  550. $plugin_type = array_pop(explode('_', $table_data['export']['identifier']));
  551. $fs_before = 'openlayers.' . $plugin_type . '.';
  552. $fs_after = 'openlayers.' . drupal_ucfirst($plugin_type) . '.';
  553. db_update($table)
  554. ->expression('factory_service', 'REPLACE(factory_service, :before, :after)', array(':before' => $fs_before, ':after' => $fs_after))
  555. ->execute();
  556. }
  557. }
  558. /**
  559. * Update factory_service property of each OL objects to remove '.internal.'.
  560. */
  561. function openlayers_update_7370() {
  562. $tables = openlayers_schema();
  563. foreach ($tables as $table => $table_data) {
  564. if (!isset($table_data['fields']['factory_service'])) {
  565. continue;
  566. }
  567. $fs_before = '.internal.';
  568. $fs_after = ':';
  569. db_update($table)
  570. ->expression('factory_service', 'REPLACE(factory_service, :before, :after)', array(':before' => $fs_before, ':after' => $fs_after))
  571. ->execute();
  572. }
  573. }
  574. /**
  575. * Make sure that the submodule service_container_symfony from
  576. * module service_container is properly enabled.
  577. */
  578. function openlayers_update_7380() {
  579. if (!module_exists('service_container_symfony')) {
  580. $enabled = module_enable(array('service_container_symfony'));
  581. if (!$enabled) {
  582. throw new DrupalUpdateException('Unable to enable the module service_container_symfony from service_container.');
  583. }
  584. }
  585. }
  586. /**
  587. * Make sure that the submodule service_container_annotation_discovery
  588. * from module service_container is properly enabled.
  589. */
  590. function openlayers_update_7390() {
  591. if (!module_exists('service_container_annotation_discovery')) {
  592. $enabled = module_enable(array('service_container_annotation_discovery'));
  593. if (!$enabled) {
  594. throw new DrupalUpdateException('Unable to enable the module service_container_annotation_discovery from service_container.');
  595. }
  596. }
  597. }