ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilLanguageMetricsCollectedObjective.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 use ILIAS\Setup;
22 
23 class ilLanguageMetricsCollectedObjective extends Setup\Metrics\CollectedObjective
24 {
25  protected \ilSetupLanguage $il_setup_language;
26 
27  public function __construct(
28  Setup\Metrics\Storage $storage,
29  \ilSetupLanguage $il_setup_language
30  ) {
31  parent::__construct($storage);
32  $this->il_setup_language = $il_setup_language;
33  }
34 
38  protected function getTentativePreconditions(Setup\Environment $environment): array
39  {
40  return [
43  ];
44  }
45 
49  protected function collectFrom(Setup\Environment $environment, Setup\Metrics\Storage $storage): void
50  {
51  $client_ini = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_INI);
52  if ($client_ini) {
53  $storage->storeConfigText(
54  "default_language",
55  $client_ini->readVariable("language", "default"),
56  "The language that is used by default."
57  );
58  }
59 
60  $db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
61  if (!($db instanceof \ilDBInterface)) {
62  return;
63  }
64  $this->il_setup_language->setDbHandler($db);
65 
66  // TODO: Remove this once ilSetupLanguage (or a successor) supports proper
67  // DI for all methods.
68  $GLOBALS["ilDB"] = $db;
69 
70  $installed_languages = [];
71  $local_languages = $this->il_setup_language->getLocalLanguages();
72  foreach ($this->il_setup_language->getInstalledLanguages() as $lang) {
73  $local_file = new Setup\Metrics\Metric(
74  Setup\Metrics\Metric::STABILITY_STABLE,
75  Setup\Metrics\Metric::TYPE_BOOL,
76  in_array($lang, $local_languages, true),
77  "Is there a local language file for the language?"
78  );
79  $local_changes = new Setup\Metrics\Metric(
80  Setup\Metrics\Metric::STABILITY_STABLE,
81  Setup\Metrics\Metric::TYPE_BOOL,
82  count($this->il_setup_language->getLocalChanges($lang)) > 0,
83  "Are there local changes for the language?"
84  );
85  $installed_languages[$lang] = new Setup\Metrics\Metric(
86  Setup\Metrics\Metric::STABILITY_STABLE,
87  Setup\Metrics\Metric::TYPE_COLLECTION,
88  [
89  "local_file" => $local_file,
90  "local_changes" => $local_changes
91  ]
92  );
93  }
94  $installed_languages = new Setup\Metrics\Metric(
95  Setup\Metrics\Metric::STABILITY_STABLE,
96  Setup\Metrics\Metric::TYPE_COLLECTION,
97  $installed_languages
98  );
99  $storage->store(
100  "installed_languages",
101  $installed_languages
102  );
103  }
104 }
language handling for setup
Storage is simple key/value store without further schema definition.
Definition: Storage.php:29
$GLOBALS["DIC"]
Definition: wac.php:53
__construct(Setup\Metrics\Storage $storage, \ilSetupLanguage $il_setup_language)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$lang
Definition: xapiexit.php:25
An environment holds resources to be used in the setup process.
Definition: Environment.php:27
__construct(Container $dic, ilPlugin $plugin)
collectFrom(Setup\Environment $environment, Setup\Metrics\Storage $storage)