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

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

Modification: new header on PHP files, PhpWebGallery renamed Piwigo.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 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// +-----------------------------------------------------------------------+
24// | PhpWebGallery - a PHP based picture gallery                           |
25// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
26// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
27// +-----------------------------------------------------------------------+
28// | file          : $Id: upgrade_1.3.0.php 2297 2008-04-04 22:57:23Z plg $
29// | last update   : $Date: 2008-04-04 22:57:23 +0000 (Fri, 04 Apr 2008) $
30// | last modifier : $Author: plg $
31// | revision      : $Revision: 2297 $
32// +-----------------------------------------------------------------------+
33// | This program is free software; you can redistribute it and/or modify  |
34// | it under the terms of the GNU General Public License as published by  |
35// | the Free Software Foundation                                          |
36// |                                                                       |
37// | This program is distributed in the hope that it will be useful, but   |
38// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
39// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
40// | General Public License for more details.                              |
41// |                                                                       |
42// | You should have received a copy of the GNU General Public License     |
43// | along with this program; if not, write to the Free Software           |
44// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
45// | USA.                                                                  |
46// +-----------------------------------------------------------------------+
47
48
49/**
50 * Upgrade from 1.3.0 to 1.3.1
51 */
52
53if (!defined('PHPWG_ROOT_PATH'))
54{
55  die ('This page cannot be loaded directly, load upgrade.php');
56}
57else
58{
59  if (!defined('PHPWG_IN_UPGRADE') or !PHPWG_IN_UPGRADE)
60  {
61    die ('Hacking attempt!');
62  }
63}
64
65$queries = array(
66  "
67ALTER TABLE phpwebgallery_categories
68  ADD COLUMN uppercats varchar(255) NOT NULL default ''
69;",
70
71  "
72CREATE TABLE phpwebgallery_user_category (
73  user_id smallint(5) unsigned NOT NULL default '0'
74)
75;",
76
77  "
78ALTER TABLE phpwebgallery_categories
79  ADD INDEX id (id)
80;",
81
82  "
83ALTER TABLE phpwebgallery_categories
84  ADD INDEX id_uppercat (id_uppercat)
85;",
86
87  "
88ALTER TABLE phpwebgallery_image_category
89  ADD INDEX category_id (category_id)
90;",
91
92  "
93ALTER TABLE phpwebgallery_image_category
94  ADD INDEX image_id (image_id)
95;",
96  );
97
98foreach ($queries as $query)
99{
100  $query = str_replace('phpwebgallery_', PREFIX_TABLE, $query);
101  pwg_query($query);
102}
103// filling the new column categories.uppercats
104$id_uppercats = array();
105
106$query = '
107SELECT id, id_uppercat
108  FROM '.CATEGORIES_TABLE.'
109;';
110$result = pwg_query($query);
111while ($row = mysql_fetch_array($result))
112{
113  if (!isset($row['id_uppercat']) or $row['id_uppercat'] == '')
114  {
115    $row['id_uppercat'] = 'NULL';
116  }
117  $id_uppercats[$row['id']] = $row['id_uppercat'];
118}
119
120$datas = array();
121
122foreach (array_keys($id_uppercats) as $id)
123{
124  $data = array();
125  $data['id'] = $id;
126  $uppercats = array();
127 
128  array_push($uppercats, $id);
129  while (isset($id_uppercats[$id]) and $id_uppercats[$id] != 'NULL')
130  {
131    array_push($uppercats, $id_uppercats[$id]);
132    $id = $id_uppercats[$id];
133  }
134  $data['uppercats'] = implode(',', array_reverse($uppercats));
135
136  array_push($datas, $data);
137}
138
139mass_updates(
140  CATEGORIES_TABLE,
141  array(
142    'primary' => array('id'),
143    'update' => array('uppercats')
144    ),
145  $datas
146  );
147
148// now we upgrade from 1.3.1 to 1.6.0
149include_once(PHPWG_ROOT_PATH.'install/upgrade_1.3.1.php');
150?>
Note: See TracBrowser for help on using the repository browser.