Skip to content

Commit

Permalink
ORGU: 42725, include a setup objective process to remove assigned met…
Browse files Browse the repository at this point in the history
…a data sets from OrgUnit types if the meta data sets are already deleted but are still assigned to OrgUnit types.

https://mantis.ilias.de/view.php?id=42725

Please note that you have to run 'php cli/setup.php achieve orgunit.removeDeletedMDSetsFromOrgUnitTypes'.
  • Loading branch information
lukastocker committed Nov 20, 2024
1 parent da6a478 commit b5c71dd
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components/ILIAS/Init/classes/class.ilInitialisation.php
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ protected static function abortAndDie(string $a_message): void
{
if (isset($GLOBALS['ilLog'])) {
$GLOBALS['ilLog']->write("Fatal Error: ilInitialisation - " . $a_message);
$GLOBALS['ilLog']->logStack();
//$GLOBALS['ilLog']->logStack();
}
die($a_message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public function getNamedObjectives(?Setup\Config $config = null): array
'removeDeletedUsersFromOrgUnits' => new Setup\ObjectiveConstructor(
'clean assignments of deleted users',
static fn(): Setup\Objective => new ilOrgUnitRemoveDeletedUsersObjective()
),
'removeDeletedMDSetsFromOrgUnitTypes' => new Setup\ObjectiveConstructor(
'clean assignments of deleted meta data sets',
static fn(): Setup\Objective => new ilOrgUnitRemoveDeletedMDSetsObjective()
)
];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?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);

use ILIAS\Setup\Environment;
use ILIAS\Setup\NullConfig;

class ilOrgUnitRemoveDeletedMDSetsObjective extends ilSetupObjective
{
public function __construct()
{
parent::__construct(new NullConfig());
}

public function getHash(): string
{
return hash('sha256', self::class);
}

public function getLabel(): string
{
return 'Deleted meta data set assignments are removed for OrgUnit types';
}

public function isNotable(): bool
{
return true;
}

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

public function achieve(Environment $environment): Environment
{
$db = $environment->getResource(Environment::RESOURCE_DATABASE);
$query = 'DELETE FROM orgu_types_adv_md_rec' . PHP_EOL
. 'WHERE rec_id NOT IN (' . PHP_EOL
. 'SELECT record_id FROM adv_md_record' . PHP_EOL
. ')';
$db->manipulate($query);
return $environment;
}

public function isApplicable(Environment $environment): bool
{
return true;
}
}

0 comments on commit b5c71dd

Please sign in to comment.