r1387: Merging the upgrade script from the 1.1.x branch to the trunk
[bugdar.git] / includes / functions_datastore.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 // ###################### Start build_languages ######################
23 function build_languages()
24 {
25 global $bugsys;
26
27 $languages = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "language");
28 while ($language = $bugsys->db->fetch_array($languages))
29 {
30 $tempstore["$language[languageid]"] = $language;
31 }
32
33 $bugsys->db->query("
34 ### replacing the language cache ###
35 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
36 VALUES ('language', '" . $bugsys->escape(serialize($tempstore)) . "')"
37 );
38
39 $bugsys->datastore['language'] = $tempstore;
40 }
41
42 // ####################### Start build_settings ######################
43 function build_settings()
44 {
45 global $bugsys;
46
47 $settings = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "setting");
48 while ($setting = $bugsys->db->fetch_array($settings))
49 {
50 $options["$setting[varname]"] = $setting['value'];
51 }
52
53 $bugsys->db->query("
54 ### replacing the setting cache ###
55 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
56 VALUES ('setting', '" . $bugsys->escape(serialize($options)) . "')"
57 );
58
59 $bugsys->datastore['setting'] = $options;
60 }
61
62 // ###################### Start build_usergroups #####################
63 function build_usergroups()
64 {
65 global $bugsys;
66
67 $usergroups = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "usergroup");
68 while ($usergroup = $bugsys->db->fetch_array($usergroups))
69 {
70 $groups["$usergroup[usergroupid]"] = $usergroup;
71 }
72
73 $bugsys->db->query("
74 ### replacing usergroup cache ###
75 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
76 VALUES ('usergroup', '" . $bugsys->escape(serialize($groups)) . "')"
77 );
78
79 $bugsys->datastore['usergroup'] = $groups;
80 }
81
82 // ####################### Start build_statuses ######################
83 function build_statuses()
84 {
85 global $bugsys;
86
87 $statuses = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "status ORDER BY displayorder ASC");
88 while ($status = $bugsys->db->fetch_array($statuses))
89 {
90 $tempstore["$status[statusid]"] = $status;
91 }
92
93 $bugsys->db->query("
94 ### replacing status cache ###
95 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
96 VALUES ('status', '" . $bugsys->escape(serialize($tempstore)) . "')"
97 );
98
99 $bugsys->datastore['status'] = $tempstore;
100 }
101
102 // ###################### Start build_severities #####################
103 function build_severities()
104 {
105 global $bugsys;
106
107 $severities = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "severity ORDER BY displayorder ASC");
108 while ($severity = $bugsys->db->fetch_array($severities))
109 {
110 $tempstore["$severity[severityid]"] = $severity;
111 }
112
113 $bugsys->db->query("
114 ### replacing severity cache ###
115 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
116 VALUES ('severity', '" . $bugsys->escape(serialize($tempstore)) . "')"
117 );
118
119 $bugsys->datastore['severity'] = $tempstore;
120 }
121
122 // ###################### Start build_priorities #####################
123 function build_priorities()
124 {
125 global $bugsys;
126
127 $priorities = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "priority ORDER BY displayorder ASC");
128 while ($priority = $bugsys->db->fetch_array($priorities))
129 {
130 $tempstore["$priority[priorityid]"] = $priority;
131 }
132
133 $bugsys->db->query("
134 ### replacing priority cache ###
135 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
136 VALUES ('priority', '" . $bugsys->escape(serialize($tempstore)) . "')"
137 );
138
139 $bugsys->datastore['priority'] = $tempstore;
140 }
141
142 // ###################### Start build_assignedto #####################
143 function build_assignedto()
144 {
145 global $bugsys;
146
147 $users = $bugsys->db->query("
148 SELECT user.email, user.displayname, user.userid, user.showemail
149 FROM " . TABLE_PREFIX . "user AS user
150 LEFT JOIN " . TABLE_PREFIX . "usergroup AS usergroup ON (user.usergroupid = usergroup.usergroupid)
151 WHERE (usergroup.permissions & " . $bugsys->permissions['canbeassignedto'] . ")"
152 );
153 while ($user = $bugsys->db->fetch_array($users))
154 {
155 $devs["$user[userid]"] = $user;
156 }
157
158 $bugsys->db->query("
159 ### replacing developer / assign to cache ###
160 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
161 VALUES ('assignto', '" . $bugsys->escape(serialize($devs)) . "')"
162 );
163
164 $bugsys->datastore['assignto'] = $devs;
165 }
166
167 // ##################### Start build_resolutions #####################
168 function build_resolutions()
169 {
170 global $bugsys;
171
172 $resolutions = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "resolution ORDER BY displayorder ASC");
173 while ($resolution = $bugsys->db->fetch_array($resolutions))
174 {
175 $tempstore["$resolution[resolutionid]"] = $resolution;
176 }
177
178 $bugsys->db->query("
179 ### replacing resolution cache ###
180 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
181 VALUES ('resolution', '" . $bugsys->escape(serialize($tempstore)) . "')"
182 );
183
184 $bugsys->datastore['resolution'] = $tempstore;
185 }
186
187 // ####################### Start build_versions ######################
188 function build_versions()
189 {
190 global $bugsys;
191
192 $versions = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "version ORDER BY displayorder ASC");
193 while ($version = $bugsys->db->fetch_array($versions))
194 {
195 $tempstore["$version[versionid]"] = $version;
196 }
197
198 $bugsys->db->query("
199 ### replacing version cache ###
200 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
201 VALUES ('version', '" . $bugsys->escape(serialize($tempstore)) . "')"
202 );
203
204 $bugsys->datastore['version'] = $tempstore;
205 }
206
207 // ####################### Start build_products ######################
208 function build_products()
209 {
210 global $bugsys;
211
212 $products = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "product ORDER BY displayorder ASC");
213 while ($product = $bugsys->db->fetch_array($products))
214 {
215 if ($product['parentid'])
216 {
217 $tempstore['component']["$product[productid]"] = $product;
218 }
219 else
220 {
221 $tempstore['product']["$product[productid]"] = $product;
222 }
223 }
224
225 $bugsys->db->query("
226 ### replacing product / component cache ###
227 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
228 VALUES
229 ('product', '" . $bugsys->escape(serialize($tempstore['product'])) . "'),
230 ('component', '" . $bugsys->escape(serialize($tempstore['component'])) . "')"
231 );
232
233 $bugsys->datastore['product'] = $tempstore['product'];
234 $bugsys->datastore['component'] = $tempstore['component'];
235 }
236
237 // ##################### Start build_permissions #####################
238 function build_permissions()
239 {
240 global $bugsys;
241
242 $permissions = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "permission ORDER BY usergroupid, productid");
243 while ($permission = $bugsys->db->fetch_array($permissions))
244 {
245 $tempstore["$permission[usergroupid]"]["$permission[productid]"] = $permission['mask'];
246 }
247
248 $bugsys->db->query("
249 ### replacing permissions cache ###
250 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
251 VALUES ('permission', '" . $bugsys->escape(serialize($tempstore)) . "')"
252 );
253
254 $bugsys->datastore['permission'] = $tempstore;
255 }
256
257 // ##################### Start build_automations ####################
258 function build_automations()
259 {
260 global $bugsys;
261
262 $automations = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "automation ORDER BY name ASC");
263 while ($automation = $bugsys->db->fetch_array($automations))
264 {
265 $actions["$automation[actionid]"] = $automation;
266 }
267
268 $bugsys->db->query("
269 ### replacing automation cache ###
270 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
271 VALUES ('automation', '" . $bugsys->escape(serialize($actions)) . "')"
272 );
273
274 $bugsys->datastore['automation'] = $actions;
275 }
276
277 // ###################### Start build_user_help ######################
278 function build_user_help()
279 {
280 global $bugsys;
281
282 // custom field descriptions
283 $descriptions = $bugsys->db->query("SELECT fieldid, name, description FROM " . TABLE_PREFIX . "bugfield");
284 while ($field = $bugsys->db->fetch_array($descriptions))
285 {
286 $help["field$field[fieldid]"] = array('title' => $field['name'], 'body' => $field['description']);
287 }
288
289 // standard help texts
290 $texts = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "fieldhelp");
291 while ($field = $bugsys->db->fetch_array($texts))
292 {
293 $help["$field[keystring]"] = $field;
294 }
295
296 $bugsys->db->query("
297 ### replacing user help cache ###
298 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
299 VALUES ('help', '" . $bugsys->escape(serialize($help)) . "')"
300 );
301
302 $bugsys->datastore['help'] = $help;
303 }
304
305 /*=====================================================================*\
306 || ###################################################################
307 || # $HeadURL$
308 || # $Id$
309 || ###################################################################
310 \*=====================================================================*/
311 ?>