openlayers.install 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <?php
  2. /**
  3. * @file
  4. * This file holds the functions for the installing
  5. * and enabling of the openlayers module.
  6. *
  7. * @ingroup openlayers
  8. */
  9. /**
  10. * Implements hook_install().
  11. */
  12. function openlayers_install() {
  13. }
  14. /**
  15. * Implements hook_uninstall().
  16. */
  17. function openlayers_uninstall() {
  18. // Get module variables
  19. global $conf;
  20. foreach (array_keys($conf) as $key) {
  21. // Find variables that have the module prefix
  22. if (strpos($key, 'openlayers_') === 0) {
  23. variable_del($key);
  24. }
  25. }
  26. }
  27. /**
  28. * Implements hook_schema().
  29. */
  30. function openlayers_schema() {
  31. $schema = array();
  32. // Maps table (ctools extras)
  33. $schema['openlayers_maps'] = array(
  34. 'description' => 'Storage for User defined OpenLayers maps.',
  35. 'export' => array(
  36. 'key' => 'name',
  37. 'key name' => 'Name',
  38. 'primary key' => 'name',
  39. 'identifier' => 'openlayers_maps',
  40. 'default hook' => 'openlayers_maps',
  41. 'api' => array(
  42. 'owner' => 'openlayers',
  43. 'api' => 'openlayers_maps',
  44. 'minimum_version' => 1,
  45. 'current_version' => 1,
  46. ),
  47. ),
  48. 'fields' => array(
  49. 'name' => array(
  50. 'description' => 'The primary identifier for the map.',
  51. 'type' => 'varchar',
  52. 'length' => 255,
  53. 'not null' => TRUE,
  54. ),
  55. 'title' => array(
  56. 'description' => 'The title of the map.',
  57. 'type' => 'varchar',
  58. 'length' => 255,
  59. 'not null' => TRUE,
  60. ),
  61. 'description' => array(
  62. 'description' => 'The description of the map.',
  63. 'type' => 'text',
  64. 'not null' => TRUE,
  65. ),
  66. 'data' => array(
  67. 'description' => 'The serialized map.',
  68. 'type' => 'text',
  69. 'not null' => TRUE,
  70. 'serialize' => TRUE,
  71. ),
  72. ),
  73. 'primary key' => array('name'),
  74. );
  75. // Layer table (ctools extras)
  76. $schema['openlayers_layers'] = array(
  77. 'description' => 'Storage for user defined OpenLayers layers.',
  78. 'export' => array(
  79. 'key' => 'name',
  80. 'key name' => 'Name',
  81. 'primary key' => 'name',
  82. 'identifier' => 'openlayers_layers',
  83. 'default hook' => 'openlayers_layers',
  84. 'api' => array(
  85. 'owner' => 'openlayers',
  86. 'api' => 'openlayers_layers',
  87. 'minimum_version' => 1,
  88. 'current_version' => 1,
  89. ),
  90. ),
  91. 'fields' => array(
  92. 'name' => array(
  93. 'type' => 'varchar',
  94. 'length' => '255',
  95. 'not null' => TRUE,
  96. 'default' => '',
  97. 'description' => 'Layer name.',
  98. ),
  99. 'title' => array(
  100. 'type' => 'varchar',
  101. 'length' => '255',
  102. 'not null' => TRUE,
  103. 'default' => '',
  104. 'description' => 'Layer title.',
  105. ),
  106. 'description' => array(
  107. 'type' => 'text',
  108. 'not null' => TRUE,
  109. 'description' => 'Layer description.',
  110. ),
  111. 'data' => array(
  112. 'type' => 'text',
  113. 'not null' => FALSE,
  114. 'description' => 'Layer data serialized.',
  115. 'serialize' => TRUE,
  116. ),
  117. ),
  118. 'primary key' => array('name'),
  119. );
  120. // Styles table (ctools extras)
  121. $schema['openlayers_styles'] = array(
  122. 'description' => 'Storage for user defined OpenLayers styles.',
  123. 'export' => array(
  124. 'key' => 'name',
  125. 'key name' => 'Name',
  126. 'primary key' => 'name',
  127. 'identifier' => 'openlayers_styles',
  128. 'default hook' => 'openlayers_styles',
  129. 'api' => array(
  130. 'owner' => 'openlayers',
  131. 'api' => 'openlayers_styles',
  132. 'minimum_version' => 1,
  133. 'current_version' => 1,
  134. ),
  135. ),
  136. 'fields' => array(
  137. 'name' => array(
  138. 'type' => 'varchar',
  139. 'length' => '255',
  140. 'not null' => TRUE,
  141. 'default' => '',
  142. 'description' => 'Style name.',
  143. ),
  144. 'title' => array(
  145. 'type' => 'varchar',
  146. 'length' => '255',
  147. 'not null' => TRUE,
  148. 'default' => '',
  149. 'description' => 'Style title.',
  150. ),
  151. 'description' => array(
  152. 'type' => 'text',
  153. 'not null' => TRUE,
  154. 'description' => 'Style description.',
  155. ),
  156. 'data' => array(
  157. 'type' => 'text',
  158. 'not null' => FALSE,
  159. 'description' => 'Style data serialized.',
  160. 'serialize' => TRUE,
  161. ),
  162. ),
  163. 'primary key' => array('name'),
  164. );
  165. return $schema;
  166. }
  167. /**
  168. * Implements hook_requirements().
  169. */
  170. function openlayers_requirements($phase) {
  171. $req = array();
  172. $t = get_t();
  173. // We should not require a specfic version of the OpenLayers library, but
  174. // we should tell the administrator that specific versions are more
  175. // compatible than others.
  176. if ($phase == 'runtime') {
  177. $ol_library_version = 0;
  178. $current_library = variable_get('openlayers_source', OPENLAYERS_DEFAULT_LIBRARY);
  179. // As of 2.11, the hosted version supports the newest hosted
  180. // stable with an actual version number. This used to be just under
  181. // the 'api' path.
  182. if (strpos($current_library, (string) OPENLAYERS_SUGGESTED_LIBRARY) !== FALSE) {
  183. $ol_library_version = OPENLAYERS_SUGGESTED_LIBRARY;
  184. }
  185. // Check if it is the default hosted.
  186. if ($current_library == 'http://openlayers.org/api/OpenLayers.js') {
  187. $ol_library_version = OPENLAYERS_HOSTED_API_LIBRARY;
  188. }
  189. // Finally, let's see if the client has sent us a value
  190. // from the UI module AJAX magic.
  191. $client = variable_get('openlayers_ui_version_check', '');
  192. if (strpos($client, (string) OPENLAYERS_SUGGESTED_LIBRARY) !== FALSE) {
  193. $ol_library_version = OPENLAYERS_SUGGESTED_LIBRARY;
  194. }
  195. // Check if suggest version.
  196. if ($ol_library_version == OPENLAYERS_SUGGESTED_LIBRARY) {
  197. $req['openlayers_old_presets'] = array(
  198. 'title' => $t('OpenLayers library version'),
  199. 'value' => $t('Using suggested compatible version %suggested.',
  200. array(
  201. '%suggested' => OPENLAYERS_SUGGESTED_LIBRARY,
  202. )),
  203. 'severity' => REQUIREMENT_OK,
  204. );
  205. }
  206. else {
  207. $req['openlayers_old_presets'] = array(
  208. 'title' => $t('OpenLayers library version'),
  209. 'value' => $t('Not suggested compatible version.'),
  210. 'description' => $t('Though you are very welcome to use whatever version of the OpenLayers library you want, it is suggested that you use version %suggested. You are currently not using that version or we are unable to determine which version you are using. Update your library settings at !settings.',
  211. array(
  212. '%suggested' => OPENLAYERS_SUGGESTED_LIBRARY,
  213. '!settings' => l(t('OpenLayers settings'), 'admin/structure/openlayers'),
  214. )),
  215. 'severity' => REQUIREMENT_WARNING,
  216. );
  217. }
  218. }
  219. // There are some backwards compability for the shift from
  220. // preset to maps. We want to communicate to administrators
  221. // that this will not be there forever.
  222. if ($phase == 'runtime') {
  223. // Check preset hook
  224. $presets = module_invoke_all('openlayers_presets');
  225. $found_presets = (count($presets) > 0) ? TRUE : FALSE;
  226. // Check features
  227. $feature_names = array();
  228. $found_features = FALSE;
  229. if (module_exists('features')) {
  230. $features = features_get_features();
  231. foreach ($features as $feature) {
  232. // Only utilize enabled features and look for presets
  233. if ($feature->status > 0 && !empty($feature->info['features']['openlayers_map_presets'])) {
  234. $feature_names[] = $feature->name;
  235. $found_features = TRUE;
  236. }
  237. }
  238. }
  239. // Create requirement entries
  240. if ($found_presets) {
  241. $req['openlayers_old_presets'] = array(
  242. 'title' => $t('OpenLayers Presets'),
  243. 'value' => $t('Found old presets.'),
  244. 'description' => $t('With the 7.x-2.x version of the OpenLayers module, map presets were renamed to just maps. This has some implications on APIs and hooks. One or more of of the modules installed on this site is utilizing the deprecated %hook. Please <a href="@url">read the upgrade page</a>, then contact the module owner or fix the custom module yourself.',
  245. array(
  246. '%hook' => 'hook_openlayers_presets()',
  247. '@url' => url('http://drupal.org/node/1136810'),
  248. )),
  249. 'severity' => REQUIREMENT_ERROR,
  250. );
  251. }
  252. if ($found_features) {
  253. $req['openlayers_old_features'] = array(
  254. 'title' => $t('OpenLayers Presets'),
  255. 'value' => $t('Found Features with presets.'),
  256. 'description' => $t('With the 7.x-2.x version of the OpenLayers module, map presets were renamed to just maps. This has some implications on APIs and hooks. There are Features on this site that contain the old map presets. Please <a href="@url">read the upgrade page</a>, and rebuild the following Features: %features',
  257. array(
  258. '@url' => url('http://drupal.org/node/1136810'),
  259. '%features' => implode(',', $feature_names),
  260. )),
  261. 'severity' => REQUIREMENT_ERROR,
  262. );
  263. }
  264. }
  265. return $req;
  266. }
  267. /**
  268. * Implements hook_update_N().
  269. *
  270. * Rename of presets to maps.
  271. */
  272. function openlayers_update_7201() {
  273. // Change table name
  274. db_rename_table('openlayers_map_presets', 'openlayers_maps');
  275. // Set default map variable
  276. variable_set('openlayers_default_map', variable_get('openlayers_default_preset', 'default'));
  277. variable_del('openlayers_default_preset');
  278. }
  279. /**
  280. * Drop name indexes duplicates of primary key.
  281. */
  282. function openlayers_update_7202() {
  283. db_drop_index('openlayers_layers', 'name');
  284. db_drop_index('openlayers_styles', 'name');
  285. }
  286. /**
  287. * Renamme the 'baselayer' in 'isBaseLayer' in layers.
  288. */
  289. function openlayers_update_7204() {
  290. foreach (openlayers_layers_load() as $key => $layer) {
  291. if ($layer->export_type != 1) continue;
  292. if (isset($layer->data['baselayer'])) {
  293. $layer->data['isBaseLayer'] = $layer->data['baselayer'];
  294. unset($layer->data['baselayer']);
  295. ctools_export_crud_save('openlayers_layers', $layer);
  296. }
  297. }
  298. }
  299. /**
  300. * Change the case of machine_name for layers, maps and styles.
  301. * Warning, it can break things.
  302. */
  303. function openlayers_update_7205() {
  304. db_query('UPDATE {openlayers_layers} SET name = LOWER(name);');
  305. db_query('UPDATE {openlayers_styles} SET name = LOWER(name);');
  306. db_query('UPDATE {openlayers_maps} SET name = LOWER(name);');
  307. }