location.install 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the location module.
  5. */
  6. /**
  7. * Implentation of hook_uninstall().
  8. */
  9. function location_uninstall() {
  10. // Delete variables.
  11. variable_del('location_default_country');
  12. variable_del('location_display_location');
  13. variable_del('location_usegmap');
  14. variable_del('location_locpick_macro');
  15. // Delete geocoder settings.
  16. $result = db_query("SELECT name FROM {variable} WHERE name LIKE 'location_geocode_%'")->fetchCol();
  17. foreach ($result as $var) {
  18. variable_del($var);
  19. }
  20. }
  21. /**
  22. * Implementation of hook_schema().
  23. */
  24. function location_schema() {
  25. $schema['location'] = array(
  26. 'description' => 'Locational data managed by location.module.',
  27. 'fields' => array(
  28. 'lid' => array(
  29. 'description' => 'Primary Key: Unique location ID.',
  30. 'type' => 'serial',
  31. 'unsigned' => TRUE,
  32. 'not null' => TRUE,
  33. ),
  34. 'name' => array(
  35. 'description' => 'Place Name.',
  36. 'type' => 'varchar',
  37. 'length' => 255,
  38. 'default' => '',
  39. 'not null' => TRUE,
  40. ),
  41. 'street' => array(
  42. 'description' => 'Street address, line 1.',
  43. 'type' => 'varchar',
  44. 'length' => 255,
  45. 'default' => '',
  46. 'not null' => TRUE,
  47. ),
  48. 'additional' => array(
  49. 'description' => 'Street address, line 2.',
  50. 'type' => 'varchar',
  51. 'length' => 255,
  52. 'default' => '',
  53. 'not null' => TRUE,
  54. ),
  55. 'city' => array(
  56. 'description' => 'City.',
  57. 'type' => 'varchar',
  58. 'length' => 255,
  59. 'default' => '',
  60. 'not null' => TRUE,
  61. ),
  62. 'province' => array(
  63. 'description' => 'State / Province code.',
  64. 'type' => 'varchar',
  65. 'length' => 16,
  66. 'default' => '',
  67. 'not null' => TRUE,
  68. ),
  69. 'postal_code' => array(
  70. 'description' => 'Postal / ZIP code.',
  71. 'type' => 'varchar',
  72. 'length' => 16,
  73. 'default' => '',
  74. 'not null' => TRUE,
  75. ),
  76. 'country' => array(
  77. 'description' => 'Two letter ISO country code.',
  78. 'type' => 'char',
  79. 'length' => 2,
  80. 'not null' => TRUE,
  81. 'default' => '',
  82. ),
  83. 'latitude' => array(
  84. 'description' => 'Location latitude (decimal degrees).',
  85. 'type' => 'numeric',
  86. 'precision' => 10,
  87. 'scale' => 6, // @@@ Shouldn't these all be 7?
  88. 'not null' => TRUE,
  89. 'default' => 0.0,
  90. ),
  91. 'longitude' => array(
  92. 'description' => 'Location longitude (decimal degrees).',
  93. 'type' => 'numeric',
  94. 'precision' => 10,
  95. 'scale' => 6,
  96. 'not null' => TRUE,
  97. 'default' => 0.0,
  98. ),
  99. 'source' => array(
  100. 'description' => 'Source of the latitude and longitude data (Geocoder, user entered, invalid, etc.)',
  101. 'type' => 'int',
  102. 'size' => 'tiny',
  103. 'default' => 0,
  104. 'not null' => TRUE,
  105. ),
  106. // @@@ Historical civicrm field that isn't applicable to location, I think..
  107. 'is_primary' => array(
  108. 'description' => 'Is this the primary location of an object? (unused, civicrm legacy field?).',
  109. 'type' => 'int',
  110. 'size' => 'tiny',
  111. 'default' => 0,
  112. 'not null' => TRUE,
  113. ),
  114. ),
  115. 'primary key' => array('lid'),
  116. );
  117. $schema['location_instance'] = array(
  118. 'description' => 'N:M join table to join locations to other tables.',
  119. 'fields' => array(
  120. 'nid' => array(
  121. 'description' => 'Reference to {node}.nid.',
  122. 'type' => 'int',
  123. 'unsigned' => TRUE,
  124. 'not null' => TRUE,
  125. 'default' => 0,
  126. ),
  127. 'vid' => array(
  128. 'description' => 'Reference to {node_revision}.vid.',
  129. 'type' => 'int',
  130. 'unsigned' => TRUE,
  131. 'not null' => TRUE,
  132. 'default' => 0,
  133. ),
  134. 'uid' => array(
  135. 'description' => 'Reference to {users}.uid.',
  136. 'type' => 'int',
  137. 'unsigned' => TRUE,
  138. 'not null' => TRUE,
  139. 'default' => 0,
  140. ),
  141. 'genid' => array(
  142. 'description' => 'Generic reference key.',
  143. 'type' => 'varchar',
  144. 'length' => 255,
  145. 'not null' => TRUE,
  146. 'default' => '',
  147. ),
  148. 'lid' => array(
  149. 'description' => 'Reference to {location}.lid.',
  150. 'type' => 'int',
  151. 'unsigned' => TRUE,
  152. 'not null' => TRUE,
  153. 'default' => 0,
  154. ),
  155. ),
  156. 'indexes' => array(
  157. 'nid' => array('nid'),
  158. 'vid' => array('vid'),
  159. 'uid' => array('uid'),
  160. 'genid' => array('genid'),
  161. 'lid' => array('lid'),
  162. ),
  163. );
  164. $schema['zipcodes'] = array(
  165. 'description' => 'Location.module zipcode database.',
  166. 'fields' => array(
  167. 'zip' => array(
  168. 'description' => 'Postal / ZIP code.',
  169. 'type' => 'varchar',
  170. 'length' => 16,
  171. 'not null' => TRUE,
  172. 'default' => '0', // @@@ Why?
  173. ),
  174. 'city' => array(
  175. 'description' => 'City.',
  176. 'type' => 'varchar',
  177. 'length' => 30,
  178. 'not null' => TRUE,
  179. 'default' => '',
  180. ),
  181. 'state' => array(
  182. 'description' => 'Province / State.',
  183. 'type' => 'varchar',
  184. 'length' => 30,
  185. 'not null' => TRUE,
  186. 'default' => '',
  187. ),
  188. 'latitude' => array(
  189. 'description' => 'Location latitude (decimal degrees).',
  190. 'type' => 'numeric',
  191. 'precision' => 10,
  192. 'scale' => 6,
  193. 'not null' => TRUE,
  194. 'default' => 0.0,
  195. ),
  196. 'longitude' => array(
  197. 'description' => 'Location longitude (decimal degrees).',
  198. 'type' => 'numeric',
  199. 'precision' => 10,
  200. 'scale' => 6,
  201. 'not null' => TRUE,
  202. 'default' => 0.0,
  203. ),
  204. // @@@ Not used, an artifact of the original data dump format.
  205. 'timezone' => array(
  206. 'description' => 'Timezone (unused).',
  207. 'type' => 'int',
  208. 'size' => 'tiny',
  209. 'not null' => TRUE,
  210. 'default' => 0,
  211. ),
  212. // @@@ Not used, an artifact of the original data dump format.
  213. 'dst' => array(
  214. 'description' => 'Daylight Savings Time (unused).',
  215. 'type' => 'int',
  216. 'size' => 'tiny',
  217. 'not null' => TRUE,
  218. 'default' => 0,
  219. ),
  220. 'country' => array(
  221. 'description' => 'Two letter ISO country code.',
  222. 'type' => 'char',
  223. 'length' => 2,
  224. 'not null' => TRUE,
  225. 'default' => '',
  226. ),
  227. ),
  228. // @@@ This pk is invalid, see issue queue.
  229. //'primary key' => array('country', 'zip'),
  230. // @@@ These need reworked.
  231. 'indexes' => array(
  232. 'pc' => array('country', 'zip'),
  233. 'zip' => array('zip'),
  234. // @@@ No combined one?
  235. 'latitude' => array('latitude'),
  236. 'longitude' => array('longitude'),
  237. 'country' => array('country'),
  238. ),
  239. );
  240. // Copied from system.module.
  241. $schema['cache_location'] = array(
  242. 'description' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.',
  243. 'fields' => array(
  244. 'cid' => array(
  245. 'description' => 'Primary Key: Unique cache ID.',
  246. 'type' => 'varchar',
  247. 'length' => 255,
  248. 'not null' => TRUE,
  249. 'default' => ''),
  250. 'data' => array(
  251. 'description' => 'A collection of data to cache.',
  252. 'type' => 'blob',
  253. 'not null' => FALSE,
  254. 'size' => 'big'),
  255. 'expire' => array(
  256. 'description' => 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.',
  257. 'type' => 'int',
  258. 'not null' => TRUE,
  259. 'default' => 0),
  260. 'created' => array(
  261. 'description' => 'A Unix timestamp indicating when the cache entry was created.',
  262. 'type' => 'int',
  263. 'not null' => TRUE,
  264. 'default' => 0),
  265. 'headers' => array(
  266. 'description' => 'Any custom HTTP headers to be added to cached data.',
  267. 'type' => 'text',
  268. 'not null' => FALSE),
  269. 'serialized' => array(
  270. 'description' => 'A flag to indicate whether content is serialized (1) or not (0).',
  271. 'type' => 'int',
  272. 'size' => 'small',
  273. 'not null' => TRUE,
  274. 'default' => 0)
  275. ),
  276. 'indexes' => array('expire' => array('expire')),
  277. 'primary key' => array('cid'),
  278. );
  279. return $schema;
  280. }
  281. /**
  282. * Legacy update 1.
  283. * Convert tables to utf8.
  284. */
  285. function location_update_1() {
  286. // return _system_update_utf8(array('location', 'zipcodes'));
  287. }
  288. /**
  289. * Legacy update 2.
  290. * Fix a bug with the "us" entry in the "location_configured_countries" var.
  291. */
  292. function location_update_2() {
  293. $configured_countries = variable_get('location_configured_countries', array());
  294. if ($configured_countries['us']) {
  295. $configured_countries['us'] = 'us';
  296. variable_set('location_configured_countries', $configured_countries);
  297. }
  298. return array();
  299. }
  300. /**
  301. * Legacy update 3.
  302. * Allow for postgresql support by renaming the oid column, which is a reserved
  303. * name on postgresql.
  304. */
  305. function location_update_3() {
  306. db_change_field('location', 'oid', 'eid', array(
  307. 'type' => 'int',
  308. 'unsigned' => TRUE,
  309. 'not null' => TRUE,
  310. 'default' => 0,
  311. ));
  312. if (module_exists('views')) {
  313. views_invalidate_cache();
  314. }
  315. return t("The schema for location module has been updated. The update is such that you may want to re-resave any views you have that may include locations.");
  316. }
  317. /***************************************************************
  318. PostgreSQL must be supported in all updates after this comment
  319. ***************************************************************/
  320. /**
  321. * Legacy update 4.
  322. * Add "lid" as the new location key.
  323. */
  324. function location_update_4() {
  325. db_add_field('location', 'lid', array(
  326. 'type' => 'serial',
  327. 'unsigned' => TRUE,
  328. 'not null' => TRUE,
  329. 'description' => 'Primary Key: Unique location ID.',
  330. ));
  331. $result = db_query("SELECT eid, type FROM {location}");
  332. $next_id = 0;
  333. foreach ($result as $row) {
  334. $next_id++;
  335. db_update('location')
  336. ->fields(array(
  337. 'lid' => $next_id,
  338. ))
  339. ->condition('eid', $row->eid)
  340. ->condition('type', $row->type)
  341. ->execute();
  342. }
  343. db_drop_primary_key('location');
  344. db_add_primary_key('location', array('lid'));
  345. db_insert('sequences')
  346. ->fields(array(
  347. 'name' => '{location}_lid',
  348. 'id' => $next_id,
  349. ))
  350. ->execute();
  351. db_add_field('location', 'is_primary', array(
  352. 'description' => 'Is this the primary location of an object? (unused, civicrm legacy field?).',
  353. 'type' => 'int',
  354. 'size' => 'tiny',
  355. 'default' => 0,
  356. 'not null' => TRUE,
  357. ));
  358. db_update('location')
  359. ->fields(array(
  360. 'is_primary' => 1,
  361. ))
  362. ->condition('type', 'user')
  363. ->execute();
  364. foreach (node_type_get_types() as $type) {
  365. $new_setting = variable_get('location_' . $type->type, 0) ? 1 : 0;
  366. variable_del('location_' . $type->type);
  367. variable_set('location_maxnum_' . $type->type, $new_setting);
  368. variable_set('location_defaultnum_' . $type->type, $new_setting);
  369. }
  370. }
  371. /**
  372. * Legacy update 5.
  373. * Postgresql support that was missing from previous update.
  374. *
  375. * This update is redundant now that we have db api functions
  376. * that are database independant.
  377. */
  378. function location_update_5() {
  379. }
  380. /**
  381. * Legacy update 6.
  382. * Use correct country code for Sweeden.
  383. */
  384. function location_update_6() {
  385. db_update('location')
  386. ->fields(array(
  387. 'country' => 'se',
  388. ))
  389. ->condition('country', 'sw')
  390. ->execute();
  391. }
  392. /**
  393. * Update 7 (Location 2.x)
  394. * Generalize google geocoding so you don't have to enter the api key over and over.
  395. */
  396. function location_update_7() {
  397. $services = array('google');
  398. $general_geocoders_in_use = array();
  399. $result = db_query("SELECT * FROM {variable} WHERE name REGEXP '^location_geocode_[a-z][a-z]$'");
  400. foreach ($result as $row) {
  401. $value_decoded = unserialize($row->value);
  402. if (!in_array($value_decoded, $services)) {
  403. db_update('variable')
  404. ->fields(array(
  405. 'value' => serialize($value_decoded . '|' . substr($row->name, 17)),
  406. ))
  407. ->condition('name', $row->name)
  408. ->execute();
  409. }
  410. else {
  411. $general_geocoders_in_use[$value_decoded] = $value_decoded;
  412. }
  413. }
  414. $key = db_query("SELECT value FROM {variable} WHERE name REGEXP '^location_geocode_[a-z][a-z]_google_apikey$'")->fetchField();
  415. db_delete('variable')
  416. ->where("name REGEXP '^location_geocode_[a-z][a-z]_google_apikey$'")
  417. ->execute();
  418. db_insert('variable')
  419. ->fields(array(
  420. 'name' => 'location_geocode_google_apikey',
  421. 'value' => $key,
  422. ))
  423. ->execute();
  424. db_delete('cache')
  425. ->condition('cid', 'variables')
  426. ->execute();
  427. variable_set('location_general_geocoders_in_use', $general_geocoders_in_use);
  428. }
  429. /**
  430. * Location 3.x update 1.
  431. * Add location specific cache table.
  432. */
  433. function location_update_5300() {
  434. $schema['cache_location'] = array(
  435. 'description' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.',
  436. 'fields' => array(
  437. 'cid' => array(
  438. 'description' => 'Primary Key: Unique cache ID.',
  439. 'type' => 'varchar',
  440. 'length' => 255,
  441. 'not null' => TRUE,
  442. 'default' => '',
  443. ),
  444. 'data' => array(
  445. 'description' => 'A collection of data to cache.',
  446. 'type' => 'blob',
  447. 'not null' => FALSE,
  448. 'size' => 'big',
  449. ),
  450. 'expire' => array(
  451. 'description' => 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.',
  452. 'type' => 'int',
  453. 'not null' => TRUE,
  454. 'default' => 0,
  455. ),
  456. 'created' => array(
  457. 'description' => 'A Unix timestamp indicating when the cache entry was created.',
  458. 'type' => 'int',
  459. 'not null' => TRUE,
  460. 'default' => 0,
  461. ),
  462. 'headers' => array(
  463. 'description' => 'Any custom HTTP headers to be added to cached data.',
  464. 'type' => 'text',
  465. 'not null' => FALSE,
  466. ),
  467. ),
  468. 'indexes' => array('expire' => array('expire')),
  469. 'primary key' => array('cid'),
  470. );
  471. db_create_table('cache_location', $schema['cache_location']);
  472. }
  473. /**
  474. * Location 3.x update 2.
  475. * Normalize the location table.
  476. * This allows:
  477. * - Making the loading and saving code cleaner.
  478. * - Fixing a longstanding bug with revisions.
  479. * - Having the same location on multiple nodes/users/both.
  480. * - Garbage collecting unused locations periodically.
  481. * - Having full support for deletions.
  482. * - Full revisions support.
  483. * Note that the location_instance table does NOT have a primary key.
  484. * This is on purpose. It's a N:M join table.
  485. */
  486. function location_update_5301() {
  487. $schema['location_instance'] = array(
  488. 'description' => 'N:M join table to join locations to other tables.',
  489. 'fields' => array(
  490. 'nid' => array(
  491. 'description' => 'Reference to {node}.nid.',
  492. 'type' => 'int',
  493. 'unsigned' => TRUE,
  494. 'not null' => TRUE,
  495. 'default' => 0,
  496. ),
  497. 'vid' => array(
  498. 'description' => 'Reference to {node_revision}.vid.',
  499. 'type' => 'int',
  500. 'unsigned' => TRUE,
  501. 'not null' => TRUE,
  502. 'default' => 0,
  503. ),
  504. 'uid' => array(
  505. 'description' => 'Reference to {users}.uid.',
  506. 'type' => 'int',
  507. 'unsigned' => TRUE,
  508. 'not null' => TRUE,
  509. 'default' => 0,
  510. ),
  511. 'genid' => array(
  512. 'description' => 'Generic reference key.',
  513. 'type' => 'varchar',
  514. 'length' => 255,
  515. 'not null' => TRUE,
  516. 'default' => '',
  517. ),
  518. 'lid' => array(
  519. 'description' => 'Reference to {location}.lid.',
  520. 'type' => 'int',
  521. 'unsigned' => TRUE,
  522. 'not null' => TRUE,
  523. 'default' => 0,
  524. ),
  525. ),
  526. 'indexes' => array(
  527. 'nid' => array('nid'),
  528. 'vid' => array('vid'),
  529. 'uid' => array('uid'),
  530. 'genid' => array('genid'),
  531. 'lid' => array('lid'),
  532. ),
  533. );
  534. db_create_table('location_instance', $schema['location_instance']);
  535. // Synthesise node location data based on what we have.
  536. // Storage of locations was previously stored against node revision, BUT the
  537. // data was not properly duplicated by revision (i.e. only the latest revision
  538. // carried the data.)
  539. // Joining like this allows us to backfill all the old revisions with the current
  540. // data, which is not nice but better than having no data at all when viewing
  541. // old revisions.
  542. $query = db_select('node_revision', 'nr');
  543. $query->join('node_revision', 'nr2', 'nr.nid = nr2.nid');
  544. $query->join('location', 'l', "nr2.vid = l.eid AND l.type = 'node'");
  545. $query->addField('nr', 'nid');
  546. $query->addField('nr', 'vid');
  547. $query->addField('l', 'lid');
  548. db_insert('location_instance')
  549. ->fields(array('nid', 'vid', 'lid'))
  550. ->from($query)
  551. ->execute();
  552. // Users is much simpler.
  553. $query = db_select('location', 'l');
  554. $query->addField('l', 'eid');
  555. $query->addField('l', 'lid');
  556. $query->condition('type', 'user');
  557. db_insert('location_instance')
  558. ->fields(array('uid', 'lid'))
  559. ->from($query)
  560. ->execute();
  561. // Aug 18 2008:
  562. // Save everything else in genid.
  563. $query = db_select('location', 'l');
  564. $query->addExpression("CONCAT(l.type, ':', l.eid)");
  565. $query->addField('l', 'lid');
  566. $query->condition('type', 'user', '<>');
  567. $query->condition('type', 'node', '<>');
  568. db_insert('location_instance')
  569. ->fields(array('genid', 'lid'))
  570. ->from($query)
  571. ->execute();
  572. // Remove now unused columns.
  573. db_drop_field('location', 'type');
  574. db_drop_field('location', 'eid');
  575. // General cleanup.
  576. variable_del('location_user'); // Removed in favor of permission check.
  577. // Variable consolidation (as part of the element based system)
  578. // We're doing this "raw" so we can be sure we got everything moved over,
  579. // INCLUDING content types that were deleted in the past.
  580. // This will let us do better cleanup sometime in the future.
  581. $data = array();
  582. $todelete = array();
  583. foreach(array('name', 'street', 'additional', 'city', 'province', 'postal_code', 'country', 'phone', 'fax') as $field) {
  584. $result = db_query("SELECT name, value FROM {variable} WHERE name > :name", array(':name' => "location_$field%"));
  585. foreach ($result as $row) {
  586. $data[substr($row->name, strlen($field) + 10)][$field] = (string)(int)unserialize($row->value);
  587. $todelete[] = $row->name;
  588. }
  589. }
  590. foreach ($data as $type => $value) {
  591. // We aren't going to trust that hook_locationapi is operational.
  592. // So, stick with some conservative defaults.
  593. $value = array_merge(array(
  594. 'name' => '1',
  595. 'street' => '1',
  596. // additional is left out of this list intentionally.
  597. 'city' => '0',
  598. 'province' => '0',
  599. 'postal_code' => '0',
  600. 'country' => '1',
  601. ), $value);
  602. if (!isset($value['additional'])) {
  603. // Initialize additional to match street.
  604. $value['additional'] = $value['street'];
  605. }
  606. variable_set('location_fields_'. $type, $value);
  607. }
  608. foreach ($todelete as $key) {
  609. variable_del($key);
  610. }
  611. // This update was retrofitted on Aug 18, 2008. Set a flag for use by
  612. // the next update in order to handle the case where someone has already
  613. // updated to EXACTLY schema revision 5301 before the retrofit took effect.
  614. // People who migrated past this point before that date may have the following
  615. // inconsistencies:
  616. // A) location_{field}_{type} variables were not collected for content types
  617. // that had been deleted in the past.
  618. // B) Any locations with the 'type' field set to something other than 'node'
  619. // or 'user' did not get entries in {location_instance}.
  620. variable_set('location_update_5301_retrofit', TRUE);
  621. }
  622. /**
  623. * Location 3.x update 3.
  624. * Add genid to {location_instance}.
  625. */
  626. function location_update_5302() {
  627. // OK, here's the deal. I retrofitted 5301 on Aug 18 2008 to integrate the genid.
  628. // This was needed to fix the pre location 3.x todo item regarding keeping non
  629. // user, non node data intact. People doing an update after Aug 18 will already
  630. // have the genid column in place, so it can be safely skipped.
  631. if (!variable_get('location_update_5301_retrofit', FALSE)) {
  632. db_add_field('location_instance', 'genid', array(
  633. 'description' => 'Generic reference key.',
  634. 'type' => 'varchar',
  635. 'length' => 255,
  636. 'not null' => TRUE,
  637. 'default' => '',
  638. ));
  639. db_add_index('location_instance', 'genid', array('genid'));
  640. }
  641. }
  642. /**
  643. * Location 3.x update 4.
  644. * Shuffle more variables around.
  645. */
  646. function location_update_5303() {
  647. $types = array();
  648. $result = db_query("SELECT name FROM {variable} WHERE name LIKE 'location_display_teaser_%'");
  649. foreach ($result as $row) {
  650. $type = substr($row->name, 24);
  651. $types[$type]['teaser'] = variable_get('location_display_teaser_'. $type, TRUE);
  652. $types[$type]['full'] = variable_get('location_display_full_'. $type, TRUE);
  653. $types[$type]['weight'] = variable_get('location_display_weight_'. $type, 0);
  654. // @@@ Combine location_suppress_country and country require settings to set this up?
  655. $types[$type]['hide'] = array();
  656. }
  657. foreach ($types as $type => $value) {
  658. variable_set("location_display_$type", $value);
  659. variable_del("location_display_teaser_$type");
  660. variable_del("location_display_full_$type");
  661. variable_del("location_display_weight_$type");
  662. }
  663. }
  664. // @@@ Does 5303 need rerun in some circumstances?
  665. /**
  666. * Drupal 6 location 3.x update.
  667. */
  668. function location_update_6301() {
  669. $message = '';
  670. // Update cache table.
  671. db_drop_table('cache_location');
  672. $schema['cache_location'] = array(
  673. 'description' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.',
  674. 'fields' => array(
  675. 'cid' => array(
  676. 'description' => 'Primary Key: Unique cache ID.',
  677. 'type' => 'varchar',
  678. 'length' => 255,
  679. 'not null' => TRUE,
  680. 'default' => ''),
  681. 'data' => array(
  682. 'description' => 'A collection of data to cache.',
  683. 'type' => 'blob',
  684. 'not null' => FALSE,
  685. 'size' => 'big'),
  686. 'expire' => array(
  687. 'description' => 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.',
  688. 'type' => 'int',
  689. 'not null' => TRUE,
  690. 'default' => 0),
  691. 'created' => array(
  692. 'description' => 'A Unix timestamp indicating when the cache entry was created.',
  693. 'type' => 'int',
  694. 'not null' => TRUE,
  695. 'default' => 0),
  696. 'headers' => array(
  697. 'description' => 'Any custom HTTP headers to be added to cached data.',
  698. 'type' => 'text',
  699. 'not null' => FALSE),
  700. 'serialized' => array(
  701. 'description' => 'A flag to indicate whether content is serialized (1) or not (0).',
  702. 'type' => 'int',
  703. 'size' => 'small',
  704. 'not null' => TRUE,
  705. 'default' => 0)
  706. ),
  707. 'indexes' => array('expire' => array('expire')),
  708. 'primary key' => array('cid'),
  709. );
  710. db_create_table('cache_location', $schema['cache_location']);
  711. // LID 0 causes all sorts of issues, and will break our update routine
  712. // unless we handle it beforehand.
  713. // Since we're so nice, we're gonna renumber it for the user.
  714. $has_rows = (bool) db_query_range('SELECT 1 FROM {location} WHERE lid = 0', 0, 1)->fetchField();
  715. if ($has_rows) {
  716. $lid = 1 + db_query('SELECT MAX(lid) FROM {location}')->fetchField();
  717. $message = t('Note: A location with lid 0 was found in your database. It has been moved to lid %lid. You may wish to verify it manually, as lid 0 is usually a corrupt entry.', array('%lid' => $lid));
  718. db_update('location')
  719. ->fields(array(
  720. 'lid' => $lid,
  721. ))
  722. ->condition('lid', 0)
  723. ->execute();
  724. db_update('location_instance')
  725. ->fields(array(
  726. 'lid' => $lid,
  727. ))
  728. ->condition('lid', 0)
  729. ->execute();
  730. }
  731. // Field changes
  732. // {location}
  733. // {location}.lid -- Becomes a serial.
  734. db_drop_primary_key('location');
  735. db_change_field('location', 'lid', 'lid',
  736. array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
  737. array('primary key' => array('lid')));
  738. // (The rest of the changes to this table were moved to update 6302 due to a bug.)
  739. // {location_instance}
  740. // Fix oddly named indexes -- Was using the postgresql method for both.
  741. db_drop_index('location_instance', '{location_instance}_nid_idx');
  742. db_drop_index('location_instance', '{location_instance}_vid_idx');
  743. db_drop_index('location_instance', '{location_instance}_uid_idx');
  744. db_drop_index('location_instance', '{location_instance}_genid_idx');
  745. db_drop_index('location_instance', '{location_instance}_lid_idx');
  746. db_drop_index('location_instance', 'nid');
  747. db_drop_index('location_instance', 'vid');
  748. db_drop_index('location_instance', 'uid');
  749. db_drop_index('location_instance', 'genid');
  750. db_drop_index('location_instance', 'lid');
  751. // Fill in nulls.
  752. db_update('location_instance')
  753. ->fields(array(
  754. 'nid' => 0,
  755. ))
  756. ->isNull('nid')
  757. ->execute();
  758. db_update('location_instance')
  759. ->fields(array(
  760. 'vid' => 0,
  761. ))
  762. ->isNull('vid')
  763. ->execute();
  764. db_update('location_instance')
  765. ->fields(array(
  766. 'uid' => 0,
  767. ))
  768. ->isNull('uid')
  769. ->execute();
  770. db_update('location_instance')
  771. ->fields(array(
  772. 'genid' => 0,
  773. ))
  774. ->isNull('genid')
  775. ->execute();
  776. // {location_instance}.nid
  777. db_change_field('location_instance', 'nid', 'nid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
  778. // {location_instance}.vid
  779. db_change_field('location_instance', 'vid', 'vid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
  780. // {location_instance}.uid
  781. db_change_field('location_instance', 'uid', 'uid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
  782. // {location_instance}.genid
  783. db_change_field('location_instance', 'genid', 'genid', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
  784. // {location_instance}.lid
  785. db_change_field('location_instance', 'lid', 'lid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
  786. // Readd indexes.
  787. db_add_index('location_instance', 'nid', array('nid'));
  788. db_add_index('location_instance', 'vid', array('vid'));
  789. db_add_index('location_instance', 'uid', array('uid'));
  790. db_add_index('location_instance', 'genid', array('genid'));
  791. db_add_index('location_instance', 'lid', array('lid'));
  792. // {zipcodes}
  793. // Drop primary key.
  794. db_drop_primary_key('zipcodes');
  795. if ($message) {
  796. $message .= '<br /><br />';
  797. }
  798. return $message . t('Note: Location.module update 6301 will generate several warnings/failures regarding indexes and primary keys if you are upgrading from one of the 6.x test releases. These warnings can be safely disregarded in this case.');
  799. }
  800. /**
  801. * Drupal 6 location 3.x update, part 2.
  802. */
  803. function location_update_6302() {
  804. // OK, here's the update to fix the previous update which had a few problems
  805. // when upgrading from pre-rc 6.x versions.
  806. // The "mismatch between mysql and postgresql" was actually applicable to
  807. // 6.x-3.0 pre-rc1 as well, but I didn't notice because I accidentally added
  808. // the not null when reformatting the schema.
  809. db_update('location')
  810. ->fields(array(
  811. 'is_primary' => 0,
  812. ))
  813. ->isNull('is_primary')
  814. ->execute();
  815. db_change_field('location', 'is_primary', 'is_primary', array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'not null' => TRUE));
  816. // Fix zipcode mismatches caused by the same problem.
  817. // There shouldn't be any rows like this, but it doesn't hurt to be sure.
  818. db_update('zipcodes')
  819. ->fields(array(
  820. 'zip' => 0,
  821. ))
  822. ->isNull('zip')
  823. ->execute();
  824. // Set not null.
  825. db_change_field('zipcodes', 'zip', 'zip', array('type' => 'varchar', 'length' => 16, 'not null' => TRUE, 'default' => '0'));
  826. // Prepare latitude and longitude for the same.
  827. db_update('zipcodes')
  828. ->fields(array(
  829. 'latitude' => 0.0,
  830. ))
  831. ->isNull('latitude')
  832. ->execute();
  833. db_update('zipcodes')
  834. ->fields(array(
  835. 'longitude' => 0.0,
  836. ))
  837. ->isNull('longitude')
  838. ->execute();
  839. // Set not null.
  840. db_change_field('zipcodes', 'latitude', 'latitude', array('type' => 'numeric', 'not null' => TRUE, 'default' => 0, 'precision' => 10, 'scale' => 6));
  841. db_change_field('zipcodes', 'longitude', 'longitude', array('type' => 'numeric', 'not null' => TRUE, 'default' => 0, 'precision' => 10, 'scale' => 6));
  842. // Prepare country.
  843. update_sql("UPDATE {zipcodes} SET country = '' WHERE country IS NULL");
  844. db_update('zipcodes')
  845. ->fields(array(
  846. 'country' => '',
  847. ))
  848. ->isNull('country')
  849. ->execute();
  850. // Set not null.
  851. db_change_field('zipcodes', 'country', 'country', array('type' => 'char', 'length' => 2, 'not null' => TRUE, 'default' => ''));
  852. // Fix up possible {location} problems from previous update that could be caused if you had NULLed fields.
  853. // Set defaults
  854. $fields = array(
  855. 'name' => '',
  856. 'street' => '',
  857. 'additional' => '',
  858. 'city' => '',
  859. 'province' => '',
  860. 'postal_code' => '',
  861. 'latitude' => 0.0,
  862. 'longitude' => 0.0,
  863. 'source' => 0,
  864. );
  865. foreach ($fields as $field => $value) {
  866. db_update('location')
  867. ->fields(array(
  868. $field => $value,
  869. ))
  870. ->isNull($field)
  871. ->execute();
  872. }
  873. // {location}.name -- NOT NULL
  874. db_change_field('location', 'name', 'name', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
  875. // {location}.street -- NOT NULL
  876. db_change_field('location', 'street', 'street', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
  877. // {location}.additional -- NOT NULL
  878. db_change_field('location', 'additional', 'additional', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
  879. // {location}.city -- NOT NULL
  880. db_change_field('location', 'city', 'city', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
  881. // {location}.province -- NOT NULL
  882. db_change_field('location', 'province', 'province', array('type' => 'varchar', 'length' => 16, 'not null' => TRUE, 'default' => ''));
  883. // {location}.postal_code -- NOT NULL
  884. db_change_field('location', 'postal_code', 'postal_code', array('type' => 'varchar', 'length' => 16, 'not null' => TRUE, 'default' => ''));
  885. // {location}.country -- NOT NULL
  886. db_change_field('location', 'country', 'country', array('type' => 'char', 'length' => 2, 'not null' => TRUE, 'default' => ''));
  887. // {location}.latitude
  888. db_change_field('location', 'latitude', 'latitude', array('type' => 'numeric', 'precision' => 10, 'scale' => 6, 'not null' => TRUE, 'default' => 0.0));
  889. // {location}.longitude
  890. db_change_field('location', 'longitude', 'longitude', array('type' => 'numeric', 'precision' => 10, 'scale' => 6, 'not null' => TRUE, 'default' => 0.0));
  891. // {location}.source
  892. db_change_field('location', 'source', 'source', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0));
  893. }
  894. /**
  895. * Drupal 6 location 3.x update, part 3.
  896. */
  897. function location_update_6303() {
  898. if (!variable_get('location_update_5304_done', FALSE)) {
  899. // Do the same updates as 5304.
  900. // Delete unused variables.
  901. variable_del('location_configured_countries');
  902. variable_del('location_garbagecollect');
  903. // Update province code for Italy/Forlì-Cesena.
  904. db_update('location')
  905. ->fields(array(
  906. 'province' => 'FC',
  907. ))
  908. ->condition('country', 'it')
  909. ->condition('province', 'FO')
  910. ->execute();
  911. // Update province code for Italy/Pesaro e Urbino.
  912. db_update('location')
  913. ->fields(array(
  914. 'province' => 'PU',
  915. ))
  916. ->condition('country', 'it')
  917. ->condition('province', 'PS')
  918. ->execute();
  919. // Do one final garbage collection by hand.
  920. $query = db_select('location_instance', 'li')
  921. ->addField('li', 'lid');
  922. db_delete('location')
  923. ->condition('lid', $query, 'NOT IN')
  924. ->execute();
  925. // Garbage collect {location_phone} by hand.
  926. if (db_table_exists('location_phone')) {
  927. $query = db_select('location', 'l')
  928. ->addField('l', 'lid');
  929. db_delete('location_phone')
  930. ->condition('lid', $query, 'NOT IN')
  931. ->execute();
  932. }
  933. // Garbage collect {location_fax} by hand.
  934. if (db_table_exists('location_fax')) {
  935. $query = db_select('location', 'l')
  936. ->addField('l', 'lid');
  937. db_delete('location_fax')
  938. ->condition('lid', $query, 'NOT IN')
  939. ->execute();
  940. }
  941. variable_del('location_update_5304_done');
  942. }
  943. }
  944. /**
  945. * Upgrade all of the settings variables to the new unified system.
  946. */
  947. function location_update_6304() {
  948. // Skip this update if it was already done on the 5.x side.
  949. if (variable_get('location_update_5305_done', FALSE)) {
  950. variable_del('location_update_5305_done');
  951. return array();
  952. }
  953. $variables = array();
  954. $todelete = array();
  955. $base = array(
  956. 'multiple' => array(
  957. 'min' => 0,
  958. 'max' => 0,
  959. 'add' => 3,
  960. ),
  961. 'form' => array(
  962. 'weight' => 0,
  963. 'collapsible' => TRUE,
  964. 'collapsed' => TRUE,
  965. 'fields' => array(),
  966. ),
  967. 'display' => array(
  968. 'weight' => 0,
  969. 'hide' => array(),
  970. ),
  971. );
  972. // Pull in user settings.
  973. $variables['location_settings_user'] = $base;
  974. $tmp = &$variables['location_settings_user'];
  975. // Users previously could not have multiple locations, initialize with those
  976. // settings.
  977. $tmp['multiple'] = array(
  978. 'min' => 0,
  979. 'max' => 1,
  980. 'add' => 3,
  981. );
  982. $tmp['form']['weight'] = variable_get('location_user_weight', 9);
  983. $tmp['form']['collapsible'] = variable_get('location_user_collapsible', TRUE);
  984. $tmp['form']['collapased'] = variable_get('location_user_collapsed', TRUE);
  985. $tmp['form']['fields'] = variable_get('location_user_fields', array());
  986. // Pull in node settings.
  987. $result = db_query("SELECT name FROM {variable} WHERE name LIKE 'location_maxnum_%'");
  988. foreach ($result as $row) {
  989. $type = substr($row->name, 16);
  990. $todelete[] = $type;
  991. $variables["location_settings_node_$type"] = $base;
  992. $tmp = &$variables["location_settings_node_$type"];
  993. $tmp['multiple']['min'] = 1; // Old behavior was to have the first one be required.
  994. $tmp['multiple']['max'] = variable_get("location_maxnum_$type", 0);
  995. $tmp['multiple']['add'] = variable_get("location_defaultnum_$type", 3);
  996. $tmp['form']['weight'] = variable_get("location_weight_$type", 9);
  997. $tmp['form']['collapsible'] = variable_get("location_collapsible_$type", TRUE);
  998. $tmp['form']['collapsed'] = variable_get("location_collapsed_$type", TRUE);
  999. $tmp['form']['fields'] = variable_get("location_fields_$type", array());
  1000. $tmp['rss']['mode'] = variable_get("location_rss_$type", 'simple');
  1001. $tmp['display'] = variable_get("location_display_$type", array(
  1002. 'teaser' => TRUE,
  1003. 'full' => TRUE,
  1004. 'weight' => 0,
  1005. 'hide' => array(),
  1006. ));
  1007. }
  1008. foreach ($variables as $name => $value) {
  1009. variable_set($name, $value);
  1010. }
  1011. // Delete old node variables.
  1012. foreach ($todelete as $key) {
  1013. // variable_del("location_maxnum_$key");
  1014. // variable_del("location_defaultnum_$key");
  1015. variable_del("location_weight_$key");
  1016. variable_del("location_collapsible_$key");
  1017. variable_del("location_collapsed_$key");
  1018. variable_del("location_fields_$key");
  1019. variable_del("location_rss_$key");
  1020. variable_del("location_display_$key");
  1021. }
  1022. // Delete old user variables.
  1023. variable_del('location_user_weight');
  1024. variable_del('location_user_collapsible');
  1025. variable_del('location_user_collapsed');
  1026. variable_del('location_user_fields');
  1027. }
  1028. /**
  1029. * Disabled due to some typos, moved to 6306.
  1030. */
  1031. function location_update_6305() {
  1032. return array();
  1033. }
  1034. /**
  1035. * Add per-location-field weights and defaults.
  1036. */
  1037. function location_update_6306() {
  1038. // Skip this update if it was already done on the 5.x side.
  1039. if (variable_get('location_update_5306_done', FALSE)) {
  1040. variable_del('location_update_5306_done');
  1041. return array();
  1042. }
  1043. $result = db_query("SELECT name FROM {variable} WHERE name LIKE 'location_settings_%'");
  1044. foreach ($result as $row) {
  1045. $var = variable_get($row->name, array());
  1046. $collect = $var['form']['fields'];
  1047. $var['form']['fields'] = array();
  1048. foreach ($collect as $k => $v) {
  1049. $var['form']['fields'][$k]['collect'] = $v;
  1050. }
  1051. // Country 3 has changed to 4 to make requirements code easier.
  1052. if (isset($var['form']['fields']['country']['collect']) && $var['form']['fields']['country']['collect'] == 3) {
  1053. $var['form']['fields']['country']['collect'] = 4;
  1054. }
  1055. // Weight and default values don't need to get set for now.
  1056. variable_set($row->name, $var);
  1057. }
  1058. }
  1059. /**
  1060. * Tell users about the new location_user module and enable it.
  1061. */
  1062. function location_update_6307() {
  1063. $message = t("Note: Location module has now split off user location support into a seperate module, called <em>User Locations</em>. It has been enabled for you. If you don't want user locations, visit the <a href='!url'>modules page</a> and disable it.", array('!url' => url('admin/modules')));
  1064. if (module_exists('location')) {
  1065. module_enable(array('location_user'));
  1066. }
  1067. else {
  1068. $message .= '<br />' . t("Note: Refusing to enable location_user.module, as location.module is not currently enabled.");
  1069. }
  1070. return $message;
  1071. }
  1072. /**
  1073. * Tell users about the new location_node module and enable it.
  1074. */
  1075. function location_update_6308() {
  1076. $message = t("Note: Location module has now split off node location support into a seperate module, called <em>Node Locations</em>. It has been enabled for you. If you don't want node locations, visit the <a href='!url'>modules page</a> and disable it.", array('!url' => url('admin/modules')));
  1077. if (module_exists('location')) {
  1078. module_enable(array('location_node'));
  1079. }
  1080. else {
  1081. $message .= '<br />' . t("Note: Refusing to enable location_node.module, as location.module is not currently enabled.");
  1082. }
  1083. return $message;
  1084. }
  1085. /**
  1086. * There has been a change in the options for the views distance/proximity filter.
  1087. * The old options need to be migrated into the new.
  1088. */
  1089. function location_update_6309() {
  1090. $updated_views = array();
  1091. if (module_exists('views')) {
  1092. $views = views_get_all_views();
  1093. foreach ($views as $view) {
  1094. $modified = FALSE;
  1095. // For each view check all filters of all displays for the distance field filter.
  1096. foreach ($view->display as $did => $display) {
  1097. if (isset($display->display_options['filters']) && !empty($display->display_options['filters'])) {
  1098. foreach ($display->display_options['filters'] as $fid => $filter) {
  1099. if ($filter['table'] == 'location' && $filter['field'] == 'distance') {
  1100. // Set the origin (new option) from the type (old option).
  1101. $origin = '';
  1102. switch ($filter['type']) {
  1103. case 'latlon':
  1104. $origin = 'static';
  1105. break;
  1106. case 'postal':
  1107. case 'postal_default':
  1108. case 'latlon_gmap':
  1109. $origin = $filter['type'];
  1110. break;
  1111. }
  1112. if ($origin) {
  1113. $view->display[$did]->display_options['filters'][$fid]['origin'] = $origin;
  1114. unset($view->display[$did]->display_options['filters'][$fid]['type']);
  1115. $modified = TRUE;
  1116. }
  1117. }
  1118. }
  1119. }
  1120. }
  1121. // Save the view if we changed any options on any diplays.
  1122. // Views caches are cleared during save so we don't have to do it.
  1123. if ($modified) {
  1124. $updated_views[] = $view->name;
  1125. $view->save();
  1126. }
  1127. }
  1128. }
  1129. if (!empty($updated_views)) {
  1130. return t("Note: The 'Form type' option for the 'Location: Distance / Proximity' filter in views has been changed and is now the 'Origin' option. The following views were using that setting and have been updated to use the new setting: %views.", array('%views' => implode(', ', $updated_views)));
  1131. }
  1132. }
  1133. /**
  1134. * Updates the ISO code for United Kingdom from 'uk' to 'gb' in the location
  1135. * table, the zipcodes table, and for any variable names and variable values
  1136. * where it is used.
  1137. */
  1138. function location_update_7301() {
  1139. db_update('location')
  1140. ->fields(array(
  1141. 'country' => 'gb',
  1142. ))
  1143. ->condition('country', 'uk')
  1144. ->execute();
  1145. db_update('zipcodes')
  1146. ->fields(array(
  1147. 'country' => 'gb',
  1148. ))
  1149. ->condition('country', 'uk')
  1150. ->execute();
  1151. $uk = variable_get('location_geocode_uk', '');
  1152. $gb = variable_get('location_geocode_gb', '');
  1153. if ($uk) {
  1154. variable_set('location_geocode_gb', $uk);
  1155. }
  1156. $uk = variable_get('location_map_link_uk', '');
  1157. $gb = variable_get('location_map_link_gb', '');
  1158. if ($uk) {
  1159. variable_set('location_map_link_gb', $uk);
  1160. }
  1161. cache_clear_all('*', 'cache_location', TRUE);
  1162. return;
  1163. }