source: trunk/install/db/139-database.php @ 25802

Last change on this file since 25802 was 25802, checked in by mistic100, 10 years ago

feature 3009: Don't delete 'lat' and 'lon' fields in case users try to delete an old plugin using them (SQL crash)

File size: 2.3 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2013 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24if (!defined('PHPWG_ROOT_PATH'))
25{
26  die('Hacking attempt!');
27}
28
29$upgrade_description = 'add "latitude" and "longitude" fields';
30
31// add fields
32$query = '
33ALTER TABLE '. IMAGES_TABLE .'
34  ADD `latitude` DOUBLE(8, 6) DEFAULT NULL,
35  ADD `longitude` DOUBLE(9, 6) DEFAULT NULL
36;';
37pwg_query($query);
38
39// add index
40$query = '
41ALTER TABLE '. IMAGES_TABLE .'
42  ADD INDEX `images_i6` (`latitude`)
43;';
44pwg_query($query);
45
46// search for old "lat" field
47$query = 'SHOW COLUMNS FROM '. IMAGES_TABLE .' LIKE "lat";';
48
49if (pwg_db_num_rows(pwg_query($query)))
50{
51  // duplicate non-null values
52  $query = '
53UPDATE '. IMAGES_TABLE .'
54  SET latitude = lat,
55    longitude = lon
56  WHERE lat != NULL
57    AND lon != NULL
58;';
59  pwg_query($query);
60}
61
62echo "\n".$upgrade_description."\n";
63
64?>
Note: See TracBrowser for help on using the repository browser.