Migrate 4 builtin fields to fields2: priority, resolution, severity, status.
[bugdar.git] / includes / functions_datastore.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2002-2007 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 2 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 Bugdar::$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 Bugdar::$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 Bugdar::$datastore['usergroup'] = $groups;
80 }
81
82 // ###################### Start build_assignedto #####################
83 function build_assignedto()
84 {
85 global $bugsys;
86
87 // determine the groups that are assignable
88 $ids = $exprs = array();
89 foreach (Bugdar::$datastore['usergroup'] AS $id => $group)
90 {
91 if ($group['permissions'] & $bugsys->permissions['canbeassignedto'])
92 {
93 $ids[] = $id;
94 $exprs[] = "FIND_IN_SET($id, groupids)";
95 }
96 }
97
98 $ids = implode(',', $ids);
99 $exprs = implode(' OR ', $exprs);
100 $users = $bugsys->db->query("
101 SELECT email, displayname, userid, showemail
102 FROM " . TABLE_PREFIX . "user AS user
103 WHERE usergroupid IN ($ids) OR $exprs"
104 );
105 while ($user = $bugsys->db->fetch_array($users))
106 {
107 $devs["$user[userid]"] = $user;
108 }
109
110 $bugsys->db->query("
111 ### replacing developer / assign to cache ###
112 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
113 VALUES ('assignto', '" . $bugsys->escape(serialize($devs)) . "')"
114 );
115
116 Bugdar::$datastore['assignto'] = $devs;
117 }
118
119 // ####################### Start build_versions ######################
120 function build_versions()
121 {
122 global $bugsys;
123
124 $versions = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "version ORDER BY displayorder ASC");
125 while ($version = $bugsys->db->fetch_array($versions))
126 {
127 $tempstore["$version[versionid]"] = $version;
128 }
129
130 $bugsys->db->query("
131 ### replacing version cache ###
132 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
133 VALUES ('version', '" . $bugsys->escape(serialize($tempstore)) . "')"
134 );
135
136 Bugdar::$datastore['version'] = $tempstore;
137 }
138
139 // ####################### Start build_products ######################
140 function build_products()
141 {
142 global $bugsys;
143
144 $products = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "product ORDER BY displayorder ASC");
145 while ($product = $bugsys->db->fetch_array($products))
146 {
147 if ($product['parentid'])
148 {
149 $tempstore['component']["$product[productid]"] = $product;
150 }
151 else
152 {
153 $tempstore['product']["$product[productid]"] = $product;
154 }
155 }
156
157 $bugsys->db->query("
158 ### replacing product / component cache ###
159 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
160 VALUES
161 ('product', '" . $bugsys->escape(serialize($tempstore['product'])) . "'),
162 ('component', '" . $bugsys->escape(serialize($tempstore['component'])) . "')"
163 );
164
165 Bugdar::$datastore['product'] = $tempstore['product'];
166 Bugdar::$datastore['component'] = $tempstore['component'];
167 }
168
169 // ##################### Start build_permissions #####################
170 function build_permissions()
171 {
172 global $bugsys;
173
174 $permissions = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "permission ORDER BY usergroupid, productid");
175 while ($permission = $bugsys->db->fetch_array($permissions))
176 {
177 $tempstore["$permission[usergroupid]"]["$permission[productid]"] = $permission['mask'];
178 }
179
180 $bugsys->db->query("
181 ### replacing permissions cache ###
182 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
183 VALUES ('permission', '" . $bugsys->escape(serialize($tempstore)) . "')"
184 );
185
186 Bugdar::$datastore['permission'] = $tempstore;
187 }
188
189 // ##################### Start build_automations ####################
190 function build_automations()
191 {
192 global $bugsys;
193
194 $automations = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "automation ORDER BY name ASC");
195 while ($automation = $bugsys->db->fetch_array($automations))
196 {
197 $actions["$automation[actionid]"] = $automation;
198 }
199
200 $bugsys->db->query("
201 ### replacing automation cache ###
202 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
203 VALUES ('automation', '" . $bugsys->escape(serialize($actions)) . "')"
204 );
205
206 Bugdar::$datastore['automation'] = $actions;
207 }
208
209 // ###################### Start build_user_help ######################
210 function build_user_help()
211 {
212 global $bugsys;
213
214 // custom field descriptions
215 $descriptions = $bugsys->db->query("SELECT fieldid, name, description FROM " . TABLE_PREFIX . "bugfield");
216 while ($field = $bugsys->db->fetch_array($descriptions))
217 {
218 $help["field$field[fieldid]"] = array('title' => $field['name'], 'body' => $field['description']);
219 }
220
221 // standard help texts
222 $texts = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "fieldhelp");
223 while ($field = $bugsys->db->fetch_array($texts))
224 {
225 $help["$field[keystring]"] = $field;
226 }
227
228 $bugsys->db->query("
229 ### replacing user help cache ###
230 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
231 VALUES ('help', '" . $bugsys->escape(serialize($help)) . "')"
232 );
233
234 Bugdar::$datastore['help'] = $help;
235 }
236