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$ |
---|
9 | // | last update : $Date: 2005-01-08 00:10:51 +0100 (sam, 08 jan 2005) $ |
---|
10 | // | last modifier : $Author: plg $ |
---|
11 | // | revision : $Revision: 675 $ |
---|
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 | |
---|
29 | /** |
---|
30 | * Upgrade from 1.3.0 to 1.3.1 |
---|
31 | */ |
---|
32 | |
---|
33 | if (!defined('PHPWG_ROOT_PATH')) |
---|
34 | { |
---|
35 | die ('This page cannot be loaded directly, load upgrade.php'); |
---|
36 | } |
---|
37 | else |
---|
38 | { |
---|
39 | if (!defined('PHPWG_IN_UPGRADE') or !PHPWG_IN_UPGRADE) |
---|
40 | { |
---|
41 | die ('Hacking attempt!'); |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | $queries = array( |
---|
46 | " |
---|
47 | ALTER TABLE phpwebgallery_categories |
---|
48 | ADD COLUMN uppercats varchar(255) NOT NULL default '' |
---|
49 | ;", |
---|
50 | |
---|
51 | " |
---|
52 | CREATE TABLE phpwebgallery_user_category ( |
---|
53 | user_id smallint(5) unsigned NOT NULL default '0' |
---|
54 | ) |
---|
55 | ;", |
---|
56 | |
---|
57 | " |
---|
58 | ALTER TABLE phpwebgallery_categories |
---|
59 | ADD INDEX id (id) |
---|
60 | ;", |
---|
61 | |
---|
62 | " |
---|
63 | ALTER TABLE phpwebgallery_categories |
---|
64 | ADD INDEX id_uppercat (id_uppercat) |
---|
65 | ;", |
---|
66 | |
---|
67 | " |
---|
68 | ALTER TABLE phpwebgallery_image_category |
---|
69 | ADD INDEX category_id (category_id) |
---|
70 | ;", |
---|
71 | |
---|
72 | " |
---|
73 | ALTER TABLE phpwebgallery_image_category |
---|
74 | ADD INDEX image_id (image_id) |
---|
75 | ;", |
---|
76 | ); |
---|
77 | |
---|
78 | foreach ($queries as $query) |
---|
79 | { |
---|
80 | $query = str_replace('phpwebgallery_', PREFIX_TABLE, $query); |
---|
81 | pwg_query($query); |
---|
82 | } |
---|
83 | // filling the new column categories.uppercats |
---|
84 | $id_uppercats = array(); |
---|
85 | |
---|
86 | $query = ' |
---|
87 | SELECT id, id_uppercat |
---|
88 | FROM '.CATEGORIES_TABLE.' |
---|
89 | ;'; |
---|
90 | $result = pwg_query($query); |
---|
91 | while ($row = mysql_fetch_array($result)) |
---|
92 | { |
---|
93 | if (!isset($row['id_uppercat']) or $row['id_uppercat'] == '') |
---|
94 | { |
---|
95 | $row['id_uppercat'] = 'NULL'; |
---|
96 | } |
---|
97 | $id_uppercats[$row['id']] = $row['id_uppercat']; |
---|
98 | } |
---|
99 | |
---|
100 | $datas = array(); |
---|
101 | |
---|
102 | foreach (array_keys($id_uppercats) as $id) |
---|
103 | { |
---|
104 | $data = array(); |
---|
105 | $data['id'] = $id; |
---|
106 | $uppercats = array(); |
---|
107 | |
---|
108 | array_push($uppercats, $id); |
---|
109 | while (isset($id_uppercats[$id]) and $id_uppercats[$id] != 'NULL') |
---|
110 | { |
---|
111 | array_push($uppercats, $id_uppercats[$id]); |
---|
112 | $id = $id_uppercats[$id]; |
---|
113 | } |
---|
114 | $data['uppercats'] = implode(',', array_reverse($uppercats)); |
---|
115 | |
---|
116 | array_push($datas, $data); |
---|
117 | } |
---|
118 | |
---|
119 | mass_updates( |
---|
120 | CATEGORIES_TABLE, |
---|
121 | array( |
---|
122 | 'primary' => array('id'), |
---|
123 | 'update' => array('uppercats') |
---|
124 | ), |
---|
125 | $datas |
---|
126 | ); |
---|
127 | |
---|
128 | // now we upgrade from 1.3.1 to 1.6.0 |
---|
129 | include_once(PHPWG_ROOT_PATH.'install/upgrade_1.3.1.php'); |
---|
130 | ?> |
---|