source: trunk/upgrade.php @ 1134

Last change on this file since 1134 was 1075, checked in by rub, 18 years ago

Step 4 improvement issue 0000301:

o Correction lock categories and is_admin (functions with parameters now)
o Cannot use check_status with upgrade.php and upgrade_feed.php => New function check_upgrade use in upgrade*.php (new functionality for upgrade_feed.php)
o upgrade_feed.php is showed only for administrator user

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.6 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-2006 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-03-10 20:17:18 +0000 (Fri, 10 Mar 2006) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1075 $
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
36// +-----------------------------------------------------------------------+
37// | Check Access and exit when it is not ok                               |
38// +-----------------------------------------------------------------------+
39check_upgrade();
40
41// concerning upgrade, we use the default users table
42$conf['users_table'] = $prefixeTable.'users';
43
44include_once(PHPWG_ROOT_PATH.'include/constants.php');
45define('PREFIX_TABLE', $prefixeTable);
46
47$conf['show_queries'] = false;
48
49// Database connection
50mysql_connect( $cfgHote, $cfgUser, $cfgPassword )
51or die ( "Could not connect to database server" );
52mysql_select_db( $cfgBase )
53or die ( "Could not connect to database" );
54// +-----------------------------------------------------------------------+
55// |                            tricky output                              |
56// +-----------------------------------------------------------------------+
57echo '<!-- This is an HTML comment given in order to make IE outputs';
58echo ' the code.'."\n";
59echo ' Indeed, IE doesn\'t start to send output until a limit';
60echo ' of XXX bytes '."\n";
61echo str_repeat( ' ', 80 )."\n";
62echo str_repeat( ' ', 80 )."\n";
63echo str_repeat( ' ', 80 )."\n";
64echo '-->'."\n";
65flush();
66// +-----------------------------------------------------------------------+
67// |                              functions                                |
68// +-----------------------------------------------------------------------+
69
70/**
71 * loads an sql file and executes all queries
72 *
73 * Before executing a query, $replaced is... replaced by $replacing. This is
74 * useful when the SQL file contains generic words. Drop table queries are
75 * not executed.
76 *
77 * @param string filepath
78 * @param string replaced
79 * @param string replacing
80 * @return void
81 */
82function execute_sqlfile($filepath, $replaced, $replacing)
83{
84  $sql_lines = file($filepath);
85  $query = '';
86  foreach ($sql_lines as $sql_line)
87  {
88    $sql_line = trim($sql_line);
89    if (preg_match('/(^--|^$)/', $sql_line))
90    {
91      continue;
92    }
93    $query.= ' '.$sql_line;
94    // if we reached the end of query, we execute it and reinitialize the
95    // variable "query"
96    if (preg_match('/;$/', $sql_line))
97    {
98      $query = trim($query);
99      $query = str_replace($replaced, $replacing, $query);
100      // we don't execute "DROP TABLE" queries
101      if (!preg_match('/^DROP TABLE/i', $query))
102      {
103        mysql_query($query);
104      }
105      $query = '';
106    }
107  }
108}
109// +-----------------------------------------------------------------------+
110// |                        template initialization                        |
111// +-----------------------------------------------------------------------+
112
113$template = new Template(PHPWG_ROOT_PATH.'template/yoga');
114$template->set_filenames(array('upgrade'=>'upgrade.tpl'));
115$template->assign_vars(array('RELEASE'=>PHPWG_VERSION));
116
117// +-----------------------------------------------------------------------+
118// |                          versions upgradable                          |
119// +-----------------------------------------------------------------------+
120$versions = array();
121$path = PHPWG_ROOT_PATH.'install';
122if ($contents = opendir($path))
123{
124  while (($node = readdir($contents)) !== false)
125  {
126    if (is_file($path.'/'.$node)
127        and preg_match('/^upgrade_(.*?)\.php$/', $node, $match))
128    {
129      array_push($versions, $match[1]);
130    }
131  }
132}
133natcasesort($versions);
134// +-----------------------------------------------------------------------+
135// |                            upgrade choice                             |
136// +-----------------------------------------------------------------------+
137if (!isset($_GET['version']))
138{
139  $template->assign_block_vars('choices', array());
140  foreach ($versions as $version)
141  {
142    $template->assign_block_vars(
143      'choices.choice',
144      array(
145        'URL' => PHPWG_ROOT_PATH.'upgrade.php?version='.$version,
146        'VERSION' => $version
147        ));
148  }
149}
150// +-----------------------------------------------------------------------+
151// |                            upgrade launch                             |
152// +-----------------------------------------------------------------------+
153else
154{
155  $upgrade_file = $path.'/upgrade_'.$_GET['version'].'.php';
156  if (is_file($upgrade_file))
157  {
158    $page['upgrade_start'] = get_moment();
159    include($upgrade_file);
160    $page['upgrade_end'] = get_moment();
161
162    $template->assign_block_vars(
163      'upgrade',
164      array(
165        'VERSION' => $_GET['version'],
166        'TOTAL_TIME' => get_elapsed_time($page['upgrade_start'],
167                                         $page['upgrade_end']),
168        'SQL_TIME' => number_format($page['queries_time'], 3, '.', ' ').' s',
169        'NB_QUERIES' => $page['count_queries']
170        ));
171
172    if (!isset($infos))
173    {
174      $infos = array();
175    }
176    array_push(
177      $infos,
178      '[security] delete files "upgrade.php", "install.php" and "install"
179directory'
180      );
181
182    array_push(
183      $infos,
184      'in include/mysql.inc.php, remove
185<pre style="background-color:lightgray">
186define(\'PHPWG_IN_UPGRADE\', true);
187</pre>'
188      );
189
190    array_push(
191      $infos,
192      'Perform a maintenance check in [Administration>General>Maintenance]
193if you encounter any problem.'
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.