ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilPluginStateDBOverIlDBInterface.php
Go to the documentation of this file.
1 <?php
2 
20 declare(strict_types=1);
21 
22 use ILIAS\Data;
24 
29 {
30  protected const TABLE_NAME = "il_plugin";
31 
32  protected Data\Factory $data_factory;
33  protected \ilDBInterface $db;
34 
35  protected bool $has_data = false;
36  protected ?array $data = null;
37 
38  public function __construct(Data\Factory $data_factory, \ilDBInterface $db)
39  {
40  $this->data_factory = $data_factory;
41  $this->db = $db;
42  }
43 
44  protected function getData(): void
45  {
46  if ($this->has_data) {
47  return;
48  }
49 
50  $res = $this->db->query("SELECT * FROM " . self::TABLE_NAME);
51  $this->data = [];
52  foreach ($this->db->fetchAll($res) as $data) {
53  $this->data[$data["plugin_id"]] = [
54  (bool) $data["active"],
55  $data["last_update_version"] ? $this->data_factory->version($data["last_update_version"]) : null,
56  $data["db_version"] ? (int) $data["db_version"] : null
57  ];
58  }
59  $this->has_data = true;
60  }
61 
62  public function isPluginActivated(string $id): bool
63  {
64  $this->getData();
65  return $this->data[$id][0] ?? false;
66  }
67 
68  public function setActivation(string $id, bool $activated): void
69  {
70  $this->getData();
71  if (!isset($this->data[$id])) {
72  throw new \InvalidArgumentException(
73  "Unknown plugin '$id'"
74  );
75  }
76  $this->db->update(
77  self::TABLE_NAME,
78  [
79  "active" => ["integer", $activated ? 1 : 0]
80  ],
81  [
82  "plugin_id" => ["text", $id]
83  ]
84  );
85  $this->has_data = false;
86  }
87 
88  public function getCurrentPluginVersion(string $id): ?Version
89  {
90  $this->getData();
91  return $this->data[$id][1] ?? null;
92  }
93 
94  public function getCurrentPluginDBVersion(string $id): ?int
95  {
96  $this->getData();
97  return $this->data[$id][2] ?? null;
98  }
99 
100  public function setCurrentPluginVersion(string $id, Version $version, int $db_version): void
101  {
102  $this->getData();
103  if (isset($this->data[$id])) {
104  $this->db->update(
105  self::TABLE_NAME,
106  [
107  "last_update_version" => ["text", (string) $version],
108  "db_version" => ["integer", $db_version]
109  ],
110  [
111  "plugin_id" => ["text", $id]
112  ]
113  );
114  } else {
115  $this->db->insert(
116  self::TABLE_NAME,
117  [
118  "plugin_id" => ["text", $id],
119  "active" => ["integer", 0],
120  "last_update_version" => ["text", (string) $version],
121  "db_version" => ["integer", $db_version]
122  ]
123  );
124  }
125  $this->has_data = false;
126  }
127 
128  public function remove(string $id): void
129  {
130  $this->db->manipulate(
131  "DELETE FROM " . self::TABLE_NAME . " WHERE plugin_id = " . $this->db->quote($id, "text")
132  );
133  $this->has_data = false;
134  }
135 }
$res
Definition: ltiservices.php:69
$version
Definition: plugin.php:25
Implementation of ilPluginStateDB over ilDBInterface.
setCurrentPluginVersion(string $id, Version $version, int $db_version)
__construct(Data\Factory $data_factory, \ilDBInterface $db)
Repository interface for plugin state data.
Builds data types.
Definition: Factory.php:35
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
A version number that consists of three numbers (major, minor, patch).
Definition: Version.php:26
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...