Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

master export: add support for ilias 10 exports #460

Merged
merged 1 commit into from
Sep 4, 2024
Merged
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
2 changes: 1 addition & 1 deletion app/src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
28 changes: 6 additions & 22 deletions app/src/Commands/Instances/CreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -65,7 +67,8 @@ public function __construct(
Filesystem $filesystem,
Linux $linux,
ProjectConfig $project_config,
Writer $writer
Writer $writer,
IliasInfo $ilias_info
) {
parent::__construct();

Expand All @@ -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
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down
16 changes: 14 additions & 2 deletions app/src/Commands/Pack/ExportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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();

Expand All @@ -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
Expand Down Expand Up @@ -130,7 +134,13 @@ 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->filesystem->makeDirectoryRecursive($name . "/var/www/html/public");
$this->docker->copy($instance . "_" . $suffix, "/var/www/html/public/data", $name . "/var/www/html/public");
} 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");
}
Expand Down Expand Up @@ -268,12 +278,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");
Expand Down
74 changes: 49 additions & 25 deletions app/src/Commands/Pack/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public function execute(InputInterface $input, OutputInterface $output) : int

$output->writeln("Importing instance $instance");

if (! $this->filesystem->exists($path)) {
if (! $this->confirmCreateNewInstance($input, $output, $instance)) {
if (!$this->filesystem->exists($path)) {
if (!$this->confirmCreateNewInstance($input, $output, $instance)) {
$output->writeln("Import aborted!");
return Command::FAILURE;
}
Expand All @@ -107,22 +107,25 @@ public function execute(InputInterface $input, OutputInterface $output) : int
if ($this->filesystem->exists($unpacked . "/conf/project_config.json")) {
$project_config = $this->filesystem->readFromJsonFile($unpacked . "/conf/project_config.json");
$project_config = array_shift($project_config);
} else if ($this->filesystem->exists("$unpacked/$target/conf/doil.conf")) {
$unpacked = $unpacked . DIRECTORY_SEPARATOR . $target;
$project_config = $this->readOldProjectConfig("$unpacked/conf/doil.conf");
$sql_dump = $unpacked . DIRECTORY_SEPARATOR . "var/ilias/ilias.sql";
} else if ($this->filesystem->exists("$unpacked/conf/doil.conf")) {
$project_config = $this->readOldProjectConfig("$unpacked/conf/doil.conf");
$sql_dump = $unpacked . DIRECTORY_SEPARATOR . "var/ilias/ilias.sql";
} else {
throw new FileNotFoundException("Can not found doil config file in package.");
if ($this->filesystem->exists("$unpacked/$target/conf/doil.conf")) {
$unpacked = $unpacked . DIRECTORY_SEPARATOR . $target;
$project_config = $this->readOldProjectConfig("$unpacked/conf/doil.conf");
$sql_dump = $unpacked . DIRECTORY_SEPARATOR . "var/ilias/ilias.sql";
} else {
if ($this->filesystem->exists("$unpacked/conf/doil.conf")) {
$project_config = $this->readOldProjectConfig("$unpacked/conf/doil.conf");
$sql_dump = $unpacked . DIRECTORY_SEPARATOR . "var/ilias/ilias.sql";
} else {
throw new FileNotFoundException("Can not found doil config file in package.");
}
}
}

$repo = $this->repo_manager->getEmptyRepo();
$repo = $repo
->withName($instance . "_import")
->withUrl($project_config->getRepositoryUrl())
;
->withUrl($project_config->getRepositoryUrl());

$existing_repo = null;
if ($this->repo_manager->repoUrlExists($repo)) {
Expand All @@ -134,7 +137,7 @@ public function execute(InputInterface $input, OutputInterface $output) : int
}
}

if (! is_null($existing_repo)) {
if (!is_null($existing_repo)) {
$repo = $existing_repo;
} else {
if ($this->repo_manager->repoNameExists($repo)) {
Expand Down Expand Up @@ -200,10 +203,18 @@ public function execute(InputInterface $input, OutputInterface $output) : int
);
}

$this->filesystem->copyDirectory(
$unpacked . "/var/www/html/data",
$path . "/volumes/ilias/data")
;
if ($this->filesystem->exists($unpacked . "/var/www/html/data")) {
$this->filesystem->copyDirectory(
$unpacked . "/var/www/html/data",
$path . "/volumes/ilias/data");
} else if ($this->filesystem->exists($unpacked . "/var/www/html/public/data")) {
$this->filesystem->copyDirectory(
$unpacked . "/var/www/html/public/data",
$path . "/volumes/ilias/public/data");
} else {
throw new RuntimeException("Can not found unpacked data folder in package.");
}

$this->filesystem->copyDirectory(
$unpacked . "/var/ilias/data",
$path . "/volumes/data")
Expand Down Expand Up @@ -254,7 +265,7 @@ public function execute(InputInterface $input, OutputInterface $output) : int
"mysql ilias < /var/ilias/data/ilias.sql"
);

$location = $this->filesystem->searchForFileRecursive($path . "/volumes/ilias/data", "/client\.ini\.php/");
$location = $this->filesystem->searchForFileRecursive($path . "/volumes/ilias", "/client\.ini\.php/");

if (is_null($location)) {
$this->writer->error(
Expand All @@ -276,13 +287,26 @@ public function execute(InputInterface $input, OutputInterface $output) : int
$this->writer->endBlock();

$this->writer->beginBlock($output, "Apply ilias config");
$this->docker->executeCommand(
$path,
$instance,
"bash",
"-c",
"php /var/www/html/setup/setup.php update /var/ilias/data/ilias-config.json -y"
);
if ($this->filesystem->exists($path . "/var/www/html/setup/setup.php")) {
$this->docker->executeCommand(
$path,
$instance,
"bash",
"-c",
"php /var/www/html/setup/setup.php update /var/ilias/data/ilias-config.json -y"
);
} else if ($path . "/var/www/html/cli/setup.php") {
$this->docker->executeCommand(
$path,
$instance,
"bash",
"-c",
"php /var/www/html/cli/setup.php update /var/ilias/data/ilias-config.json -y"
);
} else {
throw new RuntimeException("Can not found setup.php.");
}

$this->writer->endBlock();

if ($this->docker->isInstanceUp($path)) {
Expand Down
32 changes: 8 additions & 24 deletions app/src/Commands/Pack/PackCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -65,7 +67,8 @@ public function __construct(
Filesystem $filesystem,
Linux $linux,
ProjectConfig $project_config,
Writer $writer
Writer $writer,
IliasInfo $ilias_info
) {
parent::__construct();

Expand All @@ -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
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions app/src/Lib/ILIAS/ILIAS.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php declare(strict_types=1);

/* Copyright (c) 2022 - Daniel Weise <[email protected]> - Extended GPL, see LICENSE */

namespace CaT\Doil\Lib\ILIAS;

interface ILIAS
{
public function getIliasVersion(string $path) : string;
}
39 changes: 39 additions & 0 deletions app/src/Lib/ILIAS/IliasInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php declare(strict_types=1);

/* Copyright (c) 2022 - Daniel Weise <[email protected]> - 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];
}
}
Loading
Loading