Skip to content

Commit

Permalink
Refactor deprecated update steps using Objectives #2
Browse files Browse the repository at this point in the history
  • Loading branch information
tfamula committed Oct 14, 2022
1 parent ffc67e4 commit 3339b92
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 53 deletions.
53 changes: 10 additions & 43 deletions Services/Skill/classes/Setup/class.ilSkillDBUpdateSteps.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions Services/Skill/classes/Setup/class.ilSkillSetupAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ public function getUpdateObjective(Setup\Config $config = null): Setup\Objective
return new Setup\ObjectiveCollection(
"Updates of Services/Skill",
false,
new ilDatabaseUpdateStepsExecutedObjective(
new ilSkillDBUpdateSteps()
),
...$this->getRbacObjectives()
...$this->getObjectives()
);
}

Expand All @@ -40,12 +37,12 @@ public function getStatusObjective(Setup\Metrics\Storage $storage): Setup\Object
return new ilDatabaseUpdateStepsMetricsCollectedObjective($storage, new ilSkillDBUpdateSteps());
}

public function getRbacObjectives(): array
protected function getObjectives(): 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(
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 3339b92

Please sign in to comment.