1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based photo gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2014 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 | |
---|
24 | if (!defined('PHPWG_ROOT_PATH')) |
---|
25 | { |
---|
26 | die ('This page cannot be loaded directly, load upgrade.php'); |
---|
27 | } |
---|
28 | else |
---|
29 | { |
---|
30 | if (!defined('PHPWG_IN_UPGRADE') or !PHPWG_IN_UPGRADE) |
---|
31 | { |
---|
32 | die ('Hacking attempt!'); |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | // +-----------------------------------------------------------------------+ |
---|
37 | // | Fill upgrade table without applying upgrade | |
---|
38 | // +-----------------------------------------------------------------------+ |
---|
39 | |
---|
40 | // retrieve already applied upgrades |
---|
41 | $query = ' |
---|
42 | SELECT id |
---|
43 | FROM '.PREFIX_TABLE.'upgrade |
---|
44 | ;'; |
---|
45 | $applied = array_from_query($query, 'id'); |
---|
46 | |
---|
47 | // retrieve existing upgrades |
---|
48 | $existing = get_available_upgrade_ids(); |
---|
49 | |
---|
50 | // which upgrades need to be applied? |
---|
51 | $to_apply = array_diff($existing, $applied); |
---|
52 | $inserts = array(); |
---|
53 | foreach ($to_apply as $upgrade_id) |
---|
54 | { |
---|
55 | if ($upgrade_id >= 112) // TODO change on each release |
---|
56 | { |
---|
57 | break; |
---|
58 | } |
---|
59 | |
---|
60 | array_push( |
---|
61 | $inserts, |
---|
62 | array( |
---|
63 | 'id' => $upgrade_id, |
---|
64 | 'applied' => CURRENT_DATE, |
---|
65 | 'description' => '[migration from 2.3.0 to '.PHPWG_VERSION.'] not applied', |
---|
66 | ) |
---|
67 | ); |
---|
68 | } |
---|
69 | |
---|
70 | if (!empty($inserts)) |
---|
71 | { |
---|
72 | mass_inserts( |
---|
73 | '`'.UPGRADE_TABLE.'`', |
---|
74 | array_keys($inserts[0]), |
---|
75 | $inserts |
---|
76 | ); |
---|
77 | } |
---|
78 | |
---|
79 | // +-----------------------------------------------------------------------+ |
---|
80 | // | Perform upgrades | |
---|
81 | // +-----------------------------------------------------------------------+ |
---|
82 | |
---|
83 | ob_start(); |
---|
84 | echo '<pre>'; |
---|
85 | |
---|
86 | for ($upgrade_id = 112; $upgrade_id <= 127; $upgrade_id++) // TODO change on each release |
---|
87 | { |
---|
88 | if (!file_exists(UPGRADES_PATH.'/'.$upgrade_id.'-database.php')) |
---|
89 | { |
---|
90 | continue; |
---|
91 | } |
---|
92 | |
---|
93 | // maybe the upgrade task has already been applied in a previous and |
---|
94 | // incomplete upgrade |
---|
95 | if (in_array($upgrade_id, $applied)) |
---|
96 | { |
---|
97 | continue; |
---|
98 | } |
---|
99 | |
---|
100 | unset($upgrade_description); |
---|
101 | |
---|
102 | echo "\n\n"; |
---|
103 | echo '=== upgrade '.$upgrade_id."\n"; |
---|
104 | |
---|
105 | // include & execute upgrade script. Each upgrade script must contain |
---|
106 | // $upgrade_description variable which describe briefly what the upgrade |
---|
107 | // script does. |
---|
108 | include(UPGRADES_PATH.'/'.$upgrade_id.'-database.php'); |
---|
109 | |
---|
110 | // notify upgrade |
---|
111 | $query = ' |
---|
112 | INSERT INTO `'.PREFIX_TABLE.'upgrade` |
---|
113 | (id, applied, description) |
---|
114 | VALUES |
---|
115 | (\''.$upgrade_id.'\', NOW(), \'[migration from 2.3.0 to '.PHPWG_VERSION.'] '.$upgrade_description.'\') |
---|
116 | ;'; |
---|
117 | pwg_query($query); |
---|
118 | } |
---|
119 | |
---|
120 | echo '</pre>'; |
---|
121 | ob_end_clean(); |
---|
122 | |
---|
123 | // now we upgrade from 2.4.0 |
---|
124 | include_once(PHPWG_ROOT_PATH.'install/upgrade_2.4.0.php'); |
---|
125 | ?> |
---|