ILIAS  trunk Revision v11.0_alpha-2645-g16283d3b3f8
class.ilDefaultLanguageSetObjective.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 use ILIAS\Setup;
22 
24 {
28  public function getHash(): string
29  {
30  return hash(
31  "sha256",
32  self::class . "::en"
33  );
34  }
35 
39  public function getLabel(): string
40  {
41  return "Set default language to en";
42  }
43 
47  public function isNotable(): bool
48  {
49  return true;
50  }
51 
55  public function getPreconditions(Setup\Environment $environment): array
56  {
57  return [
58  new \ilIniFilesLoadedObjective(),
59  new \ilSettingsFactoryExistsObjective()
60  ];
61  }
62 
66  public function achieve(Setup\Environment $environment): Setup\Environment
67  {
68  $factory = $environment->getResource(Setup\Environment::RESOURCE_SETTINGS_FACTORY);
69 
70  $settings = $factory->settingsFor("common");
71  $settings->set("language", "en");
72 
73  $client_ini = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_INI);
74  $client_ini->setVariable("language", "default", "en");
75 
76  if (!$client_ini->write()) {
77  throw new Setup\UnachievableException("Could not write client.ini.php");
78  }
79 
80  return $environment;
81  }
82 
86  public function isApplicable(Setup\Environment $environment): bool
87  {
88  $factory = $environment->getResource(Setup\Environment::RESOURCE_SETTINGS_FACTORY);
89  $client_ini = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_INI);
90  $settings = $factory->settingsFor("common");
91 
92  return
93  $settings->get("language") !== "en" ||
94  $client_ini->readVariable("language", "default") !== "en";
95  }
96 }
getPreconditions(Setup\Environment $environment)
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An environment holds resources to be used in the setup process.
Definition: Environment.php:27
isApplicable(Setup\Environment $environment)