From e66cb9e0967383876247127e5b11014960c3313b Mon Sep 17 00:00:00 2001 From: Thomas Famula Date: Fri, 14 Oct 2022 17:40:56 +0200 Subject: [PATCH] Refactor deprecated update steps using Objectives #2 --- .../Setup/class.ilSkillDBUpdateSteps.php | 53 ++++--------------- .../classes/Setup/class.ilSkillSetupAgent.php | 10 ++-- .../class.ilTreeAdminNodeAddedObjective.php | 29 ++++++++-- 3 files changed, 41 insertions(+), 51 deletions(-) diff --git a/Services/Skill/classes/Setup/class.ilSkillDBUpdateSteps.php b/Services/Skill/classes/Setup/class.ilSkillDBUpdateSteps.php index 848341ab358b..99372fe99b2a 100644 --- a/Services/Skill/classes/Setup/class.ilSkillDBUpdateSteps.php +++ b/Services/Skill/classes/Setup/class.ilSkillDBUpdateSteps.php @@ -87,50 +87,17 @@ public function step_5(): void public function step_6(): void { - // get skill managemenet object id - $set = $this->db->queryF( - "SELECT * FROM object_data " . - " WHERE type = %s ", - ["text"], - ["skmg"] - ); - $rec = $this->db->fetchAssoc($set); - - // get skill management ref id - $set = $this->db->queryF( - "SELECT * FROM object_reference " . - " WHERE obj_id = %s ", - ["integer"], - [$rec["obj_id"]] + $this->db->update( + "object_data", + [ + "title" => ["text", "Default"], + "description" => ["text", ""] + ], + [ // where + "type" => ["text", "skee"], + "title" => ["text", "Skill Tree"] + ] ); - $rec = $this->db->fetchAssoc($set); - $skmg_ref_id = $rec["ref_id"]; - - // create default tree object entry - $obj_id = $this->db->nextId('object_data'); - $this->db->manipulate("INSERT INTO object_data " . - "(obj_id, type, title, description, owner, create_date, last_update) VALUES (" . - $this->db->quote($obj_id, "integer") . "," . - $this->db->quote("skee", "text") . "," . - $this->db->quote("Default", "text") . "," . - $this->db->quote("", "text") . "," . - $this->db->quote(-1, "integer") . "," . - $this->db->now() . "," . - $this->db->now() . - ")"); - - // get ref id for default tree object - $ref_id = $this->db->nextId('object_reference'); - $this->db->manipulate("INSERT INTO object_reference " . - "(obj_id, ref_id) VALUES (" . - $this->db->quote($obj_id, "integer") . "," . - $this->db->quote($ref_id, "integer") . - ")"); - - // put in tree - require_once("Services/Tree/classes/class.ilTree.php"); - $tree = new ilTree(ROOT_FOLDER_ID); - $tree->insertNode($ref_id, (int) $skmg_ref_id); } public function step_7(): void diff --git a/Services/Skill/classes/Setup/class.ilSkillSetupAgent.php b/Services/Skill/classes/Setup/class.ilSkillSetupAgent.php index 978b9465b5f7..89a498cefebb 100644 --- a/Services/Skill/classes/Setup/class.ilSkillSetupAgent.php +++ b/Services/Skill/classes/Setup/class.ilSkillSetupAgent.php @@ -28,9 +28,6 @@ public function getUpdateObjective(Setup\Config $config = null): Setup\Objective return new Setup\ObjectiveCollection( "Updates of Services/Skill", false, - new ilDatabaseUpdateStepsExecutedObjective( - new ilSkillDBUpdateSteps() - ), ...$this->getRbacObjectives() ); } @@ -44,8 +41,8 @@ public function getRbacObjectives(): array { $objectives = []; - // add basic object type - $objectives[] = new ilObjectNewTypeAddedObjective("skee", "Skill Tree"); + // add basic object type and put in tree + $objectives[] = new ilTreeAdminNodeAddedObjective("skee", "Skill Tree", "skmg"); // custom rbac operations $objectives[] = new ilAccessCustomRBACOperationAddedObjective( @@ -96,6 +93,9 @@ public function getRbacObjectives(): array // common rbac operations $objectives[] = new ilAccessRbacStandardOperationsAddedObjective("skee"); + // db update steps + $objectives[] = new ilDatabaseUpdateStepsExecutedObjective(new ilSkillDBUpdateSteps()); + return $objectives; } } diff --git a/Services/Tree/classes/Setup/class.ilTreeAdminNodeAddedObjective.php b/Services/Tree/classes/Setup/class.ilTreeAdminNodeAddedObjective.php index eb127754e849..7a65bd8d12b3 100644 --- a/Services/Tree/classes/Setup/class.ilTreeAdminNodeAddedObjective.php +++ b/Services/Tree/classes/Setup/class.ilTreeAdminNodeAddedObjective.php @@ -37,16 +37,18 @@ class ilTreeAdminNodeAddedObjective implements Setup\Objective protected string $type; protected string $title; + protected string $parent_type; - public function __construct(string $type, string $title) + public function __construct(string $type, string $title, string $parent_type = "") { $this->type = $type; $this->title = $title; + $this->parent_type = $parent_type; } public function getHash(): string { - return hash("sha256", self::class); + return hash("sha256", self::class . "::" . $this->type); } public function getLabel(): string @@ -120,7 +122,28 @@ public function achieve(Environment $environment): Environment 0, $db ); - $tree->insertNode((int) $ref_id, (int) SYSTEM_FOLDER_ID); + if ($this->parent_type) { + $set = $db->queryF( + "SELECT * FROM object_data " . + " WHERE type = %s ", + ["text"], + [$this->parent_type] + ); + $rec = $db->fetchAssoc($set); + + $set = $db->queryF( + "SELECT * FROM object_reference " . + " WHERE obj_id = %s ", + ["integer"], + [$rec["obj_id"]] + ); + $rec = $db->fetchAssoc($set); + $parent_type_ref_id = $rec["ref_id"]; + + $tree->insertNode((int) $ref_id, (int) $parent_type_ref_id); + } else { + $tree->insertNode((int) $ref_id, (int) SYSTEM_FOLDER_ID); + } foreach ($this->rbac_ops as $ops_id) { if (ilRbacReview::_isRBACOperation($obj_type_id, $ops_id)) {