1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
5 | // | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2005-12-03 23:24:17 +0000 (Sat, 03 Dec 2005) $ |
---|
10 | // | last modifier : $Author: plg $ |
---|
11 | // | revision : $Revision: 971 $ |
---|
12 | // +-----------------------------------------------------------------------+ |
---|
13 | // | This program is free software; you can redistribute it and/or modify | |
---|
14 | // | it under the terms of the GNU General Public License as published by | |
---|
15 | // | the Free Software Foundation | |
---|
16 | // | | |
---|
17 | // | This program is distributed in the hope that it will be useful, but | |
---|
18 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
19 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
20 | // | General Public License for more details. | |
---|
21 | // | | |
---|
22 | // | You should have received a copy of the GNU General Public License | |
---|
23 | // | along with this program; if not, write to the Free Software | |
---|
24 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
25 | // | USA. | |
---|
26 | // +-----------------------------------------------------------------------+ |
---|
27 | |
---|
28 | define('PHPWG_ROOT_PATH', './'); |
---|
29 | |
---|
30 | include_once(PHPWG_ROOT_PATH.'include/functions.inc.php'); |
---|
31 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
32 | include(PHPWG_ROOT_PATH.'include/template.php'); |
---|
33 | |
---|
34 | include(PHPWG_ROOT_PATH.'include/mysql.inc.php'); |
---|
35 | // Is PhpWebGallery already installed ? |
---|
36 | if (!defined('PHPWG_IN_UPGRADE') or !PHPWG_IN_UPGRADE) |
---|
37 | { |
---|
38 | $message = 'PhpWebGallery is not in upgrade mode. In include/mysql.inc.php, |
---|
39 | insert line |
---|
40 | <pre style="background-color:lightgray"> |
---|
41 | define(\'PHPWG_IN_UPGRADE\', true); |
---|
42 | </pre> |
---|
43 | if you want to upgrade'; |
---|
44 | die($message); |
---|
45 | } |
---|
46 | |
---|
47 | // concerning upgrade, we use the default users table |
---|
48 | $conf['users_table'] = $prefixeTable.'users'; |
---|
49 | |
---|
50 | include_once(PHPWG_ROOT_PATH.'include/constants.php'); |
---|
51 | define('PREFIX_TABLE', $prefixeTable); |
---|
52 | |
---|
53 | $conf['show_queries'] = false; |
---|
54 | |
---|
55 | // Database connection |
---|
56 | mysql_connect( $cfgHote, $cfgUser, $cfgPassword ) |
---|
57 | or die ( "Could not connect to database server" ); |
---|
58 | mysql_select_db( $cfgBase ) |
---|
59 | or die ( "Could not connect to database" ); |
---|
60 | // +-----------------------------------------------------------------------+ |
---|
61 | // | tricky output | |
---|
62 | // +-----------------------------------------------------------------------+ |
---|
63 | echo '<!-- This is an HTML comment given in order to make IE outputs'; |
---|
64 | echo ' the code.'."\n"; |
---|
65 | echo ' Indeed, IE doesn\'t start to send output until a limit'; |
---|
66 | echo ' of XXX bytes '."\n"; |
---|
67 | echo str_repeat( ' ', 80 )."\n"; |
---|
68 | echo str_repeat( ' ', 80 )."\n"; |
---|
69 | echo str_repeat( ' ', 80 )."\n"; |
---|
70 | echo '-->'."\n"; |
---|
71 | flush(); |
---|
72 | // +-----------------------------------------------------------------------+ |
---|
73 | // | functions | |
---|
74 | // +-----------------------------------------------------------------------+ |
---|
75 | |
---|
76 | /** |
---|
77 | * loads an sql file and executes all queries |
---|
78 | * |
---|
79 | * Before executing a query, $replaced is... replaced by $replacing. This is |
---|
80 | * useful when the SQL file contains generic words. Drop table queries are |
---|
81 | * not executed. |
---|
82 | * |
---|
83 | * @param string filepath |
---|
84 | * @param string replaced |
---|
85 | * @param string replacing |
---|
86 | * @return void |
---|
87 | */ |
---|
88 | function execute_sqlfile($filepath, $replaced, $replacing) |
---|
89 | { |
---|
90 | $sql_lines = file($filepath); |
---|
91 | $query = ''; |
---|
92 | foreach ($sql_lines as $sql_line) |
---|
93 | { |
---|
94 | $sql_line = trim($sql_line); |
---|
95 | if (preg_match('/(^--|^$)/', $sql_line)) |
---|
96 | { |
---|
97 | continue; |
---|
98 | } |
---|
99 | $query.= ' '.$sql_line; |
---|
100 | // if we reached the end of query, we execute it and reinitialize the |
---|
101 | // variable "query" |
---|
102 | if (preg_match('/;$/', $sql_line)) |
---|
103 | { |
---|
104 | $query = trim($query); |
---|
105 | $query = str_replace($replaced, $replacing, $query); |
---|
106 | // we don't execute "DROP TABLE" queries |
---|
107 | if (!preg_match('/^DROP TABLE/i', $query)) |
---|
108 | { |
---|
109 | mysql_query($query); |
---|
110 | } |
---|
111 | $query = ''; |
---|
112 | } |
---|
113 | } |
---|
114 | } |
---|
115 | // +-----------------------------------------------------------------------+ |
---|
116 | // | template initialization | |
---|
117 | // +-----------------------------------------------------------------------+ |
---|
118 | |
---|
119 | $template = new Template(PHPWG_ROOT_PATH.'template/yoga'); |
---|
120 | $template->set_filenames(array('upgrade'=>'upgrade.tpl')); |
---|
121 | $template->assign_vars(array('RELEASE'=>PHPWG_VERSION)); |
---|
122 | |
---|
123 | // +-----------------------------------------------------------------------+ |
---|
124 | // | versions upgradable | |
---|
125 | // +-----------------------------------------------------------------------+ |
---|
126 | $versions = array(); |
---|
127 | $path = PHPWG_ROOT_PATH.'install'; |
---|
128 | if ($contents = opendir($path)) |
---|
129 | { |
---|
130 | while (($node = readdir($contents)) !== false) |
---|
131 | { |
---|
132 | if (is_file($path.'/'.$node) |
---|
133 | and preg_match('/^upgrade_(.*?)\.php$/', $node, $match)) |
---|
134 | { |
---|
135 | array_push($versions, $match[1]); |
---|
136 | } |
---|
137 | } |
---|
138 | } |
---|
139 | natcasesort($versions); |
---|
140 | // +-----------------------------------------------------------------------+ |
---|
141 | // | upgrade choice | |
---|
142 | // +-----------------------------------------------------------------------+ |
---|
143 | if (!isset($_GET['version'])) |
---|
144 | { |
---|
145 | $template->assign_block_vars('choices', array()); |
---|
146 | foreach ($versions as $version) |
---|
147 | { |
---|
148 | $template->assign_block_vars( |
---|
149 | 'choices.choice', |
---|
150 | array( |
---|
151 | 'URL' => PHPWG_ROOT_PATH.'upgrade.php?version='.$version, |
---|
152 | 'VERSION' => $version |
---|
153 | )); |
---|
154 | } |
---|
155 | } |
---|
156 | // +-----------------------------------------------------------------------+ |
---|
157 | // | upgrade launch | |
---|
158 | // +-----------------------------------------------------------------------+ |
---|
159 | else |
---|
160 | { |
---|
161 | $upgrade_file = $path.'/upgrade_'.$_GET['version'].'.php'; |
---|
162 | if (is_file($upgrade_file)) |
---|
163 | { |
---|
164 | $page['upgrade_start'] = get_moment(); |
---|
165 | include($upgrade_file); |
---|
166 | $page['upgrade_end'] = get_moment(); |
---|
167 | |
---|
168 | $template->assign_block_vars( |
---|
169 | 'upgrade', |
---|
170 | array( |
---|
171 | 'VERSION' => $_GET['version'], |
---|
172 | 'TOTAL_TIME' => get_elapsed_time($page['upgrade_start'], |
---|
173 | $page['upgrade_end']), |
---|
174 | 'SQL_TIME' => number_format($page['queries_time'], 3, '.', ' ').' s', |
---|
175 | 'NB_QUERIES' => $page['count_queries'] |
---|
176 | )); |
---|
177 | |
---|
178 | if (!isset($infos)) |
---|
179 | { |
---|
180 | $infos = array(); |
---|
181 | } |
---|
182 | array_push( |
---|
183 | $infos, |
---|
184 | '[security] delete files "upgrade.php", "install.php" and "install" |
---|
185 | directory' |
---|
186 | ); |
---|
187 | |
---|
188 | array_push( |
---|
189 | $infos, |
---|
190 | 'in include/mysql.inc.php, remove |
---|
191 | <pre style="background-color:lightgray"> |
---|
192 | define(\'PHPWG_IN_UPGRADE\', true); |
---|
193 | </pre>' |
---|
194 | ); |
---|
195 | |
---|
196 | array_push( |
---|
197 | $infos, |
---|
198 | 'Perform a maintenance check in [Administration>General>Maintenance] |
---|
199 | if you encounter any problem.' |
---|
200 | ); |
---|
201 | |
---|
202 | $template->assign_block_vars('upgrade.infos', array()); |
---|
203 | |
---|
204 | foreach ($infos as $info) |
---|
205 | { |
---|
206 | $template->assign_block_vars('upgrade.infos.info', |
---|
207 | array('CONTENT' => $info)); |
---|
208 | } |
---|
209 | } |
---|
210 | else |
---|
211 | { |
---|
212 | die('Hacking attempt'); |
---|
213 | } |
---|
214 | } |
---|
215 | // +-----------------------------------------------------------------------+ |
---|
216 | // | sending html code | |
---|
217 | // +-----------------------------------------------------------------------+ |
---|
218 | $template->pparse('upgrade'); |
---|
219 | ?> |
---|