diff --git a/app/src/App.php b/app/src/App.php index add20138..88a732ab 100644 --- a/app/src/App.php +++ b/app/src/App.php @@ -9,7 +9,7 @@ class App extends Application { - const NAME = "Doil Version 20240807 - build 2024-08-07"; + const NAME = "Doil Version 20240902 - build 2024-09-02"; public function __construct(Command ...$commands) { diff --git a/app/src/Commands/Instances/CreateCommand.php b/app/src/Commands/Instances/CreateCommand.php index 7f43a266..34119394 100644 --- a/app/src/Commands/Instances/CreateCommand.php +++ b/app/src/Commands/Instances/CreateCommand.php @@ -12,6 +12,7 @@ use CaT\Doil\Lib\Linux\Linux; use CaT\Doil\Lib\ProjectConfig; use CaT\Doil\Lib\Docker\Docker; +use CaT\Doil\Lib\ILIAS\IliasInfo; use CaT\Doil\Commands\Repo\RepoManager; use CaT\Doil\Lib\ConsoleOutput\Writer; use CaT\Doil\Lib\FileSystem\Filesystem; @@ -56,6 +57,7 @@ class CreateCommand extends Command protected Linux $linux; protected ProjectConfig $project_config; protected Writer $writer; + protected IliasInfo $ilias_info; public function __construct( Docker $docker, @@ -65,7 +67,8 @@ public function __construct( Filesystem $filesystem, Linux $linux, ProjectConfig $project_config, - Writer $writer + Writer $writer, + IliasInfo $ilias_info ) { parent::__construct(); @@ -77,6 +80,7 @@ public function __construct( $this->linux = $linux; $this->project_config = $project_config; $this->writer = $writer; + $this->ilias_info = $ilias_info; } public function configure() : void @@ -277,7 +281,7 @@ public function execute(InputInterface $input, OutputInterface $output) : int sleep(5); $this->writer->endBlock(); - $ilias_version = $this->getIliasVersion($instance_path); + $ilias_version = $this->ilias_info->getIliasVersion($instance_path); // set grains $this->writer->beginBlock($output, "Setting up instance configuration"); @@ -713,26 +717,6 @@ protected function getBranches(OutputInterface $output, string $path, string $ur return $branches; } - protected function getIliasVersion(string $path) : string - { - if ($this->filesystem->exists($path . "/volumes/ilias/include/inc.ilias_version.php")) { - $ilias_version_path = $path . "/volumes/ilias/include/inc.ilias_version.php"; - } else if ($this->filesystem->exists($path . "/volumes/ilias/ilias_version.php")) { - $ilias_version_path = $path . "/volumes/ilias/ilias_version.php"; - } else { - throw new RuntimeException("Can't detect ilias version!"); - } - - $ilias_version = $this->filesystem->getLineInFile( - $ilias_version_path, - "ILIAS_VERSION_NUMERIC" - ); - - preg_match("/\d+.\d/", $ilias_version, $version); - - return $version[0]; - } - protected function getComposerVersion(string $ilias_version) : string { if ($ilias_version > 6.9) { diff --git a/app/src/Commands/Pack/ExportCommand.php b/app/src/Commands/Pack/ExportCommand.php index 498d8063..43816f64 100644 --- a/app/src/Commands/Pack/ExportCommand.php +++ b/app/src/Commands/Pack/ExportCommand.php @@ -11,6 +11,7 @@ use CaT\Doil\Lib\Docker\Docker; use CaT\Doil\Lib\ProjectConfig; use CaT\Doil\Commands\Repo\Repo; +use CaT\Doil\Lib\ILIAS\IliasInfo; use CaT\Doil\Lib\ConsoleOutput\Writer; use CaT\Doil\Lib\FileSystem\Filesystem; use CaT\Doil\Commands\Repo\RepoManager; @@ -35,6 +36,7 @@ class ExportCommand extends Command protected ProjectConfig $project_config; protected Git $git; protected RepoManager $repo_manager; + protected IliasInfo $ilias_info; public function __construct( Docker $docker, @@ -43,7 +45,8 @@ public function __construct( Writer $writer, ProjectConfig $project_config, Git $git, - RepoManager $repo_manager + RepoManager $repo_manager, + IliasInfo $ilias_info ) { parent::__construct(); @@ -54,6 +57,7 @@ public function __construct( $this->project_config = $project_config; $this->git = $git; $this->repo_manager = $repo_manager; + $this->ilias_info = $ilias_info; } public function configure() : void @@ -130,7 +134,12 @@ public function execute(InputInterface $input, OutputInterface $output) : int $this->docker->copy($instance . "_" . $suffix, "/var/ilias", $name . "/var/"); $this->docker->copy($instance . "_" . $suffix, "/var/www/html/.git/config", $name . "/var/www/html/.git/config"); - $this->docker->copy($instance . "_" . $suffix, "/var/www/html/data", $name . "/var/www/html"); + if ($this->ilias_info->getIliasVersion($path) >= 10) { + $this->docker->copy($instance . "_" . $suffix, "/var/www/html/public/data", $name . "/var/www/html"); + } else { + $this->docker->copy($instance . "_" . $suffix, "/var/www/html/data", $name . "/var/www/html"); + } + if ($this->filesystem->exists($path . "/volumes/ilias/Customizing/global/skin")) { $this->docker->copy($instance . "_" . $suffix, "/var/www/html/Customizing/global/skin", $name . "/var/www/html/Customizing/global"); } @@ -268,12 +277,14 @@ protected function exportProjectConfig(OutputInterface $output, string $path, st return self::FAILURE; } + $local_cat_ilias_repos = []; if (count($local_repos) > 0) { $local_cat_ilias_repos = array_filter($local_repos, function(Repo $local_repo) { return strstr($local_repo->getUrl(), "conceptsandtraining") || strstr($local_repo->getUrl(), "ILIAS-eLearning"); }); } + $global_cat_ilias_repos = []; if (count($global_repos) > 0) { $global_cat_ilias_repos = array_filter($global_repos, function(Repo $local_repo) { return strstr($local_repo->getUrl(), "conceptsandtraining") || strstr($local_repo->getUrl(), "ILIAS-eLearning"); diff --git a/app/src/Commands/Pack/PackCreateCommand.php b/app/src/Commands/Pack/PackCreateCommand.php index bf9bcc16..c93b3cdc 100644 --- a/app/src/Commands/Pack/PackCreateCommand.php +++ b/app/src/Commands/Pack/PackCreateCommand.php @@ -7,13 +7,14 @@ use Closure; use RuntimeException; use CaT\Doil\Lib\Git\Git; -use CaT\Doil\Commands\Repo\Repo; use CaT\Doil\Lib\Posix\Posix; use CaT\Doil\Lib\Linux\Linux; use CaT\Doil\Lib\ProjectConfig; use CaT\Doil\Lib\Docker\Docker; -use CaT\Doil\Commands\Repo\RepoManager; +use CaT\Doil\Commands\Repo\Repo; +use CaT\Doil\Lib\ILIAS\IliasInfo; use CaT\Doil\Lib\ConsoleOutput\Writer; +use CaT\Doil\Commands\Repo\RepoManager; use CaT\Doil\Lib\FileSystem\Filesystem; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Question\Question; @@ -56,6 +57,7 @@ class PackCreateCommand extends Command protected Linux $linux; protected ProjectConfig $project_config; protected Writer $writer; + protected IliasInfo $ilias_info; public function __construct( Docker $docker, @@ -65,7 +67,8 @@ public function __construct( Filesystem $filesystem, Linux $linux, ProjectConfig $project_config, - Writer $writer + Writer $writer, + IliasInfo $ilias_info ) { parent::__construct(); @@ -77,6 +80,7 @@ public function __construct( $this->linux = $linux; $this->project_config = $project_config; $this->writer = $writer; + $this->ilias_info = $ilias_info; } public function configure() : void @@ -278,7 +282,7 @@ public function execute(InputInterface $input, OutputInterface $output) : int sleep(5); $this->writer->endBlock(); - $ilias_version = $this->getIliasVersion($instance_path); + $ilias_version = $this->ilias_info->getIliasVersion($instance_path); // set grains $this->writer->beginBlock($output, "Setting up instance configuration"); @@ -657,26 +661,6 @@ protected function getBranches(OutputInterface $output, string $path, string $ur return $branches; } - protected function getIliasVersion(string $path) : string - { - if ($this->filesystem->exists($path . "/volumes/ilias/include/inc.ilias_version.php")) { - $ilias_version_path = $path . "/volumes/ilias/include/inc.ilias_version.php"; - } else if ($this->filesystem->exists($path . "/volumes/ilias/ilias_version.php")) { - $ilias_version_path = $path . "/volumes/ilias/ilias_version.php"; - } else { - throw new RuntimeException("Can't detect ilias version!"); - } - - $ilias_version = $this->filesystem->getLineInFile( - $ilias_version_path, - "ILIAS_VERSION_NUMERIC" - ); - - preg_match("/\d+.\d/", $ilias_version, $version); - - return $version[0]; - } - protected function getComposerVersion(string $ilias_version) : string { if ($ilias_version > 6.9) { diff --git a/app/src/Lib/ILIAS/ILIAS.php b/app/src/Lib/ILIAS/ILIAS.php new file mode 100644 index 00000000..8442b688 --- /dev/null +++ b/app/src/Lib/ILIAS/ILIAS.php @@ -0,0 +1,10 @@ + - Extended GPL, see LICENSE */ + +namespace CaT\Doil\Lib\ILIAS; + +interface ILIAS +{ + public function getIliasVersion(string $path) : string; +} \ No newline at end of file diff --git a/app/src/Lib/ILIAS/IliasInfo.php b/app/src/Lib/ILIAS/IliasInfo.php new file mode 100644 index 00000000..24ebbe57 --- /dev/null +++ b/app/src/Lib/ILIAS/IliasInfo.php @@ -0,0 +1,39 @@ + - Extended GPL, see LICENSE */ + +namespace CaT\Doil\Lib\ILIAS; + +use RuntimeException; +use CaT\Doil\Lib\FileSystem\Filesystem; + +class IliasInfo implements ILIAS +{ + protected Filesystem $filesystem; + + public function __construct( + Filesystem $filesystem + ) { + $this->filesystem = $filesystem; + } + + public function getIliasVersion(string $path) : string + { + if ($this->filesystem->exists($path . "/volumes/ilias/include/inc.ilias_version.php")) { + $ilias_version_path = $path . "/volumes/ilias/include/inc.ilias_version.php"; + } else if ($this->filesystem->exists($path . "/volumes/ilias/ilias_version.php")) { + $ilias_version_path = $path . "/volumes/ilias/ilias_version.php"; + } else { + throw new RuntimeException("Can't detect ilias version!"); + } + + $ilias_version = $this->filesystem->getLineInFile( + $ilias_version_path, + "ILIAS_VERSION_NUMERIC" + ); + + preg_match("/\d+.\d/", $ilias_version, $version); + + return $version[0]; + } +} \ No newline at end of file diff --git a/app/src/cli.php b/app/src/cli.php index 20655eeb..f53b5e19 100644 --- a/app/src/cli.php +++ b/app/src/cli.php @@ -13,6 +13,7 @@ use CaT\Doil\Lib\Git\GitShell; use CaT\Doil\Lib\ProjectConfig; use CaT\Doil\Commands\Instances; +use CaT\Doil\Lib\ILIAS\IliasInfo; use CaT\Doil\Lib\Posix\PosixShell; use CaT\Doil\Lib\Linux\LinuxShell; use CaT\Doil\Lib\Docker\DockerShell; @@ -86,6 +87,12 @@ function buildContainerForApp() : Container ); }; + $c["ilias.info"] = function($c) { + return new IliasInfo( + $c["filesystem.shell"] + ); + }; + $c["git.shell"] = function($c) { return new GitShell( $c["logger"] @@ -152,7 +159,8 @@ function buildContainerForApp() : Container $c["filesystem.shell"], $c["linux.shell"], $c["project.config"], - $c["command.writer"] + $c["command.writer"], + $c["ilias.info"] ); }; @@ -284,7 +292,8 @@ function buildContainerForApp() : Container $c["command.writer"], $c["project.config"], $c["git.shell"], - $c["repo.manager"] + $c["repo.manager"], + $c["ilias.info"] ); }; @@ -307,7 +316,8 @@ function buildContainerForApp() : Container $c["filesystem.shell"], $c["linux.shell"], $c["project.config"], - $c["command.writer"] + $c["command.writer"], + $c["ilias.info"] ); }; diff --git a/app/tests/Commands/Instances/CreateCommandTest.php b/app/tests/Commands/Instances/CreateCommandTest.php index 9b77cf08..a381f175 100644 --- a/app/tests/Commands/Instances/CreateCommandTest.php +++ b/app/tests/Commands/Instances/CreateCommandTest.php @@ -10,6 +10,7 @@ use CaT\Doil\Lib\Docker\Docker; use PHPUnit\Framework\TestCase; use CaT\Doil\Lib\ProjectConfig; +use CaT\Doil\Lib\ILIAS\IliasInfo; use CaT\Doil\Lib\ConsoleOutput\Writer; use CaT\Doil\Lib\FileSystem\Filesystem; use CaT\Doil\Commands\Repo\RepoManager; @@ -60,6 +61,7 @@ public function test_execute_with_wrong_chars_in_instance_param() : void $linux = $this->createMock(Linux::class); $project_config = $this->createMock(ProjectConfig::class); $writer = new CommandWriter(); + $ilias_info = $this->createMock(IliasInfo::class); $command = new CreateCommandWrapper( $docker, @@ -69,7 +71,8 @@ public function test_execute_with_wrong_chars_in_instance_param() : void $filesystem, $linux, $project_config, - $writer + $writer, + $ilias_info ); $tester = new CommandTester($command); $app = new Application("doil"); @@ -90,6 +93,7 @@ public function test_execute_with_no_repo_param() : void $linux = $this->createMock(Linux::class); $project_config = $this->createMock(ProjectConfig::class); $writer = new CommandWriter(); + $ilias_info = $this->createMock(IliasInfo::class); $command = new CreateCommand( $docker, @@ -99,7 +103,8 @@ public function test_execute_with_no_repo_param() : void $filesystem, $linux, $project_config, - $writer + $writer, + $ilias_info ); $tester = new CommandTester($command); $app = new Application("doil"); @@ -120,6 +125,7 @@ public function test_execute_with_wrong_formatted_phpversion_param() : void $linux = $this->createMock(Linux::class); $project_config = $this->createMock(ProjectConfig::class); $writer = new CommandWriter(); + $ilias_info = $this->createMock(IliasInfo::class); $command = new CreateCommand( $docker, @@ -129,7 +135,8 @@ public function test_execute_with_wrong_formatted_phpversion_param() : void $filesystem, $linux, $project_config, - $writer + $writer, + $ilias_info ); $tester = new CommandTester($command); $app = new Application("doil"); @@ -156,6 +163,7 @@ public function test_execute_with_non_existing_target() : void $linux = $this->createMock(Linux::class); $project_config = $this->createMock(ProjectConfig::class); $writer = new CommandWriter(); + $ilias_info = $this->createMock(IliasInfo::class); $command = new CreateCommand( $docker, @@ -165,7 +173,8 @@ public function test_execute_with_non_existing_target() : void $filesystem, $linux, $project_config, - $writer + $writer, + $ilias_info ); $tester = new CommandTester($command); $app = new Application("doil"); @@ -199,6 +208,7 @@ public function test_execute_with_no_write_access_on_target() : void $linux = $this->createMock(Linux::class); $project_config = $this->createMock(ProjectConfig::class); $writer = new CommandWriter(); + $ilias_info = $this->createMock(IliasInfo::class); $command = new CreateCommand( $docker, @@ -208,7 +218,8 @@ public function test_execute_with_no_write_access_on_target() : void $filesystem, $linux, $project_config, - $writer + $writer, + $ilias_info ); $tester = new CommandTester($command); $app = new Application("doil"); @@ -249,6 +260,7 @@ public function test_execute_with_no_write_access_on_target_by_param() : void $linux = $this->createMock(Linux::class); $project_config = $this->createMock(ProjectConfig::class); $writer = new CommandWriter(); + $ilias_info = $this->createMock(IliasInfo::class); $command = new CreateCommandWrapper( $docker, @@ -258,7 +270,8 @@ public function test_execute_with_no_write_access_on_target_by_param() : void $filesystem, $linux, $project_config, - $writer + $writer, + $ilias_info ); $tester = new CommandTester($command); $app = new Application("doil"); @@ -293,6 +306,7 @@ public function test_execute() : void $linux = $this->createMock(Linux::class); $project_config = $this->createMock(ProjectConfig::class); $writer = $this->createMock(Writer::class); + $ilias_info = $this->createMock(IliasInfo::class); $command = new CreateCommandWrapper( $docker, @@ -302,7 +316,8 @@ public function test_execute() : void $filesystem, $linux, $project_config, - $writer + $writer, + $ilias_info ); $tester = new CommandTester($command); $app = new Application("doil"); diff --git a/app/tests/Commands/Pack/ExportCommandTest.php b/app/tests/Commands/Pack/ExportCommandTest.php index c9d86422..6d8c11ff 100644 --- a/app/tests/Commands/Pack/ExportCommandTest.php +++ b/app/tests/Commands/Pack/ExportCommandTest.php @@ -8,6 +8,7 @@ use PHPUnit\Framework\TestCase; use CaT\Doil\Lib\Docker\Docker; use CaT\Doil\Lib\ProjectConfig; +use CaT\Doil\Lib\ILIAS\IliasInfo; use CaT\Doil\Lib\FileSystem\Filesystem; use CaT\Doil\Commands\Repo\RepoManager; use CaT\Doil\Lib\ConsoleOutput\CommandWriter; @@ -24,8 +25,18 @@ public function test_execute_without_instance_param() : void $git = $this->createMock(Git::class); $repo_manager = $this->createMock(RepoManager::class); $writer = new CommandWriter(); - - $command = new ExportCommand($docker, $posix, $filesystem, $writer, $project_config, $git, $repo_manager); + $ilias_info = $this->createMock(IliasInfo::class); + + $command = new ExportCommand( + $docker, + $posix, + $filesystem, + $writer, + $project_config, + $git, + $repo_manager, + $ilias_info + ); $tester = new CommandTester($command); $this->expectException(RuntimeException::class); @@ -42,8 +53,18 @@ public function test_execute_with_empty_instance_param() : void $git = $this->createMock(Git::class); $repo_manager = $this->createMock(RepoManager::class); $writer = new CommandWriter(); - - $command = new ExportCommand($docker, $posix, $filesystem, $writer, $project_config, $git, $repo_manager); + $ilias_info = $this->createMock(IliasInfo::class); + + $command = new ExportCommand( + $docker, + $posix, + $filesystem, + $writer, + $project_config, + $git, + $repo_manager, + $ilias_info + ); $tester = new CommandTester($command); $this->expectException(RuntimeException::class); @@ -60,8 +81,18 @@ public function test_execute_with_wrong_chars_in_instance_param() : void $git = $this->createMock(Git::class); $repo_manager = $this->createMock(RepoManager::class); $writer = new CommandWriter(); - - $command = new ExportCommand($docker, $posix, $filesystem, $writer, $project_config, $git, $repo_manager); + $ilias_info = $this->createMock(IliasInfo::class); + + $command = new ExportCommand( + $docker, + $posix, + $filesystem, + $writer, + $project_config, + $git, + $repo_manager, + $ilias_info + ); $tester = new CommandTester($command); $this->expectException(RuntimeException::class); @@ -78,8 +109,18 @@ public function test_execute_with_no_docker_compose_file() : void $git = $this->createMock(Git::class); $repo_manager = $this->createMock(RepoManager::class); $writer = new CommandWriter(); - - $command = new ExportCommand($docker, $posix, $filesystem, $writer, $project_config, $git, $repo_manager); + $ilias_info = $this->createMock(IliasInfo::class); + + $command = new ExportCommand( + $docker, + $posix, + $filesystem, + $writer, + $project_config, + $git, + $repo_manager, + $ilias_info + ); $tester = new CommandTester($command); $posix diff --git a/setup/updates/update-20240902.sh b/setup/updates/update-20240902.sh new file mode 100644 index 00000000..18ad275f --- /dev/null +++ b/setup/updates/update-20240902.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +doil_update_20240902() { + cp -r ${SCRIPT_DIR}/../app/src/* /usr/local/lib/doil/app/src/ + return $? +} \ No newline at end of file