ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
UpdateLanguage.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28
30{
32
34 public function __construct(
35 ?RBAC $rbac,
36 private readonly \ilSetupLanguage $setup_language,
37 LanguageFolder $language_folder,
38 private readonly ?RepositoryProvider $repository = null,
39 ) {
40 parent::__construct($rbac, $language_folder);
41 }
42
43 public static function forSetup(\ilSetupLanguage $setup_language): self
44 {
45 return new self(
46 null,
47 $setup_language,
48 // never read: without RBAC, isAllowedToPerform() throws first
50 );
51 }
52
54 {
55 return $this->data->text()->markdown()->simpleDocument(
56 <<<'MARKDOWN'
57Refreshes one or more already installed languages, re-seeding their base
58data (plus a customizing/local file if one exists) from the current
59language files; the language files of the active plugins are applied again.
60A language that is not installed is left completely untouched - use
61InstallLanguage to install it first.
62MARKDOWN
63 );
64 }
65
66 protected function inputSectionTitle(): string
67 {
68 return 'Update languages';
69 }
70
72 {
73 $text = $this->data->text()->markdown();
74
75 return $f->object(
76 $text->simpleDocument('Result of the language update.'),
77 [
78 'updated_language_keys' => $f->list(
79 $text->simpleDocument(
80 'Already installed languages that were refreshed from the current ' .
81 'language files (base data, plus a customizing/local file if one exists).'
82 ),
83 $f->string($text->simpleDocument('Language key of a refreshed language.'))
84 ),
85 'not_installed_language_keys' => $f->list(
86 $text->simpleDocument(
87 'Requested languages that are not installed - skipped entirely, since ' .
88 'there is nothing installed yet to refresh. Use InstallLanguage to ' .
89 'install them first.'
90 ),
91 $f->string($text->simpleDocument('Language key of a not-yet-installed language.'))
92 ),
93 'overlay_write_failed_language_keys' => $this->overlayWriteFailedOutputField($f),
94 'invalid_markup_customizing_entries' => $this->invalidMarkupCustomizingOutputField($f),
95 'duplicate_customizing_entries' => $this->duplicateCustomizingOutputField($f),
96 ]
97 );
98 }
99
100 public function perform(mixed $parameters): array
101 {
102 if (!is_array($parameters)) {
103 throw new InvalidInputException('Parameters must be an array.');
104 }
105
106 $language_keys = $this->toLanguageKeyList($parameters['language_keys'] ?? null);
107
108 $currently_installed_language_keys = $this->setup_language->getInstalledLanguages();
109
110 $to_update = [];
111 $not_installed_no_op = [];
112
113 foreach ($language_keys as $language_key) {
114 if (in_array($language_key, $currently_installed_language_keys, true)) {
115 $to_update[] = $language_key;
116 } else {
117 $not_installed_no_op[] = $language_key;
118 }
119 }
120
121 $error_language_keys = [];
122 foreach ($to_update as $language_key) {
123 if (!$this->setup_language->checkLanguageForInstallation($language_key)) {
124 $error_language_keys[] = $language_key;
125 }
126 }
127
128 if ($error_language_keys !== []) {
129 throw new InvalidLanguageFilesException($error_language_keys);
130 }
131
132 $overlay_write_failed_language_keys = [];
133 if ($to_update !== []) {
134 $db_languages = $this->setup_language->getAvailableLanguagesForInstallation();
135 $local_language_keys = $this->setup_language->getLocalLanguages();
136
137 foreach ($to_update as $language_key) {
138 $this->setup_language->flushLanguageForInstallation($language_key);
139 if ($this->setup_language->insertLanguageForInstallation($language_key) !== []) {
140 $overlay_write_failed_language_keys[] = $language_key;
141 }
142 $this->setup_language->registerInstalledLanguage($language_key, $db_languages, $local_language_keys);
143 }
144
145 // plugin language files are flushed with the rest, so re-apply them
146 $this->repository?->refreshPlugins($to_update);
147 }
148
149 return [
150 'updated_language_keys' => $to_update,
151 'not_installed_language_keys' => $not_installed_no_op,
152 'overlay_write_failed_language_keys' => $overlay_write_failed_language_keys,
153 'invalid_markup_customizing_entries' => $this->invalidMarkupCustomizingEntries(
154 $this->setup_language->getSkippedInvalidMarkupEntries(),
155 $to_update
156 ),
157 'duplicate_customizing_entries' => $this->duplicateCustomizingEntries(
158 $this->setup_language->getSkippedDuplicateEntries(),
159 $to_update
160 ),
161 ];
162 }
163}
This describes some datastructure in terms of standard data structures such as primitives,...
Definition: Description.php:33
A state of the server, not of the call: 409, so Failure::of() passes it on and the GUI can name the l...
duplicateCustomizingEntries(array $skipped, array $language_keys)
invalidMarkupCustomizingEntries(array $skipped, array $language_keys)
Every legacy and repository access of the runtime language activities.
__construct(?RBAC $rbac, private readonly \ilSetupLanguage $setup_language, LanguageFolder $language_folder, private readonly ?RepositoryProvider $repository=null,)
static forSetup(\ilSetupLanguage $setup_language)
getOutputDescription(Description\Factory $f)
perform(mixed $parameters)
This shall perform the activity.
Looks the ref_id up on every call, so it can be built at build time without database access.
language handling for setup
Public RBAC service of the AccessControl component.
Definition: RBAC.php:30
The language folder in the administration, whose "write" permission guards the language Activities.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
to(\GdImage $image, ?int $quality=null)
Currently this is the only way to make a FileStream from a GD image resource.
$text
Definition: xapiexit.php:21