source: trunk/install/upgrade_1.3.0.php @ 14508

Last change on this file since 14508 was 12922, checked in by mistic100, 13 years ago

update Piwigo headers to 2012, last change before the expected (or not) apocalypse

  • Property svn:eol-style set to LF
File size: 3.5 KB
RevLine 
[1927]1<?php
2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[12922]5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
[2297]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// +-----------------------------------------------------------------------+
[1927]23
24
25/**
26 * Upgrade from 1.3.0 to 1.3.1
27 */
28
29if (!defined('PHPWG_ROOT_PATH'))
30{
31  die ('This page cannot be loaded directly, load upgrade.php');
32}
33else
34{
35  if (!defined('PHPWG_IN_UPGRADE') or !PHPWG_IN_UPGRADE)
36  {
37    die ('Hacking attempt!');
38  }
39}
40
41$queries = array(
42  "
43ALTER TABLE phpwebgallery_categories
44  ADD COLUMN uppercats varchar(255) NOT NULL default ''
45;",
46
47  "
48CREATE TABLE phpwebgallery_user_category (
49  user_id smallint(5) unsigned NOT NULL default '0'
50)
51;",
52
53  "
54ALTER TABLE phpwebgallery_categories
55  ADD INDEX id (id)
56;",
57
58  "
59ALTER TABLE phpwebgallery_categories
60  ADD INDEX id_uppercat (id_uppercat)
61;",
62
63  "
64ALTER TABLE phpwebgallery_image_category
65  ADD INDEX category_id (category_id)
66;",
67
68  "
69ALTER TABLE phpwebgallery_image_category
70  ADD INDEX image_id (image_id)
71;",
72  );
73
74foreach ($queries as $query)
75{
76  $query = str_replace('phpwebgallery_', PREFIX_TABLE, $query);
77  pwg_query($query);
78}
79// filling the new column categories.uppercats
80$id_uppercats = array();
81
82$query = '
83SELECT id, id_uppercat
84  FROM '.CATEGORIES_TABLE.'
85;';
86$result = pwg_query($query);
[4325]87while ($row = pwg_db_fetch_assoc($result))
[1927]88{
89  if (!isset($row['id_uppercat']) or $row['id_uppercat'] == '')
90  {
91    $row['id_uppercat'] = 'NULL';
92  }
93  $id_uppercats[$row['id']] = $row['id_uppercat'];
94}
95
96$datas = array();
97
98foreach (array_keys($id_uppercats) as $id)
99{
100  $data = array();
101  $data['id'] = $id;
102  $uppercats = array();
103 
104  array_push($uppercats, $id);
105  while (isset($id_uppercats[$id]) and $id_uppercats[$id] != 'NULL')
106  {
107    array_push($uppercats, $id_uppercats[$id]);
108    $id = $id_uppercats[$id];
109  }
110  $data['uppercats'] = implode(',', array_reverse($uppercats));
111
112  array_push($datas, $data);
113}
114
115mass_updates(
116  CATEGORIES_TABLE,
117  array(
118    'primary' => array('id'),
119    'update' => array('uppercats')
120    ),
121  $datas
122  );
123
124// now we upgrade from 1.3.1 to 1.6.0
125include_once(PHPWG_ROOT_PATH.'install/upgrade_1.3.1.php');
126?>
Note: See TracBrowser for help on using the repository browser.