@@ -202,39 +202,39 @@ function bugs_authenticate (&$user, &$pw, &$logged_in, &$user_flags)
202
202
*/
203
203
function get_pseudo_packages ($ project , $ return_disabled = true )
204
204
{
205
- global $ project_types ;
206
-
207
- require_once 'Tree/Tree.php ' ;
205
+ global $ dbh , $ project_types ;
208
206
207
+ $ pseudo_pkgs = $ nodes = $ tree = array ();
209
208
$ where = '1=1 ' ;
210
209
$ project = strtolower ($ project );
211
210
212
211
if ($ project !== false && in_array ($ project , $ project_types )) {
213
- $ where .= " AND project IN ('', ' " . $ project . " ') " ;
212
+ $ where .= " AND project IN ('', ' $ project') " ;
214
213
}
215
214
if (!$ return_disabled ) {
216
215
$ where .= " AND disabled = 0 " ;
217
216
}
218
217
219
- $ pseudo_pkgs = array ();
220
- $ tree = Tree::setup (
221
- 'Memory_MDB2simple ' ,
222
- DATABASE_DSN ,
223
- array (
224
- 'order ' => 'disabled, id ' ,
225
- 'whereAddOn ' => $ where ,
226
- 'table ' => 'bugdb_pseudo_packages ' ,
227
- 'columnNameMaps ' => array (
228
- 'parentId ' => 'parent ' ,
229
- ),
230
- )
231
- );
232
- $ tree ->setup ();
218
+ $ data = $ dbh ->queryAll ("SELECT * FROM bugdb_pseudo_packages WHERE $ where ORDER BY parent, disabled, id " , null , MDB2_FETCHMODE_ASSOC );
233
219
234
- foreach ($ tree ->data as $ data )
220
+ // Convert flat array to nested strucutre
221
+ foreach ($ data as &$ node )
235
222
{
236
- if (isset ($ data ['children ' ]))
237
- {
223
+ $ node ['children ' ] = array ();
224
+ $ id = $ node ['id ' ];
225
+ $ parent_id = $ node ['parent ' ];
226
+ $ nodes [$ id ] =& $ node ;
227
+
228
+ if (array_key_exists ($ parent_id , $ nodes )) {
229
+ $ nodes [$ parent_id ]['children ' ][] =& $ node ;
230
+ } else {
231
+ $ tree [] =& $ node ;
232
+ }
233
+ }
234
+
235
+ foreach ($ tree as $ data )
236
+ {
237
+ if (isset ($ data ['children ' ])) {
238
238
$ pseudo_pkgs [$ data ['name ' ]] = array ($ data ['long_name ' ], $ data ['disabled ' ]);
239
239
$ long_names = array ();
240
240
foreach ($ data ['children ' ] as $ k => $ v ) {
@@ -246,8 +246,9 @@ function get_pseudo_packages($project, $return_disabled = true)
246
246
$ pseudo_pkgs [$ child ['name ' ]] = array (" {$ child ['long_name ' ]}" , $ child ['disabled ' ]);
247
247
}
248
248
249
- } else if (!isset ($ pseudo_pkgs [$ data ['name ' ]]))
249
+ } elseif (!isset ($ pseudo_pkgs [$ data ['name ' ]])) {
250
250
$ pseudo_pkgs [$ data ['name ' ]] = array ($ data ['long_name ' ], $ data ['disabled ' ]);
251
+ }
251
252
}
252
253
253
254
return $ pseudo_pkgs ;
0 commit comments