ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
ILIAS\Administration\Setup\Objective\CopyPermissions Class Reference

ALL permissions are copied from the $src_type and all existing permissions are first deleted from $dest_type. More...

+ Inheritance diagram for ILIAS\Administration\Setup\Objective\CopyPermissions:
+ Collaboration diagram for ILIAS\Administration\Setup\Objective\CopyPermissions:

Public Member Functions

 __construct (private string $src_type, private string $dest_type, 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

 firstRefIdOfType (ilDBInterface $db, string $type)
 

Detailed Description

ALL permissions are copied from the $src_type and all existing permissions are first deleted from $dest_type.

Only rbac_pa is modified.

Definition at line 34 of file CopyPermissions.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Administration\Setup\Objective\CopyPermissions::__construct ( private string  $src_type,
private string  $dest_type,
private array  $additional_preconditions 
)
Parameters
Objective[]$additional_preconditions

Definition at line 39 of file CopyPermissions.php.

40 {
41 }

Member Function Documentation

◆ achieve()

ILIAS\Administration\Setup\Objective\CopyPermissions::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 63 of file CopyPermissions.php.

64 {
66 $src_ref_id = $this->firstRefIdOfType($db, $this->src_type);
67 $dest_ref_id = $this->firstRefIdOfType($db, $this->dest_type);
68
69 if (!$src_ref_id || !$dest_ref_id) {
70 return $environment;
71 }
72
73 $db->queryF(
74 'DELETE FROM rbac_pa WHERE ref_id = %s',
76 [$dest_ref_id]
77 );
78 $db->manipulateF(
79 'INSERT INTO rbac_pa (ref_id, ops_id, rol_id) SELECT %s AS ref_id, ops_id, rol_id FROM rbac_pa WHERE ref_id = %s',
81 [$dest_ref_id, $src_ref_id]
82 );
83
84 return $environment;
85 }
firstRefIdOfType(ilDBInterface $db, string $type)
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.

References ILIAS\$db, ILIAS\Administration\Setup\Objective\CopyPermissions\firstRefIdOfType(), ILIAS\Setup\Environment\getResource(), ILIAS\Setup\Environment\RESOURCE_DATABASE, and ilDBConstants\T_INTEGER.

+ Here is the call graph for this function:

◆ firstRefIdOfType()

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

Definition at line 96 of file CopyPermissions.php.

96 : int
97 {
98 $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';
99 return (int) ($db->fetchAssoc($db->queryF($ref_query, [ilDBConstants::T_TEXT], [$type]))['ref_id'] ?? 0);
100 }

References ILIAS\$db, and ilDBConstants\T_TEXT.

Referenced by ILIAS\Administration\Setup\Objective\CopyPermissions\achieve(), and ILIAS\Administration\Setup\Objective\CopyPermissions\isApplicable().

+ Here is the caller graph for this function:

◆ getHash()

ILIAS\Administration\Setup\Objective\CopyPermissions::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 43 of file CopyPermissions.php.

43 : string
44 {
45 return hash("sha256", self::class . $this->src_type . ',' . $this->dest_type);
46 }

◆ getLabel()

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

Get a label that describes this objective.

Implements ILIAS\Setup\Objective.

Definition at line 48 of file CopyPermissions.php.

48 : string
49 {
50 return sprintf('Copy permissions from %s to %s', $this->src_type, $this->dest_type);
51 }

◆ getPreconditions()

ILIAS\Administration\Setup\Objective\CopyPermissions::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 58 of file CopyPermissions.php.

58 : array
59 {
60 return [new ilDatabaseInitializedObjective(), ...$this->additional_preconditions];
61 }

◆ isApplicable()

ILIAS\Administration\Setup\Objective\CopyPermissions::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 87 of file CopyPermissions.php.

87 : bool
88 {
90 $src_ref = $this->firstRefIdOfType($db, $this->src_type);
91 $ret = null !== $db->fetchAssoc($db->queryF('select 1 from rbac_pa where ref_id = %s', [ilDBConstants::T_INTEGER], [$src_ref]));
92
93 return $ret;
94 }

References ILIAS\$db, ILIAS\Administration\Setup\Objective\CopyPermissions\firstRefIdOfType(), ILIAS\Setup\Environment\getResource(), ILIAS\Setup\Environment\RESOURCE_DATABASE, and ilDBConstants\T_INTEGER.

+ Here is the call graph for this function:

◆ isNotable()

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

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

Implements ILIAS\Setup\Objective.

Definition at line 53 of file CopyPermissions.php.

53 : bool
54 {
55 return true;
56 }

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