1<?php
2// +-----------------------------------------------------------------------+
3// | This file is part of Piwigo.                                          |
4// |                                                                       |
5// | For copyright and license information, please view the COPYING.txt    |
6// | file that was distributed with this source code.                      |
7// +-----------------------------------------------------------------------+
8
9if (!defined('PHPWG_ROOT_PATH'))
10{
11  die ('This page cannot be loaded directly, load upgrade.php');
12}
13else
14{
15  if (!defined('PHPWG_IN_UPGRADE') or !PHPWG_IN_UPGRADE)
16  {
17    die ('Hacking attempt!');
18  }
19}
20
21// +-----------------------------------------------------------------------+
22// |             Fill upgrade table without applying upgrade               |
23// +-----------------------------------------------------------------------+
24
25// retrieve already applied upgrades
26$query = '
27SELECT id
28  FROM '.PREFIX_TABLE.'upgrade
29;';
30$applied = array_from_query($query, 'id');
31
32// retrieve existing upgrades
33$existing = get_available_upgrade_ids();
34
35// which upgrades need to be applied?
36$to_apply = array_diff($existing, $applied);
37$inserts = array();
38foreach ($to_apply as $upgrade_id)
39{
40  if ($upgrade_id > 60)
41  {
42    break;
43  }
44
45  array_push(
46    $inserts,
47    array(
48      'id' => $upgrade_id,
49      'applied' => CURRENT_DATE,
50      'description' => '[migration from 1.7.0 to '.PHPWG_VERSION.'] not applied',
51      )
52    );
53}
54
55if (!empty($inserts))
56{
57  mass_inserts(
58    '`'.UPGRADE_TABLE.'`',
59    array_keys($inserts[0]),
60    $inserts
61    );
62}
63
64// +-----------------------------------------------------------------------+
65// |                          Perform upgrades                             |
66// +-----------------------------------------------------------------------+
67
68ob_start();
69echo '<pre>';
70
71for ($upgrade_id = 61; $upgrade_id <= 79; $upgrade_id++)
72{
73  if (!file_exists(UPGRADES_PATH.'/'.$upgrade_id.'-database.php'))
74  {
75    break;
76  }
77
78  unset($upgrade_description);
79
80  echo "\n\n";
81  echo '=== upgrade '.$upgrade_id."\n";
82
83  // include & execute upgrade script. Each upgrade script must contain
84  // $upgrade_description variable which describe briefly what the upgrade
85  // script does.
86  include(UPGRADES_PATH.'/'.$upgrade_id.'-database.php');
87
88  // notify upgrade
89  $query = '
90INSERT INTO `'.PREFIX_TABLE.'upgrade`
91  (id, applied, description)
92  VALUES
93  (\''.$upgrade_id.'\', NOW(), \'[migration from 1.7.0 to '.PHPWG_VERSION.'] '.$upgrade_description.'\')
94;';
95  pwg_query($query);
96}
97
98echo '</pre>';
99ob_end_clean();
100
101// now we upgrade from 2.0.0
102include_once(PHPWG_ROOT_PATH.'install/upgrade_2.0.0.php');
103?>
104