source: trunk/install/upgrade_1.7.0.php @ 2768

Last change on this file since 2768 was 2768, checked in by plg, 16 years ago

merge -c2754 from branch 2.0 to trunk

new: upgrade script from 1.7.0. Instead of previous upgrade scripts, I call
directly the "unit" upgrades from 61 to current. Previous upgrades not in
the database are inserted but not applied (and have an explicit description
saying so).

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