ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
ILIAS\Administration\Setup\Objective\DropPermissions Class Reference
+ Inheritance diagram for ILIAS\Administration\Setup\Objective\DropPermissions:
+ Collaboration diagram for ILIAS\Administration\Setup\Objective\DropPermissions:

Public Member Functions

 __construct (private string $type, private array $operations, private array $additional_preconditions=[])
 
 getHash ()
 Get a hash for this objective. More...
 
 getLabel ()
 Get a label that describes this objective. More...
 
 isNotable ()
 Get to know if this is an interesting objective for a human. More...
 
 getPreconditions (Environment $environment)
 Objectives might depend on other objectives. More...
 
 achieve (Environment $environment)
 Objectives can be achieved. More...
 
 isApplicable (Environment $environment)
 Get to know whether the objective is applicable. More...
 
 getHash ()
 Get a hash for this objective. More...
 
 getLabel ()
 Get a label that describes this objective. More...
 
 isNotable ()
 Get to know if this is an interesting objective for a human. More...
 
 getPreconditions (Environment $environment)
 Objectives might depend on other objectives. More...
 
 achieve (Environment $environment)
 Objectives can be achieved. More...
 
 isApplicable (Environment $environment)
 Get to know whether the objective is applicable. More...
 

Private Member Functions

 operations (Environment $environment)
 
 firstRefIdOfType (ilDBInterface $db, string $type)
 

Detailed Description

Definition at line 32 of file DropPermissions.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Administration\Setup\Objective\DropPermissions::__construct ( private string  $type,
private array  $operations,
private array  $additional_preconditions = [] 
)
Parameters
int[]$operations
Objective[]$additional_preconditions

Definition at line 38 of file DropPermissions.php.

42 {
43 }

Member Function Documentation

◆ achieve()

ILIAS\Administration\Setup\Objective\DropPermissions::achieve ( Environment  $environment)

Objectives can be achieved.

They might add resources to the environment when they have been achieved.

This method needs to be idempotent for a given environment. That means: if this is executed a second time, nothing new should happen. Or the other way round: if the environment already looks like desired, the objective should not take any further actions when this is called.

Exceptions

LogicException if there are unfullfilled preconditions.

Exceptions

RuntimeException if there are missing resources.

Implements ILIAS\Setup\Objective.

Definition at line 68 of file DropPermissions.php.

69 {
71 $operations = $this->operations($environment);
72 $ref_id = $this->firstRefIdOfType($db, $this->type);
73 if (!$ref_id) {
74 return $environment;
75 }
76
77 foreach ($operations as $operation) {
78 $objective = new ilAccessRBACOperationDeletedObjective($this->type, $operation);
79 $objective->achieve($environment);
80 }
81
82 // rbac_pa is not cleanup by ilAccessRBACOperationDeletedObjective::class.
83 $update_row = $db->prepare('UPDATE rbac_pa SET ops_id = ? WHERE rol_id = ? AND ref_id = ?', [ilDBConstants::T_TEXT, ilDBConstants::T_INTEGER]);
84 $delete_row = $db->prepare('DELETE FROM rbac_pa WHERE rol_id = ? AND ref_id = ?', [ilDBConstants::T_INTEGER, ilDBConstants::T_INTEGER]);
85 foreach ($db->fetchAll($db->queryF('SELECT * FROM rbac_pa WHERE ref_id = %s', [ilDBConstants::T_INTEGER], [$ref_id])) as $row) {
86 $ops_id = unserialize($row['ops_id'], ['allowed_classes' => false]);
87 $ops_id = array_values(array_filter($ops_id, fn($op) => !in_array($op, $operations, false)));
88 if ($ops_id === []) {
89 $db->execute($delete_row, [$row['rol_id'], $ref_id]);
90 } else {
91 $db->execute($update_row, [serialize($ops_id), $row['rol_id'], $ref_id]);
92 }
93 }
94
95 return $environment;
96 }
An environment holds resources to be used in the setup process.
Definition: Environment.php:28
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
$ref_id
Definition: ltiauth.php:66

References ILIAS\$db, $ref_id, ILIAS\Administration\Setup\Objective\DropPermissions\firstRefIdOfType(), ILIAS\Setup\Environment\getResource(), ILIAS\Administration\Setup\Objective\DropPermissions\operations(), ILIAS\Setup\Environment\RESOURCE_DATABASE, ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

+ Here is the call graph for this function:

◆ firstRefIdOfType()

ILIAS\Administration\Setup\Objective\DropPermissions::firstRefIdOfType ( ilDBInterface  $db,
string  $type 
)
private

Definition at line 121 of file DropPermissions.php.

121 : int
122 {
123 $ref_query = 'SELECT ref_id FROM object_reference AS r INNER JOIN object_data AS o ON r.obj_id = o.obj_id where type = %s';
124 return (int) ($db->fetchAssoc($db->queryF($ref_query, [ilDBConstants::T_TEXT], [$type]))['ref_id'] ?? 0);
125 }

References ILIAS\$db, and ilDBConstants\T_TEXT.

Referenced by ILIAS\Administration\Setup\Objective\DropPermissions\achieve().

+ Here is the caller graph for this function:

◆ getHash()

ILIAS\Administration\Setup\Objective\DropPermissions::getHash ( )

Get a hash for this objective.

The hash of two objectives must be the same, if they are the same objective, with the same config on the same environment, i.e. if the one is achieved the other is achieved as well because they are the same.

Implements ILIAS\Setup\Objective.

Definition at line 45 of file DropPermissions.php.

45 : string
46 {
47 return hash("sha256", self::class . $this->type . ',' . join(',', $this->operations));
48 }

References ILIAS\Administration\Setup\Objective\DropPermissions\operations().

+ Here is the call graph for this function:

◆ getLabel()

ILIAS\Administration\Setup\Objective\DropPermissions::getLabel ( )

Get a label that describes this objective.

Implements ILIAS\Setup\Objective.

Definition at line 50 of file DropPermissions.php.

50 : string
51 {
52 return 'Drop permissions ' . join(', ', $this->operations) . ' from ' . $this->type;
53 }

References ILIAS\Administration\Setup\Objective\DropPermissions\operations().

+ Here is the call graph for this function:

◆ getPreconditions()

ILIAS\Administration\Setup\Objective\DropPermissions::getPreconditions ( Environment  $environment)

Objectives might depend on other objectives.

Exceptions
UnachievableExceptionif the objective is not achievable
Returns
Objective[]

Implements ILIAS\Setup\Objective.

Definition at line 60 of file DropPermissions.php.

60 : array
61 {
62 return [
64 ...$this->additional_preconditions,
65 ];
66 }

◆ isApplicable()

ILIAS\Administration\Setup\Objective\DropPermissions::isApplicable ( Environment  $environment)

Get to know whether the objective is applicable.

Don't change the environment or cause changes on services in the environment. Just check if this objective needs to be achieved, either currently or at all. In case of doubt whether the objective is applicable or not return true.

Implements ILIAS\Setup\Objective.

Definition at line 98 of file DropPermissions.php.

98 : bool
99 {
100 return $this->operations($environment) !== [];
101 }

References ILIAS\Administration\Setup\Objective\DropPermissions\operations().

+ Here is the call graph for this function:

◆ isNotable()

ILIAS\Administration\Setup\Objective\DropPermissions::isNotable ( )

Get to know if this is an interesting objective for a human.

Implements ILIAS\Setup\Objective.

Definition at line 55 of file DropPermissions.php.

55 : bool
56 {
57 return true;
58 }

◆ operations()

ILIAS\Administration\Setup\Objective\DropPermissions::operations ( Environment  $environment)
private
Returns
int[]

Definition at line 106 of file DropPermissions.php.

106 : array
107 {
109
110 $s = $db->query(
111 'SELECT ops_id FROM rbac_ta WHERE ' .
112 $db->in('ops_id', $this->operations, false, ilDBConstants::T_INTEGER) .
113 ' AND typ_id IN (SELECT obj_id FROM object_data WHERE title = ' .
114 $db->quote($this->type, ilDBConstants::T_TEXT) .
115 ' AND type = "typ")'
116 );
117
118 return array_map('intval', array_column($db->fetchAll($s), 'ops_id'));
119 }

References ILIAS\$db, ILIAS\Setup\Environment\getResource(), ILIAS\Setup\Environment\RESOURCE_DATABASE, ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

Referenced by ILIAS\Administration\Setup\Objective\DropPermissions\achieve(), ILIAS\Administration\Setup\Objective\DropPermissions\getHash(), ILIAS\Administration\Setup\Objective\DropPermissions\getLabel(), and ILIAS\Administration\Setup\Objective\DropPermissions\isApplicable().

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

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