Skip to content

Commit 51faf6f

Browse files
committed
Remove dependency on PEAR/Tree package
1 parent c9782aa commit 51faf6f

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ Requirements
1313
- DB_DataObject
1414
- Text_CAPTCHA_Numeral
1515
- Text_Diff
16-
- Tree
1716
- HTTP
1817
- HTTP_Upload
1918

2019
Installation
2120
============
2221
1. Copy `local_config.php.sample` to `local_config.php` and modify accordingly
2322
2. Install all required packages:
24-
`pear install MDB2 MDB2#mysql MDB2#mysqli DB_DataObject Text_CAPTCHA_Numeral Text_Diff Tree-beta HTTP HTTP_Upload`
23+
`pear install MDB2 MDB2#mysql MDB2#mysqli DB_DataObject Text_CAPTCHA_Numeral Text_Diff HTTP HTTP_Upload`
2524
3. Import SQL schema from `sql/bugs.sql`
2625

2726
TODO

include/functions.php

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -202,39 +202,39 @@ function bugs_authenticate (&$user, &$pw, &$logged_in, &$user_flags)
202202
*/
203203
function get_pseudo_packages($project, $return_disabled = true)
204204
{
205-
global $project_types;
206-
207-
require_once 'Tree/Tree.php';
205+
global $dbh, $project_types;
208206

207+
$pseudo_pkgs = $nodes = $tree = array();
209208
$where = '1=1';
210209
$project = strtolower($project);
211210

212211
if ($project !== false && in_array($project, $project_types)) {
213-
$where .= " AND project IN ('', '". $project ."')";
212+
$where .= " AND project IN ('', '$project')";
214213
}
215214
if (!$return_disabled) {
216215
$where.= " AND disabled = 0";
217216
}
218217

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);
233219

234-
foreach ($tree->data as $data)
220+
// Convert flat array to nested strucutre
221+
foreach ($data as &$node)
235222
{
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'])) {
238238
$pseudo_pkgs[$data['name']] = array($data['long_name'], $data['disabled']);
239239
$long_names = array();
240240
foreach ($data['children'] as $k => $v) {
@@ -246,8 +246,9 @@ function get_pseudo_packages($project, $return_disabled = true)
246246
$pseudo_pkgs[$child['name']] = array("    {$child['long_name']}", $child['disabled']);
247247
}
248248

249-
} else if (!isset($pseudo_pkgs[$data['name']]))
249+
} elseif (!isset($pseudo_pkgs[$data['name']])) {
250250
$pseudo_pkgs[$data['name']] = array($data['long_name'], $data['disabled']);
251+
}
251252
}
252253

253254
return $pseudo_pkgs;

0 commit comments

Comments
 (0)