From 2bfb2169e75a656a11213a5f99bfc79c3d1731b9 Mon Sep 17 00:00:00 2001 From: Richard Klees Date: Fri, 19 Jan 2024 16:10:34 +0100 Subject: [PATCH] Setup: begin impl in new component framework --- cli/setup.php | 177 ++---------------- components/ILIAS/Setup/Setup.php | 79 +++++++- components/ILIAS/Setup/src/CLI/App.php | 19 +- .../Setup/src/ImplementationOfAgentFinder.php | 22 +-- dependency_resolution.php | 7 +- 5 files changed, 123 insertions(+), 181 deletions(-) diff --git a/cli/setup.php b/cli/setup.php index d4e9553e5b41..fbd091b003e0 100755 --- a/cli/setup.php +++ b/cli/setup.php @@ -1,162 +1,21 @@ Extended GPL, see docs/LICENSE */ - -$executed_in_directory = getcwd(); -chdir(__DIR__ . "/.."); - -require_once(__DIR__ . "/../vendor/composer/vendor/autoload.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 + * + *********************************************************************/ + +require_once(__DIR__ . "/../artifacts/bootstrap.php"); require_once(__DIR__ . "/../ilias_version.php"); -// according to ./Services/Feeds/classes/class.ilExternalFeed.php: -if (!defined("MAGPIE_DIR")) { - define("MAGPIE_DIR", "./components/ILIAS/Feeds/magpierss/"); -} - -require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilSetupObjective.php"); -require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilSetupAgent.php"); -require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilSetupConfig.php"); -require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilMakeInstallationAccessibleObjective.php"); -require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilUseRootConfirmed.php"); -require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilOwnRiskConfirmedObjective.php"); -require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilOverwritesExistingInstallationConfirmed.php"); -require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilIniFilesPopulatedObjective.php"); -require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilIniFilesLoadedObjective.php"); -require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilNICKeyRegisteredObjective.php"); -require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilNICKeyStoredObjective.php"); -require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilSetupConfigStoredObjective.php"); -require_once(__DIR__ . "/../components/ILIAS/setup_/classes/class.ilSetupMetricsCollectedObjective.php"); - -use ILIAS\UI\Component\Input\Field\Factory as FieldFactory; -use ILIAS\UI\Component\Input\Field\File; -use ILIAS\UI\Component\Input\Field\Tag; -use ILIAS\UI\Component\Input\Field\UploadHandler; - -$c = build_container_for_setup($executed_in_directory); -$app = $c["app"]; -$app->run(); - -// ATTENTION: This is a hack to get around the usage of the echo/exit pattern in -// the setup for the command line version of the setup. Do not use this. -function setup_exit($message) -{ - if (!defined("ILIAS_SETUP_IGNORE_DB_UPDATE_STEP_MESSAGES") || !ILIAS_SETUP_IGNORE_DB_UPDATE_STEP_MESSAGES) { - throw new \ILIAS\Setup\UnachievableException($message); - } -} - -function build_container_for_setup(string $executed_in_directory): \Pimple\Container -{ - $c = new \Pimple\Container(); - - $c["app"] = function ($c) { - return new \ILIAS\Setup\CLI\App( - $c["command.install"], - $c["command.update"], - $c["command.build-artifacts"], - $c["command.achieve"], - $c["command.status"], - $c["command.migrate"] - ); - }; - $c["command.install"] = function ($c) { - return new \ILIAS\Setup\CLI\InstallCommand( - $c["agent_finder"], - $c["config_reader"], - $c["common_preconditions"] - ); - }; - $c["command.update"] = function ($c) { - return new \ILIAS\Setup\CLI\UpdateCommand( - $c["agent_finder"], - $c["config_reader"], - $c["common_preconditions"] - ); - }; - $c["command.build-artifacts"] = function ($c) { - return new \ILIAS\Setup\CLI\BuildArtifactsCommand( - $c["agent_finder"] - ); - }; - $c["command.achieve"] = function ($c) { - return new \ILIAS\Setup\CLI\AchieveCommand( - $c["agent_finder"], - $c["config_reader"], - $c["common_preconditions"], - $c["refinery"] - ); - }; - $c["command.status"] = function ($c) { - return new \ILIAS\Setup\CLI\StatusCommand( - $c["agent_finder"] - ); - }; - - $c["command.migrate"] = function ($c) { - return new \ILIAS\Setup\CLI\MigrateCommand( - $c["agent_finder"], - $c["common_preconditions"] - ); - }; - - $c["common_preconditions"] = function ($c) { - return [ - new \ilOwnRiskConfirmedObjective(), - new \ilUseRootConfirmed() - ]; - }; - - $c["common_agent"] = function ($c) { - return new \ilSetupAgent( - $c["refinery"], - $c["data_factory"] - ); - }; - - $c["agent_finder"] = function ($c) { - return new ILIAS\Setup\ImplementationOfAgentFinder( - $c["refinery"], - $c["data_factory"], - $c["lng"], - $c["interface_finder"], - [ - "common" => $c["common_agent"] - ] - ); - }; - - $c["refinery"] = function ($c) { - return new ILIAS\Refinery\Factory( - $c["data_factory"], - $c["lng"] - ); - }; - - $c["data_factory"] = function ($c) { - return new ILIAS\Data\Factory(); - }; - - $c["lng"] = function ($c) { - return new \ilSetupLanguage("en"); - }; - - $c["config_reader"] = function ($c) use ($executed_in_directory) { - return new \ILIAS\Setup\CLI\ConfigReader( - $c["json.parser"], - $executed_in_directory - ); - }; - - $c["interface_finder"] = function ($c) { - return new \ILIAS\Setup\ImplementationOfInterfaceFinder(); - }; - - $c["json.parser"] = function ($c) { - return new \Seld\JsonLint\JsonParser(); - }; - - return $c; -} +exit(entry_point("The ILIAS Setup")); diff --git a/components/ILIAS/Setup/Setup.php b/components/ILIAS/Setup/Setup.php index e31e6f9bc9ef..8c41b00e9597 100644 --- a/components/ILIAS/Setup/Setup.php +++ b/components/ILIAS/Setup/Setup.php @@ -20,6 +20,8 @@ namespace ILIAS; +use ILIAS\Component\EntryPoint; + class Setup implements Component\Component { public function init( @@ -32,6 +34,81 @@ public function init( array | \ArrayAccess &$pull, array | \ArrayAccess &$internal, ): void { - // ... + $contribute[EntryPoint::class] = fn() => + new \ILIAS\Setup\CLI\App( + $internal["command.install"], + $internal["command.update"], + $internal["command.build-artifacts"], + $internal["command.achieve"], + $internal["command.status"], + $internal["command.migrate"] + ); + + $internal["command.install"] = fn() => + new \ILIAS\Setup\CLI\InstallCommand( + $internal["agent_finder"], + $internal["config_reader"], + $internal["common_preconditions"] + ); + $internal["command.update"] = fn() => + new \ILIAS\Setup\CLI\UpdateCommand( + $internal["agent_finder"], + $internal["config_reader"], + $internal["common_preconditions"] + ); + $internal["command.build-artifacts"] = fn() => + new \ILIAS\Setup\CLI\BuildArtifactsCommand( + $internal["agent_finder"] + ); + $internal["command.achieve"] = fn() => + new \ILIAS\Setup\CLI\AchieveCommand( + $internal["agent_finder"], + $internal["config_reader"], + $internal["common_preconditions"], + $pull[\ILIAS\Refinery\Factory::class], + ); + $internal["command.status"] = fn() => + new \ILIAS\Setup\CLI\StatusCommand( + $internal["agent_finder"] + ); + $internal["command.migrate"] = fn() => + new \ILIAS\Setup\CLI\MigrateCommand( + $internal["agent_finder"], + $internal["common_preconditions"] + ); + + $internal["common_preconditions"] = fn() => + [ + new \ilOwnRiskConfirmedObjective(), + new \ilUseRootConfirmed() + ]; + + $internal["common_agent"] = fn() => + new \ilSetupAgent( + $pull[\ILIAS\Refinery\Factory::class], + $pull[\ILIAS\Data\Factory::class] + ); + + $internal["agent_finder"] = fn() => + new \ILIAS\Setup\ImplementationOfAgentFinder( + $pull[\ILIAS\Refinery\Factory::class], + $pull[\ILIAS\Data\Factory::class], + $use[\ILIAS\Language\Language::class], + $internal["interface_finder"], + [ + "common" => $internal["common_agent"] + ] + ); + + $internal["config_reader"] = fn() => + new \ILIAS\Setup\CLI\ConfigReader( + $internal["json.parser"] + ); + + $internal["interface_finder"] = fn() => + new \ILIAS\Setup\ImplementationOfInterfaceFinder(); + + $internal["json.parser"] = fn() => + new \Seld\JsonLint\JsonParser(); } } diff --git a/components/ILIAS/Setup/src/CLI/App.php b/components/ILIAS/Setup/src/CLI/App.php index bc02f2eb0cd9..02c2f5324420 100755 --- a/components/ILIAS/Setup/src/CLI/App.php +++ b/components/ILIAS/Setup/src/CLI/App.php @@ -22,21 +22,34 @@ use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; +use ILIAS\Component\Component; +use ILIAS\Component\EntryPoint; /** * The ILIAS-setup-console-application. * * TODO: Add some metainformation to the app, such as name. */ -class App extends Application +class App extends Application implements EntryPoint { public const NAME = "The ILIAS Setup"; - public function __construct(Command ...$commands) - { + public function __construct( + Command ...$commands + ) { parent::__construct(self::NAME); foreach ($commands as $c) { $this->add($c); } } + + public function getName(): string + { + return self::NAME; + } + + public function enter(): int + { + return $this->run(); + } } diff --git a/components/ILIAS/Setup/src/ImplementationOfAgentFinder.php b/components/ILIAS/Setup/src/ImplementationOfAgentFinder.php index 98cdf9e07687..21d9161e3d9b 100755 --- a/components/ILIAS/Setup/src/ImplementationOfAgentFinder.php +++ b/components/ILIAS/Setup/src/ImplementationOfAgentFinder.php @@ -25,28 +25,16 @@ class ImplementationOfAgentFinder implements AgentFinder { - protected Refinery $refinery; - protected Data\Factory $data_factory; - protected \ilSetupLanguage $lng; - protected ImplementationOfInterfaceFinder $interface_finder; - - protected array $predefined_agents; - /** * @var array $predefined_agents */ public function __construct( - Refinery $refinery, - Data\Factory $data_factory, - \ilSetupLanguage $lng, - ImplementationOfInterfaceFinder $interface_finder, - array $predefined_agents = [] + protected Refinery $refinery, + protected Data\Factory $data_factory, + protected \ILIAS\Language\Language $lng, + protected ImplementationOfInterfaceFinder $interface_finder, + protected array $predefined_agents = [] ) { - $this->refinery = $refinery; - $this->data_factory = $data_factory; - $this->lng = $lng; - $this->interface_finder = $interface_finder; - $this->predefined_agents = $predefined_agents; } /** diff --git a/dependency_resolution.php b/dependency_resolution.php index ca6c70863cc2..c7f5c33cd84e 100644 --- a/dependency_resolution.php +++ b/dependency_resolution.php @@ -12,5 +12,10 @@ // that have no explicit disambiguation. return [ - "*" => [] + "*" => [ + "\\ILIAS\Language\Language" => "ilSetupLanguage" + ], + "\\ILIAS\\Refinery" => [ + "\\ILIAS\Language\Language" => "myLanguage" + ] ];