Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions components/ILIAS/ItemGroup/classes/Setup/class.Agent.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,27 @@
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\ItemGroup\Setup;

use ILIAS\Setup;
use ILIAS\Setup\Agent\NullAgent;
use ILIAS\Setup\Config;
use ILIAS\Setup\Objective;
use ilDatabaseUpdateStepsExecutedObjective;

/**
* @author Alexander Killing <killing@leifos.de>
*/
class Agent extends Setup\Agent\NullAgent
class Agent extends NullAgent
{
public function getUpdateObjective(?Setup\Config $config = null): Setup\Objective
public function getUpdateObjective(?Config $config = null): Objective
{
return new \ilDatabaseUpdateStepsExecutedObjective(new ilItemGroupDBUpdateSteps());
return new ilDatabaseUpdateStepsExecutedObjective(new ilItemGroupDBUpdateSteps());
}

public function getMigrations(): array
{
return [
new ilItemGroupDisplayMigration()
new ilItemGroupDisplayMigration(),
new ilItemGroupDataTableColumnMigration(),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,19 @@ public function step_3(): void
]);
}
}

public function step_4(): void
{
if ($this->db->tableColumnExists('itgr_data', 'hide_title')) {
$this->db->modifyTableColumn('itgr_data', 'hide_title', [
'default' => ilItemGroupDisplayMigration::MIGRATED_MARKER,
]);
}

if ($this->db->tableColumnExists('itgr_data', 'behaviour')) {
$this->db->modifyTableColumn('itgr_data', 'behaviour', [
'default' => ilItemGroupDisplayMigration::MIGRATED_MARKER,
]);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\ItemGroup\Setup;

use ilDatabaseUpdateStepsExecutedObjective;
use ilDBConstants;
use ilDBInterface;
use ILIAS\Setup\Environment;
use ILIAS\Setup\Migration;
use RuntimeException;

class ilItemGroupDataTableColumnMigration implements Migration
{
private ilDBInterface $db;

public function getLabel(): string
{
return 'Removes item group data table columns hide_title and behaviour.';
}

public function getDefaultAmountOfStepsPerRun(): int
{
return 1;
}

public function getPreconditions(Environment $environment): array
{
return [
new ilDatabaseUpdateStepsExecutedObjective(new ilItemGroupDBUpdateSteps())
];
}

public function prepare(Environment $environment): void
{
$this->db = $environment->getResource(Environment::RESOURCE_DATABASE);
}

public function step(Environment $environment): void
{
if ($this->isDataMigrationRequired()) {
return;
}

if ($this->db->tableColumnExists('itgr_data', 'hide_title')) {
$this->db->dropTableColumn('itgr_data', 'hide_title');
}

if ($this->db->tableColumnExists('itgr_data', 'behaviour')) {
$this->db->dropTableColumn('itgr_data', 'behaviour');
}
}

public function getRemainingAmountOfSteps(): int
{
if ($this->isDataMigrationRequired()) {
throw new RuntimeException(sprintf('The %s migration must be executed first.', ilItemGroupDisplayMigration::class));
}

return (int) (
$this->db->tableColumnExists('itgr_data', 'hide_title')
|| $this->db->tableColumnExists('itgr_data', 'behaviour')
);
}

private function isDataMigrationRequired(): bool
{
$result = $this->db->queryF(
'SELECT COUNT(id) AS cnt FROM itgr_data WHERE hide_title <> %s AND behaviour <> %s',
[ilDBConstants::T_INTEGER, ilDBConstants::T_INTEGER],
[ilItemGroupDisplayMigration::MIGRATED_MARKER, ilItemGroupDisplayMigration::MIGRATED_MARKER]
);

return ($this->db->fetchObject($result)?->cnt ?? 0) > 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

class ilItemGroupDisplayMigration implements Migration
{
private const MIGRATED_MARKER = -1;
public const MIGRATED_MARKER = -1;

private ilDBInterface $db;

Expand Down Expand Up @@ -58,6 +58,10 @@ public function prepare(Environment $environment): void

public function step(Environment $environment): void
{
if (!$this->columnsExist()) {
return;
}

$result = $this->db->queryF(
'SELECT id, hide_title, behaviour FROM itgr_data WHERE hide_title <> %s AND behaviour <> %s LIMIT 1',
[ilDBConstants::T_INTEGER, ilDBConstants::T_INTEGER],
Expand Down Expand Up @@ -87,6 +91,10 @@ public function step(Environment $environment): void

public function getRemainingAmountOfSteps(): int
{
if (!$this->columnsExist()) {
return 0;
}

$result = $this->db->queryF(
'SELECT COUNT(id) AS cnt FROM itgr_data WHERE hide_title <> %s AND behaviour <> %s',
[ilDBConstants::T_INTEGER, ilDBConstants::T_INTEGER],
Expand Down Expand Up @@ -120,4 +128,11 @@ private function mapLegacyValues(int $hide_title, int $behaviour): array
]
};
}

private function columnsExist(): bool
{
return
$this->db->tableColumnExists('itgr_data', 'hide_title')
&& $this->db->tableColumnExists('itgr_data', 'behaviour');
}
}
66 changes: 51 additions & 15 deletions components/ILIAS/ItemGroup/classes/class.ilItemGroupDataSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ilItemGroupDataSet extends ilDataSet

public function getSupportedVersions(): array
{
return array("4.3.0", "5.3.0");
return array("4.3.0", "5.3.0", "10.12");
}

public function getXmlNamespace(string $a_entity, string $a_schema_version): string
Expand All @@ -50,13 +50,21 @@ protected function getTypes(string $a_entity, string $a_version): array
"Behaviour" => "integer",
"Title" => "text",
"Description" => "text");
case "10.12":
return array(
"Id" => "integer",
"Display" => "text",
"ToggleableInitially" => "text",
"Title" => "text",
"Description" => "text");
}
}

if ($a_entity == "itgr_item") {
switch ($a_version) {
case "4.3.0":
case "5.3.0":
case "10.12":
return array(
"ItemGroupId" => "integer",
"ItemId" => "text"
Expand All @@ -79,10 +87,19 @@ public function readData(string $a_entity, string $a_version, array $a_ids): voi
$ilDB->in("obj_id", $a_ids, false, "integer"));
break;
case "5.3.0":
$this->getDirectDataFromQuery("SELECT obj_id id, title, description, hide_title, behaviour " .
" FROM object_data JOIN itgr_data ON (object_data.obj_id = itgr_data.id)" .
"WHERE " .
$ilDB->in("obj_id", $a_ids, false, "integer"));
$this->getDirectDataFromQuery(
"SELECT obj_id id, title, description, hide_title, behaviour" .
"FROM object_data " .
"WHERE {$ilDB->in("obj_id", $a_ids, false, "integer")}"
);
break;
case "10.12":
$this->getDirectDataFromQuery(
"SELECT obj_id id, title, description, itgr_data.display, itgr_data.toggleable_initially " .
"FROM object_data " .
"INNER JOIN itgr_data ON (object_data.obj_id = itgr_data.id) " .
"WHERE {$ilDB->in("obj_id", $a_ids, false, "integer")}"
);
break;
}
}
Expand All @@ -91,6 +108,7 @@ public function readData(string $a_entity, string $a_version, array $a_ids): voi
switch ($a_version) {
case "4.3.0":
case "5.3.0":
case "10.12":
$this->getDirectDataFromQuery($q = "SELECT item_group_id itgr_id, item_ref_id item_id" .
" FROM item_group_item " .
"WHERE " .
Expand Down Expand Up @@ -146,16 +164,8 @@ public function importRecord(

$newObj->setTitle($a_rec["Title"]);
$newObj->setDescription($a_rec["Description"]);
$newObj->setDisplay(
$a_rec["HideTitle"] === "1"
? ilItemGroupAR::DISPLAY_WITHOUT_TITLE
: ilItemGroupAR::DISPLAY_WITH_TITLE
);
$newObj->setDisplayWithTitleAndToggleableInitially(
$a_rec["Behaviour"] === "1"
? ilItemGroupAR::DISPLAY_WITH_TITLE_AND_TOGGLEABLE_INITIALLY_OPEN
: ilItemGroupAR::DISPLAY_WITH_TITLE_AND_TOGGLEABLE_INITIALLY_CLOSED
);
$newObj->setDisplay($this->resolveDisplay($a_rec));
$newObj->setDisplayWithTitleAndToggleableInitially($this->resolveBehaviour($a_rec));
$newObj->update();
$this->current_obj = $newObj;
$a_mapping->addMapping("components/ILIAS/ItemGroup", "itgr", $a_rec["Id"], $newObj->getId());
Expand All @@ -174,4 +184,30 @@ public function importRecord(
break;
}
}

private function resolveDisplay(array $a_set): string
{
if (isset($a_set["HideTitle"])) {
return $a_set["HideTitle"] === "1"
? ilItemGroupAR::DISPLAY_WITHOUT_TITLE
: ilItemGroupAR::DISPLAY_WITH_TITLE;
}

return $a_set["Display"] === ilItemGroupAR::DISPLAY_WITHOUT_TITLE
? ilItemGroupAR::DISPLAY_WITHOUT_TITLE
: ilItemGroupAR::DISPLAY_WITH_TITLE;
}

private function resolveBehaviour(array $a_set): string
{
if (isset($a_set["Behaviour"])) {
return $a_set["Behaviour"] === "1"
? ilItemGroupAR::DISPLAY_WITH_TITLE_AND_TOGGLEABLE_INITIALLY_OPEN
: ilItemGroupAR::DISPLAY_WITH_TITLE_AND_TOGGLEABLE_INITIALLY_CLOSED;
}

return $a_set["ToggleableInitially"] === ilItemGroupAR::DISPLAY_WITH_TITLE_AND_TOGGLEABLE_INITIALLY_OPEN
? ilItemGroupAR::DISPLAY_WITH_TITLE_AND_TOGGLEABLE_INITIALLY_OPEN
: ilItemGroupAR::DISPLAY_WITH_TITLE_AND_TOGGLEABLE_INITIALLY_CLOSED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public function getXmlRepresentation(
public function getValidSchemaVersions(string $a_entity): array
{
return array(
"10.12" => array(
"uses_dataset" => true,
"min" => "10.12",
"max" => ""),
"5.3.0" => array(
"namespace" => "https://www.ilias.de/Modules/ItemGroup/itgr/5_3",
"xsd_file" => "ilias_itgr_5_3.xsd",
Expand Down
Loading