ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\Language\Activities\LanguageActivity Class Reference
+ Inheritance diagram for ILIAS\Language\Activities\LanguageActivity:
+ Collaboration diagram for ILIAS\Language\Activities\LanguageActivity:

Public Member Functions

 __construct (private readonly ?RBAC $rbac, private readonly LanguageFolder $language_folder, protected readonly DataFactory $data=new DataFactory(),)
 
 getType ()
 
 isAllowedToPerform (int $usr_id, mixed $parameters)
 This shall check if the given user is allowed to perform the activity based on business rules of this component. More...
 
 maybePerformAs (InputFactory $input_factory, int $usr_id, array $raw_parameters)
 Grinds the $raw_parameters through the input description, checks if the users is allowed to perform the action as requested and, if so, then attempts to performs it. More...
 
- Public Member Functions inherited from ILIAS\Component\Activities\ActivityImpl
 getName ()
 Shall return classname of the Activity, wrapped in Name. More...
 
- Public Member Functions inherited from ILIAS\Component\Activities\Activity
 getName ()
 Shall return classname of the Activity, wrapped in Name. More...
 
 getType ()
 
 getDescription ()
 
 getInputDescription (FieldFactory $f)
 
 getOutputDescription (Description\Factory $f)
 
 isAllowedToPerform (int $usr_id, mixed $parameters)
 This shall check if the given user is allowed to perform the activity based on business rules of this component. More...
 
 perform (mixed $parameters)
 This shall perform the activity. More...
 
 maybePerformAs (InputFactory $input_factory, int $usr_id, array $raw_parameters)
 Grinds the $raw_parameters through the input description, checks if the users is allowed to perform the action as requested and, if so, then attempts to performs it. More...
 

Protected Member Functions

 overlayWriteFailedOutputField (Description\Factory $f)
 The database was written, but the PO/MO overlay of a module was not: callers must not report plain success. More...
 
 invalidMarkupCustomizingOutputField (Description\Factory $f)
 
 duplicateCustomizingOutputField (Description\Factory $f)
 
 duplicateCustomizingEntries (array $skipped, array $language_keys)
 
 invalidMarkupCustomizingEntries (array $skipped, array $language_keys)
 
 normalizeParameters (array $grind_result)
 

Private Member Functions

 isKnownUser (int $usr_id)
 Never the anonymous user, regardless of its RBAC roles. More...
 

Detailed Description

Definition at line 34 of file LanguageActivity.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Language\Activities\LanguageActivity::__construct ( private readonly ?RBAC  $rbac,
private readonly LanguageFolder  $language_folder,
protected readonly DataFactory  $data = new DataFactory() 
)
Parameters
RBAC | null$rbacnull only for forSetup(); isAllowedToPerform() then throws.

Definition at line 39 of file LanguageActivity.php.

43 {
44 }

Member Function Documentation

◆ duplicateCustomizingEntries()

ILIAS\Language\Activities\LanguageActivity::duplicateCustomizingEntries ( array  $skipped,
array  $language_keys 
)
protected
Parameters
array<string,array<string,list<string>>>$skipped see \ILIAS\Language\Setup\LanguageInstallationManager::getSkippedDuplicateEntries()
list<string>$language_keys
Returns
list<string> the value of duplicateCustomizingOutputField()

Definition at line 108 of file LanguageActivity.php.

108 : array
109 {
110 $entries = [];
111 foreach ($language_keys as $language_key) {
112 foreach ($skipped[$language_key] ?? [] as $entry => $existing) {
113 $entries[] = $language_key . ': ' . DuplicateIdentifierMessage::entry((string) $entry, $existing);
114 }
115 }
116
117 return $entries;
118 }

References ILIAS\Language\ComponentTranslation\DuplicateIdentifierMessage\entry().

Referenced by ILIAS\Language\Tests\Activities\LanguageActivityInvalidMarkupTestDouble\duplicateEntries(), ILIAS\Language\Activities\InstallLanguage\perform(), and ILIAS\Language\Activities\UpdateLanguage\perform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ duplicateCustomizingOutputField()

ILIAS\Language\Activities\LanguageActivity::duplicateCustomizingOutputField ( Description\Factory  $f)
protected

Definition at line 85 of file LanguageActivity.php.

85 : Description\Description
86 {
87 $text = $this->data->text()->markdown();
88
89 return $f->list(
90 $text->simpleDocument(
91 'Entries of the customizing/local language files that were not applied because their ' .
92 'identifier already exists in another module or in another spelling - the languages ' .
93 'were installed regardless.'
94 ),
95 $f->string($text->simpleDocument(
96 'Language key and entry, followed by the entries it would duplicate ' .
97 '("<language>: <module>#:#<identifier> (<module>: <identifier>, ...)").'
98 ))
99 );
100 }
$text
Definition: xapiexit.php:21

References Vendor\Package\$f, and $text.

◆ getType()

ILIAS\Language\Activities\LanguageActivity::getType ( )

◆ invalidMarkupCustomizingEntries()

ILIAS\Language\Activities\LanguageActivity::invalidMarkupCustomizingEntries ( array  $skipped,
array  $language_keys 
)
protected
Parameters
array<string,array<string,list<string>>>$skipped see \ILIAS\Language\Setup\LanguageInstallationManager::getSkippedInvalidMarkupEntries()
list<string>$language_keys
Returns
list<string> the value of invalidMarkupCustomizingOutputField()

Definition at line 126 of file LanguageActivity.php.

126 : array
127 {
128 $policy = new TranslationMarkupPolicy();
129 $entries = [];
130 foreach ($language_keys as $language_key) {
131 foreach ($skipped[$language_key] ?? [] as $entry => $violations) {
132 $markup = $policy->markupOf(array_map('strval', $violations));
133 $entries[] = $language_key . ': ' . $entry . ($markup === [] ? '' : ': ' . implode(', ', $markup));
134 }
135 }
136
137 return $entries;
138 }

References $policy.

Referenced by ILIAS\Language\Tests\Activities\LanguageActivityInvalidMarkupTestDouble\entries(), ILIAS\Language\Activities\InstallLanguage\perform(), and ILIAS\Language\Activities\UpdateLanguage\perform().

+ Here is the caller graph for this function:

◆ invalidMarkupCustomizingOutputField()

ILIAS\Language\Activities\LanguageActivity::invalidMarkupCustomizingOutputField ( Description\Factory  $f)
protected

Definition at line 67 of file LanguageActivity.php.

67 : Description\Description
68 {
69 $text = $this->data->text()->markdown();
70
71 return $f->list(
72 $text->simpleDocument(
73 'Entries of the customizing/local language files that were not applied because their ' .
74 'value contains HTML that is not allowed in language texts - the languages were ' .
75 'installed regardless.'
76 ),
77 $f->string($text->simpleDocument(
78 'Language key and entry, followed by the markup that is not allowed, language-neutral ' .
79 '("<language>: <module>#:#<identifier>: <markup>, ..."; without violations only ' .
80 '"<language>: <module>#:#<identifier>").'
81 ))
82 );
83 }

References Vendor\Package\$f, and $text.

◆ isAllowedToPerform()

ILIAS\Language\Activities\LanguageActivity::isAllowedToPerform ( int  $usr_id,
mixed  $parameters 
)

This shall check if the given user is allowed to perform the activity based on business rules of this component.

This shall, for example, check if the given user may add this other user to a course based on RBAC and position permissions, but this shall not check overall business rules such as: root may do everything. This shall not cause any observable side effects.

Parameters
mixed$parameterswhatever the FormInput from getInputDescription produces.

Implements ILIAS\Component\Activities\Activity.

Definition at line 140 of file LanguageActivity.php.

140 : bool
141 {
142 if ($this->rbac === null) {
143 throw new \LogicException(
144 'RBAC is not available during Setup; '
145 . static::class . '::isAllowedToPerform() cannot be used here.'
146 );
147 }
148
149 if (!$this->isKnownUser($usr_id)) {
150 return false;
151 }
152
153 return $this->rbac->system()->checkAccessOfUser(
154 $usr_id,
155 'write',
156 $this->language_folder->getRefId()
157 );
158 }
isKnownUser(int $usr_id)
Never the anonymous user, regardless of its RBAC roles.

References ILIAS\Language\Activities\LanguageActivity\isKnownUser(), and ILIAS\Repository\rbac().

Referenced by ILIAS\Language\Activities\LanguageActivity\maybePerformAs().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isKnownUser()

ILIAS\Language\Activities\LanguageActivity::isKnownUser ( int  $usr_id)
private

Never the anonymous user, regardless of its RBAC roles.

Definition at line 161 of file LanguageActivity.php.

161 : bool
162 {
163 if ($usr_id <= 0) {
164 return false;
165 }
166
167 return !defined('ANONYMOUS_USER_ID') || $usr_id !== ANONYMOUS_USER_ID;
168 }
const ANONYMOUS_USER_ID
Definition: constants.php:27

References ANONYMOUS_USER_ID.

Referenced by ILIAS\Language\Activities\LanguageActivity\isAllowedToPerform().

+ Here is the caller graph for this function:

◆ maybePerformAs()

ILIAS\Language\Activities\LanguageActivity::maybePerformAs ( InputFactory  $input_factory,
int  $usr_id,
array  $raw_parameters 
)

Grinds the $raw_parameters through the input description, checks if the users is allowed to perform the action as requested and, if so, then attempts to performs it.

Wraps the result and possible errors in the Result type.

Implements ILIAS\Component\Activities\Activity.

Definition at line 170 of file LanguageActivity.php.

170 : Result
171 {
172 try {
173 // inside the try: getInputDescription() may throw too; value() throws grind's input error
175 $this->grind($this->getInputDescription($input_factory->field()), $raw_parameters)->value()
176 );
177 if (!$this->isAllowedToPerform($usr_id, $parameters)) {
178 return new Result\Error(
179 new \DomainException('You are not allowed to manage the languages of this installation.', 403)
180 );
181 }
182
183 // usr_id last: the trusted value wins over a spoofed form key
184 return new Result\Ok($this->perform([...$parameters, 'usr_id' => $usr_id]));
185 } catch (\Throwable $e) {
186 return new Result\Error(Failure::of($e));
187 }
188 }
static of(\Throwable $e)
Definition: Failure.php:29
isAllowedToPerform(int $usr_id, mixed $parameters)
This shall check if the given user is allowed to perform the activity based on business rules of this...
perform(mixed $parameters)
This shall perform the activity.

References Vendor\Package\$e, $parameters, ILIAS\Component\Activities\Activity\getInputDescription(), ILIAS\Language\Activities\LanguageActivity\isAllowedToPerform(), ILIAS\Language\Activities\LanguageActivity\normalizeParameters(), ILIAS\Language\Activities\Failure\of(), and ILIAS\Component\Activities\Activity\perform().

+ Here is the call graph for this function:

◆ normalizeParameters()

◆ overlayWriteFailedOutputField()

ILIAS\Language\Activities\LanguageActivity::overlayWriteFailedOutputField ( Description\Factory  $f)
protected

The database was written, but the PO/MO overlay of a module was not: callers must not report plain success.

Definition at line 52 of file LanguageActivity.php.

52 : Description\Description
53 {
54 $text = $this->data->text()->markdown();
55
56 return $f->list(
57 $text->simpleDocument(
58 'Languages whose database content was written, but for which the per-installation ' .
59 'PO/MO files of at least one module maintained in PO files could not be written ' .
60 '(typically missing write permissions of the web server user on the client data ' .
61 'directory) - the details are logged.'
62 ),
63 $f->string($text->simpleDocument('Language key of a language with an unwritten PO/MO overlay.'))
64 );
65 }

References Vendor\Package\$f, and $text.


The documentation for this class was generated from the following file: