Skip to content

Commit

Permalink
Database: Fix Metric Objective
Browse files Browse the repository at this point in the history
Resolved initial error, which is access to a private method, and also made the
objective more fail safe.

See:

* ILIAS-eLearning#6801
* https://mantis.ilias.de/view.php?id=39355
  • Loading branch information
klees committed Jan 9, 2024
1 parent ff55ac7 commit b803fab
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,6 +16,8 @@
*
*********************************************************************/

declare(strict_types=1);

use ILIAS\Setup;
use ILIAS\DI;

Expand Down Expand Up @@ -83,85 +83,76 @@ protected function collectFrom(Setup\Environment $environment, Setup\Metrics\Sto
// is something we want. Currently, every component could just service
// locate the whole world via the global $DIC.
$DIC = $GLOBALS["DIC"] ?? [];
$GLOBALS["DIC"] = new DI\Container();
$GLOBALS["DIC"]["ilDB"] = $db;
$GLOBALS["ilDB"] = $db;
$GLOBALS["DIC"]["ilBench"] = null;
$GLOBALS["DIC"]["ilLog"] = new class () {
public function write(): void
{
try {
$GLOBALS["DIC"] = new DI\Container();
$GLOBALS["DIC"]["ilDB"] = $db;
$GLOBALS["DIC"]["ilBench"] = null;
$GLOBALS["DIC"]["ilLog"] = new class () {
public function write(): void
{
}
public function info(): void
{
}
public function warning($msg): void
{
}
public function error($msg): void
{
}
};
/** @noinspection PhpArrayIndexImmediatelyRewrittenInspection */
$GLOBALS["DIC"]["ilLoggerFactory"] = new class () {
public function getRootLogger(): object
{
return new class () {
public function write(): void
{
}
};
}
};
if (!defined("CLIENT_DATA_DIR")) {
define("CLIENT_DATA_DIR", $ini->readVariable("clients", "datadir") . "/" . $client_id);
}
public function info(): void
{
if (!defined("CLIENT_WEB_DIR")) {
define("CLIENT_WEB_DIR", dirname(__DIR__, 4) . "/data/" . $client_id);
}
public function warning($msg): void
{
if (!defined("ILIAS_ABSOLUTE_PATH")) {
define("ILIAS_ABSOLUTE_PATH", dirname(__FILE__, 5));
}
public function error($msg): void
{
if (!defined("ILIAS_LOG_ENABLED")) {
define("ILIAS_LOG_ENABLED", false);
}
};
$GLOBALS["ilLog"] = $GLOBALS["DIC"]["ilLog"];
/** @noinspection PhpArrayIndexImmediatelyRewrittenInspection */
$GLOBALS["DIC"]["ilLoggerFactory"] = new class () {
public function getRootLogger(): object
{
return new class () {
public function write(): void
{
}
};
if (!defined("ROOT_FOLDER_ID")) {
define("ROOT_FOLDER_ID", (int) $client_ini->readVariable("system", "ROOT_FOLDER_ID"));
}
};
$GLOBALS["ilCtrlStructureReader"] = new class () {
public function getStructure(): void
{
if (!defined("ROLE_FOLDER_ID")) {
define("ROLE_FOLDER_ID", (int) $client_ini->readVariable("system", "ROLE_FOLDER_ID"));
}
public function setIniFile(): void
{
if (!defined("SYSTEM_FOLDER_ID")) {
define("SYSTEM_FOLDER_ID", (int) $client_ini->readVariable("system", "SYSTEM_FOLDER_ID"));
}
};
if (!defined("CLIENT_DATA_DIR")) {
define("CLIENT_DATA_DIR", $ini->readVariable("clients", "datadir") . "/" . $client_id);
}
if (!defined("CLIENT_WEB_DIR")) {
define("CLIENT_WEB_DIR", dirname(__DIR__, 4) . "/data/" . $client_id);
}
if (!defined("ILIAS_ABSOLUTE_PATH")) {
define("ILIAS_ABSOLUTE_PATH", dirname(__FILE__, 5));
}
if (!defined("ILIAS_LOG_ENABLED")) {
define("ILIAS_LOG_ENABLED", false);
}
if (!defined("ROOT_FOLDER_ID")) {
define("ROOT_FOLDER_ID", (int) $client_ini->readVariable("system", "ROOT_FOLDER_ID"));
}
if (!defined("ROLE_FOLDER_ID")) {
define("ROLE_FOLDER_ID", (int) $client_ini->readVariable("system", "ROLE_FOLDER_ID"));
}
if (!defined("SYSTEM_FOLDER_ID")) {
define("SYSTEM_FOLDER_ID", (int) $client_ini->readVariable("system", "SYSTEM_FOLDER_ID"));
}

$db_update = new ilDBUpdate($db);
$db_update->readCustomUpdatesInfo(true);

$storage->storeStableCounter(
"custom_version",
$db_update->getCustomUpdatesCurrentVersion() ?? 0,
"The version of the custom database schema that is currently installed."
);
$storage->storeStableCounter(
"available_custom_version",
$db_update->getCustomUpdatesFileVersion() ?? 0,
"The version of the custom database schema that is available in the current source."
);
$storage->storeStableBool(
"custom_update_required",
$db_update->customUpdatesAvailable(),
"Does the database require a custom update?"
);
$db_update = new ilDBUpdate($db);

$GLOBALS["DIC"] = $DIC;
$storage->storeStableCounter(
"custom_version",
$db_update->getCustomUpdatesCurrentVersion() ?? 0,
"The version of the custom database schema that is currently installed."
);
$storage->storeStableCounter(
"available_custom_version",
$db_update->getCustomUpdatesFileVersion() ?? 0,
"The version of the custom database schema that is available in the current source."
);
$storage->storeStableBool(
"custom_update_required",
$db_update->customUpdatesAvailable(),
"Does the database require a custom update?"
);
} finally {
$GLOBALS["DIC"] = $DIC;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ protected function getTentativePreconditions(Setup\Environment $environment): ar

protected function collectFrom(Setup\Environment $environment, Setup\Metrics\Storage $storage): void
{
return;
$db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
$client_ini = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_INI);

Expand Down

0 comments on commit b803fab

Please sign in to comment.