source: branches/1.5/upgrade.php @ 3631

Last change on this file since 3631 was 870, checked in by plg, 19 years ago
  • update: upgrade from 1.4.0 or 1.4.1. Upgrade from 1.3.x is not available anymore.
  • update: README files updated for very near branch 1.5 :-)
  • new: file tools/config_local.inc.php as example for optional include/config_local.inc.php
  • bug fixed: configuration parameter show_picture_name_on_title was useless
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.5 KB
Line 
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-09-20 22:04:57 +0000 (Tue, 20 Sep 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 870 $
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
28define('PHPWG_ROOT_PATH', './');
29
30include_once(PHPWG_ROOT_PATH.'include/functions.inc.php');
31include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
32include(PHPWG_ROOT_PATH.'include/template.php');
33
34include(PHPWG_ROOT_PATH.'include/mysql.inc.php');
35// Is PhpWebGallery already installed ?
36if (!defined('PHPWG_IN_UPGRADE') or !PHPWG_IN_UPGRADE)
37{
38  $message = 'PhpWebGallery is not in upgrade mode. In include/mysql.inc.php,
39insert line
40<pre style="background-color:lightgray">
41define(\'PHPWG_IN_UPGRADE\', true);
42</pre>
43if 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
50include_once(PHPWG_ROOT_PATH.'include/constants.php');
51define('PREFIX_TABLE', $prefixeTable);
52
53$conf['show_queries'] = false;
54
55// Database connection
56mysql_connect( $cfgHote, $cfgUser, $cfgPassword )
57or die ( "Could not connect to database server" );
58mysql_select_db( $cfgBase )
59or die ( "Could not connect to database" );
60// +-----------------------------------------------------------------------+
61// |                            tricky output                              |
62// +-----------------------------------------------------------------------+
63echo '<!-- This is an HTML comment given in order to make IE outputs';
64echo ' the code.'."\n";
65echo ' Indeed, IE doesn\'t start to send output until a limit';
66echo ' of XXX bytes '."\n";
67echo str_repeat( ' ', 80 )."\n";
68echo str_repeat( ' ', 80 )."\n";
69echo str_repeat( ' ', 80 )."\n";
70echo '-->'."\n";
71flush();
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 */
88function 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';
128if ($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}
139natcasesort($versions);
140// +-----------------------------------------------------------------------+
141// |                            upgrade choice                             |
142// +-----------------------------------------------------------------------+
143if (!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// +-----------------------------------------------------------------------+
159else
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"
185directory'
186      );
187
188    array_push(
189      $infos,
190      'in include/mysql.inc.php, remove
191<pre style="background-color:lightgray">
192define(\'PHPWG_IN_UPGRADE\', true);
193</pre>'
194      );
195   
196    $template->assign_block_vars('upgrade.infos', array());
197   
198    foreach ($infos as $info)
199    {
200      $template->assign_block_vars('upgrade.infos.info',
201                                   array('CONTENT' => $info));
202    }
203  }
204  else
205  {
206    die('Hacking attempt');
207  }
208}
209// +-----------------------------------------------------------------------+
210// |                          sending html code                            |
211// +-----------------------------------------------------------------------+
212$template->pparse('upgrade');
213?>
Note: See TracBrowser for help on using the repository browser.