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