From 70e2cb6d057bd778fd57067d08268dc019f89c57 Mon Sep 17 00:00:00 2001 From: nbm Date: Tue, 31 Jan 2006 14:50:20 +0000 Subject: [PATCH] Correct units data after an upgrade - folder_id is stored in units (not unit_id in folders), and unit_id is stored directly in groups, not via groups_units_link. --- lib/upgrades/UpgradeFunctions.inc.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/upgrades/UpgradeFunctions.inc.php b/lib/upgrades/UpgradeFunctions.inc.php index 453ad84..a8ddb6e 100644 --- a/lib/upgrades/UpgradeFunctions.inc.php +++ b/lib/upgrades/UpgradeFunctions.inc.php @@ -402,9 +402,32 @@ class UpgradeFunctions { // {{{ fixUnits function fixUnits() { + // First, assign the unit to a group directly on the group + // table, not via the group_units table, since groups could only + // belong to a single unit anyway. $sGULTable = KTUtil::getTableName("groups_units"); + $sGroupsTable = KTUtil::getTableName('groups'); $aGroupUnits = DBUtil::getResultArray("SELECT group_id, unit_id FROM $sGULTable"); - exit(0); + foreach ($aGroupUnits as $aRow) { + // $curunit = DBUtil::getOneResultKey(array("SELECT unit_id FROM $sGroupsTable WHERE id = ?", array($aRow['group_id'])), "unit_id"); + DBUtil::autoUpdate($sGroupsTable, array('unit_id' => $aRow['unit_id']), $aRow['group_id']); + } + + // Now, assign the unit folder id to the unit directly, instead + // of storing the unit_id on every folder beneath the unit + // folder. + $sFoldersTable = KTUtil::getTableName('folders'); + $sUnitsTable = KTUtil::getTableName('units'); + $sQuery = "SELECT id FROM folders WHERE unit_id = ? ORDER BY LENGTH(parent_folder_ids) LIMIT 1"; + $aUnitIds = DBUtil::getResultArrayKey("SELECT id FROM $sUnitsTable", 'id'); + foreach ($aUnitIds as $iUnitId) { + $aParams = array($iUnitId); + $iFolderId = DBUtil::getOneResultKey(array($sQuery, $aParams), 'id'); + if (!empty($iFolderId)) { + DBUtil::autoUpdate($sUnitsTable, array('folder_id' => $iFolderId), $iUnitId); + } + } + return true; } // }}} } -- libgit2 0.21.4