ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilAccessRBACOperationOrderUpdatedObjective.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /* Copyright (c) 2021 - Daniel Weise <daniel.weise@concepts-and-training.de> - Extended GPL, see LICENSE */
6 
7 use ILIAS\Setup;
9 
10 class ilAccessRBACOperationOrderUpdatedObjective implements Setup\Objective
11 {
12  protected string $operation;
13  protected int $pos;
14 
15  public function __construct(string $operation, int $pos)
16  {
17  $this->operation = $operation;
18  $this->pos = $pos;
19  }
20 
21  public function getHash(): string
22  {
23  return hash("sha256", self::class);
24  }
25 
26  public function getLabel(): string
27  {
28  return "Update operation order (operation=$this->operation;pos=$this->pos)";
29  }
30 
31  public function isNotable(): bool
32  {
33  return true;
34  }
35 
36  public function getPreconditions(Environment $environment): array
37  {
38  return [
40  ];
41  }
42 
43  public function achieve(Environment $environment): Environment
44  {
45  $db = $environment->getResource(Environment::RESOURCE_DATABASE);
46 
47  $db->update(
48  'rbac_operations',
49  ['op_order' => ["integer", $this->pos]],
50  ["operation" => ["text", $this->operation]]
51  );
52 
53  return $environment;
54  }
55 
56  public function isApplicable(Environment $environment): bool
57  {
58  $db = $environment->getResource(Environment::RESOURCE_DATABASE);
59 
60  $sql =
61  "SELECT ops_id" . PHP_EOL
62  . "FROM rbac_operations" . PHP_EOL
63  . "WHERE operation = " . $db->quote($this->operation, "text") . PHP_EOL
64  ;
65 
66  return $db->numRows($db->query($sql)) == 1;
67  }
68 }
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