ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilLanguageMetricsCollectedObjective.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 use ILIAS\Setup;
23 
24 class ilLanguageMetricsCollectedObjective extends Setup\Metrics\CollectedObjective
25 {
26  protected \ilSetupLanguage $il_setup_language;
27 
28  public function __construct(
29  Setup\Metrics\Storage $storage,
30  \ilSetupLanguage $il_setup_language
31  ) {
32  parent::__construct($storage);
33  $this->il_setup_language = $il_setup_language;
34  }
35 
39  protected function getTentativePreconditions(Setup\Environment $environment): array
40  {
41  return [
44  ];
45  }
46 
50  protected function collectFrom(Setup\Environment $environment, Setup\Metrics\Storage $storage): void
51  {
52  $client_ini = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_INI);
53  if ($client_ini) {
54  $storage->storeConfigText(
55  "default_language",
56  $client_ini->readVariable("language", "default"),
57  "The language that is used by default."
58  );
59  }
60 
61  $db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
62  if (!($db instanceof \ilDBInterface)) {
63  return;
64  }
65  $this->il_setup_language->setDbHandler($db);
66 
67  // TODO: Remove this once ilSetupLanguage (or a successor) supports proper
68  // DI for all methods.
69  $GLOBALS["ilDB"] = $db;
70 
71  $installed_languages = [];
72  $local_languages = $this->il_setup_language->getLocalLanguages();
73  foreach ($this->il_setup_language->getInstalledLanguages() as $lang) {
74  $local_file = new Setup\Metrics\Metric(
75  Setup\Metrics\Metric::STABILITY_STABLE,
76  Setup\Metrics\Metric::TYPE_BOOL,
77  in_array($lang, $local_languages, true),
78  "Is there a local language file for the language?"
79  );
80  $local_changes = new Setup\Metrics\Metric(
81  Setup\Metrics\Metric::STABILITY_STABLE,
82  Setup\Metrics\Metric::TYPE_BOOL,
83  count($this->il_setup_language->getLocalChanges($lang)) > 0,
84  "Are there local changes for the language?"
85  );
86  $installed_languages[$lang] = new Setup\Metrics\Metric(
87  Setup\Metrics\Metric::STABILITY_STABLE,
88  Setup\Metrics\Metric::TYPE_COLLECTION,
89  [
90  "local_file" => $local_file,
91  "local_changes" => $local_changes
92  ]
93  );
94  }
95  $installed_languages = new Setup\Metrics\Metric(
96  Setup\Metrics\Metric::STABILITY_STABLE,
97  Setup\Metrics\Metric::TYPE_COLLECTION,
98  $installed_languages
99  );
100  $storage->store(
101  "installed_languages",
102  $installed_languages
103  );
104  }
105 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
__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:26
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)