Subversion Repositories svnkaklik

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
6 kaklik 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: upgrade.php,v $
9
// | last update   : $Date: 2005/01/08 23:56:59 $
10
// | last modifier : $Author: plg $
11
// | revision      : $Revision: 1.4 $
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('IN_UPGRADE', true);
29
define('PHPWG_ROOT_PATH', './');
30
 
31
include_once(PHPWG_ROOT_PATH.'include/functions.inc.php');
32
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
33
include(PHPWG_ROOT_PATH.'include/template.php');
34
 
35
include(PHPWG_ROOT_PATH.'include/mysql.inc.php');
36
// Is PhpWebGallery already installed ?
37
if (defined('PHPWG_INSTALLED'))
38
{
39
  $message = 'PhpWebGallery is already installed. In include/mysql.inc.php,
40
remove line
41
<pre style="background-color:lightgray">
42
define(\'PHPWG_INSTALLED\', true);
43
</pre>
44
if you want to upgrade';
45
  die($message);
46
}
47
 
48
include_once(PHPWG_ROOT_PATH.'include/constants.php');
49
define('PREFIX_TABLE', $prefixeTable);
50
 
51
$conf['show_queries'] = false;
52
 
53
// Database connection
54
mysql_connect( $cfgHote, $cfgUser, $cfgPassword )
55
or die ( "Could not connect to database server" );
56
mysql_select_db( $cfgBase )
57
or die ( "Could not connect to database" );
58
// +-----------------------------------------------------------------------+
59
// |                            tricky output                              |
60
// +-----------------------------------------------------------------------+
61
echo '<!-- This is an HTML comment given in order to make IE outputs';
62
echo ' the code.'."\n";
63
echo ' Indeed, IE doesn\'t start to send output until a limit';
64
echo ' of XXX bytes '."\n";
65
echo str_repeat( ' ', 80 )."\n";
66
echo str_repeat( ' ', 80 )."\n";
67
echo str_repeat( ' ', 80 )."\n";
68
echo '-->'."\n";
69
flush();
70
// +-----------------------------------------------------------------------+
71
// |                              functions                                |
72
// +-----------------------------------------------------------------------+
73
 
74
/**
75
 * loads an sql file and executes all queries
76
 *
77
 * Before executing a query, $replaced is... replaced by $replacing. This is
78
 * useful when the SQL file contains generic words. Drop table queries are
79
 * not executed.
80
 *
81
 * @param string filepath
82
 * @param string replaced
83
 * @param string replacing
84
 * @return void
85
 */
86
function execute_sqlfile($filepath, $replaced, $replacing)
87
{
88
  $sql_lines = file($filepath);
89
  $query = '';
90
  foreach ($sql_lines as $sql_line)
91
  {
92
    $sql_line = trim($sql_line);
93
    if (preg_match('/(^--|^$)/', $sql_line))
94
    {
95
      continue;
96
    }
97
    $query.= ' '.$sql_line;
98
    // if we reached the end of query, we execute it and reinitialize the
99
    // variable "query"
100
    if (preg_match('/;$/', $sql_line))
101
    {
102
      $query = trim($query);
103
      $query = str_replace($replaced, $replacing, $query);
104
      // we don't execute "DROP TABLE" queries
105
      if (!preg_match('/^DROP TABLE/i', $query))
106
      {
107
        mysql_query($query);
108
      }
109
      $query = '';
110
    }
111
  }
112
}
113
// +-----------------------------------------------------------------------+
114
// |                        template initialization                        |
115
// +-----------------------------------------------------------------------+
116
$template = setup_style('default');
117
$template->set_filenames(array('upgrade'=>'upgrade.tpl'));
118
$template->assign_vars(array('RELEASE'=>PHPWG_VERSION));
119
// +-----------------------------------------------------------------------+
120
// |                          versions upgradable                          |
121
// +-----------------------------------------------------------------------+
122
$versions = array();
123
$path = PHPWG_ROOT_PATH.'install';
124
if ($contents = opendir($path))
125
{
126
  while (($node = readdir($contents)) !== false)
127
  {
128
    if (is_file($path.'/'.$node)
129
        and preg_match('/^upgrade_(.*?)\.php$/', $node, $match))
130
    {
131
      array_push($versions, $match[1]);
132
    }
133
  }
134
}
135
natcasesort($versions);
136
// +-----------------------------------------------------------------------+
137
// |                            upgrade choice                             |
138
// +-----------------------------------------------------------------------+
139
if (!isset($_GET['version']))
140
{
141
  $template->assign_block_vars('choices', array());
142
  foreach ($versions as $version)
143
  {
144
    $template->assign_block_vars(
145
      'choices.choice',
146
      array(
147
        'URL' => PHPWG_ROOT_PATH.'upgrade.php?version='.$version,
148
        'VERSION' => $version
149
        ));
150
  }
151
}
152
// +-----------------------------------------------------------------------+
153
// |                            upgrade launch                             |
154
// +-----------------------------------------------------------------------+
155
else
156
{
157
  $upgrade_file = $path.'/upgrade_'.$_GET['version'].'.php';
158
  if (is_file($upgrade_file))
159
  {
160
    $page['upgrade_start'] = get_moment();
161
    include($upgrade_file);
162
    $page['upgrade_end'] = get_moment();
163
 
164
    $template->assign_block_vars(
165
      'upgrade',
166
      array(
167
        'VERSION' => $_GET['version'],
168
        'TOTAL_TIME' => get_elapsed_time($page['upgrade_start'],
169
                                         $page['upgrade_end']),
170
        'SQL_TIME' => number_format($page['queries_time'], 3, '.', ' ').' s',
171
        'NB_QUERIES' => $page['count_queries']
172
        ));
173
 
174
    if (!isset($infos))
175
    {
176
      $infos = array();
177
    }
178
    array_push(
179
      $infos,
180
      '[security] delete files "upgrade.php", "install.php" and "install"
181
directory');
182
 
183
    $template->assign_block_vars('upgrade.infos', array());
184
 
185
    foreach ($infos as $info)
186
    {
187
      $template->assign_block_vars('upgrade.infos.info',
188
                                   array('CONTENT' => $info));
189
    }
190
  }
191
  else
192
  {
193
    die('Hacking attempt');
194
  }
195
}
196
// +-----------------------------------------------------------------------+
197
// |                          sending html code                            |
198
// +-----------------------------------------------------------------------+
199
$template->pparse('upgrade');
200
?>