From 6854cb3f4d8219cf1829e32122eb2502a916eae9 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 1 Feb 2020 09:05:48 +0100 Subject: initial checkin --- setup/upgrade/0.9.9/convert_categories.php | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 setup/upgrade/0.9.9/convert_categories.php (limited to 'setup/upgrade/0.9.9/convert_categories.php') diff --git a/setup/upgrade/0.9.9/convert_categories.php b/setup/upgrade/0.9.9/convert_categories.php new file mode 100644 index 0000000..99789ad --- /dev/null +++ b/setup/upgrade/0.9.9/convert_categories.php @@ -0,0 +1,43 @@ +query('SELECT category_id FROM {list_category} WHERE parent_id = ? AND project_id = ?', array($parent, $pr)); + + while ($row = $db->fetchRow($result)) { + // recursive execution of this function for each + // child of this node + // $right is the current right value, which is + // incremented by the rebuild_tree function + $right = rebuild_tree($row['category_id'], $right, $pr); + } + + // we've got the left value, and now that we've processed + // the children of this node we also know the right value + $db->query('UPDATE {list_category} SET lft= ?, rgt= ? WHERE category_id = ?', array($left, $right, $parent)); + $sql = $db->query('SELECT * FROM {list_category} WHERE category_id = ? OR project_id=? AND parent_id=-1', array($parent, $pr)); + if (!$db->countRows($sql)) { + $db->query('INSERT INTO {list_category} (project_id, lft, rgt, category_name, parent_id) VALUES(?,?,?,?,-1)', + array($pr,$left,$right,'root')); + } + // return the right value of this node + 1 + return $right+1; +} + +$projects = $db->query('SELECT project_id FROM {projects}'); + +// Global project +rebuild_tree(0, 1, 0); +while ($pr = $db->fetchRow($projects)) { + rebuild_tree(0, 1, $pr['project_id']); +} + +?> -- cgit v1.2.3-70-g09d2