From 0df0f661bfc0b3d2e0e30967bc55dc45fc7885a2 Mon Sep 17 00:00:00 2001 From: Thomas Hackl Date: Thu, 24 Jul 2025 13:15:32 +0200 Subject: renumber migration --- db/migrations/6.1.11_tree_node_path.php | 71 --------------------------------- db/migrations/6.1.16_tree_node_path.php | 71 +++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 71 deletions(-) delete mode 100644 db/migrations/6.1.11_tree_node_path.php create mode 100644 db/migrations/6.1.16_tree_node_path.php diff --git a/db/migrations/6.1.11_tree_node_path.php b/db/migrations/6.1.11_tree_node_path.php deleted file mode 100644 index 35c3bd1..0000000 --- a/db/migrations/6.1.11_tree_node_path.php +++ /dev/null @@ -1,71 +0,0 @@ -exec("ALTER TABLE `sem_tree` - ADD `ancestors` VARCHAR(255) NOT NULL AFTER `parent_id`, - ADD INDEX `ancestors` (`ancestors`)" - ); - StudipStudyArea::expireTableScheme(); - $this->buildStructure(StudipStudyArea::class, 'root', 0, 0, ''); - - DBManager::get()->exec("ALTER TABLE `range_tree` - ADD `ancestors` VARCHAR(255) NOT NULL AFTER `parent_id`, - ADD INDEX `ancestors` (`ancestors`)" - ); - RangeTreeNode::expireTableScheme(); - $this->buildStructure(RangeTreeNode::class, 'root', 0, 0, ''); - - DBManager::get()->exec("ALTER TABLE `sem_tree` - CHANGE `sem_tree_id` `sem_tree_id` INT UNSIGNED NOT NULL AUTO_INCREMENT, - CHANGE `parent_id` `parent_id` INT UNSIGNED NOT NULL"); - DBManager::get()->exec("ALTER TABLE `seminar_sem_tree` - CHANGE `sem_tree_id` `sem_tree_id` INT UNSIGNED NOT NULL"); - DBManager::get()->exec("ALTER TABLE `range_tree` - CHANGE `item_id` `item_id` INT UNSIGNED NOT NULL AUTO_INCREMENT, - CHANGE `parent_id` `parent_id` INT UNSIGNED NOT NULL"); - } - - public function down() - { - DBManager::get()->exec("ALTER TABLE `sem_tree` DROP `ancestors`"); - DBManager::get()->exec("ALTER TABLE `range_tree` DROP `ancestors`"); - } - - private function buildStructure(string $classname, string $oldParentId, int $newParentId, int $currentId, string $ancestors) - { - foreach ($classname::findByParent_id($oldParentId, "ORDER BY `priority`") as $child) { - $currentId++; - $newAncestors = $ancestors; - if ($ancestors !== '') { - $newAncestors .= '|'; - } - $newAncestors .= $newParentId; - - $oldId = $child->id; - $child->id = $currentId; - $child->parent_id = $newParentId; - $child->ancestors = $newAncestors; - $child->store(); - - DBManager::get()->execute( - "UPDATE `seminar_sem_tree` SET `sem_tree_id` = :new WHERE `sem_tree_id` = :old", - ['new' => $child->id, 'old' => $oldId] - ); - - $currentId = $this->buildStructure($classname, $oldId, $child->id, $currentId, $newAncestors); - } - - return $currentId; - } - -}; - diff --git a/db/migrations/6.1.16_tree_node_path.php b/db/migrations/6.1.16_tree_node_path.php new file mode 100644 index 0000000..4a7530b --- /dev/null +++ b/db/migrations/6.1.16_tree_node_path.php @@ -0,0 +1,71 @@ +exec("ALTER TABLE `sem_tree` + ADD IF NOT EXISTS `ancestors` VARCHAR(255) NOT NULL AFTER `parent_id`, + ADD INDEX IF NOT EXISTS `ancestors` (`ancestors`)" + ); + StudipStudyArea::expireTableScheme(); + $this->buildStructure(StudipStudyArea::class, 'root', 0, 0, ''); + + DBManager::get()->exec("ALTER TABLE `range_tree` + ADD `ancestors` VARCHAR(255) NOT NULL AFTER `parent_id`, + ADD INDEX IF NOT EXISTS `ancestors` (`ancestors`)" + ); + RangeTreeNode::expireTableScheme(); + $this->buildStructure(RangeTreeNode::class, 'root', 0, 0, ''); + + DBManager::get()->exec("ALTER TABLE `sem_tree` + CHANGE `sem_tree_id` `sem_tree_id` INT UNSIGNED NOT NULL AUTO_INCREMENT, + CHANGE `parent_id` `parent_id` INT UNSIGNED NOT NULL"); + DBManager::get()->exec("ALTER TABLE `seminar_sem_tree` + CHANGE `sem_tree_id` `sem_tree_id` INT UNSIGNED NOT NULL"); + DBManager::get()->exec("ALTER TABLE `range_tree` + CHANGE `item_id` `item_id` INT UNSIGNED NOT NULL AUTO_INCREMENT, + CHANGE `parent_id` `parent_id` INT UNSIGNED NOT NULL"); + } + + public function down() + { + DBManager::get()->exec("ALTER TABLE `sem_tree` DROP `ancestors`"); + DBManager::get()->exec("ALTER TABLE `range_tree` DROP `ancestors`"); + } + + private function buildStructure(string $classname, string $oldParentId, int $newParentId, int $currentId, string $ancestors) + { + foreach ($classname::findByParent_id($oldParentId, "ORDER BY `priority`") as $child) { + $currentId++; + $newAncestors = $ancestors; + if ($ancestors !== '') { + $newAncestors .= '|'; + } + $newAncestors .= $newParentId; + + $oldId = $child->id; + $child->id = $currentId; + $child->parent_id = $newParentId; + $child->ancestors = $newAncestors; + $child->store(); + + DBManager::get()->execute( + "UPDATE `seminar_sem_tree` SET `sem_tree_id` = :new WHERE `sem_tree_id` = :old", + ['new' => $child->id, 'old' => $oldId] + ); + + $currentId = $this->buildStructure($classname, $oldId, $child->id, $currentId, $newAncestors); + } + + return $currentId; + } + +}; + -- cgit v1.0