ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilGlobalCacheSettings.php
Go to the documentation of this file.
1<?php
2require_once('./Services/GlobalCache/classes/class.ilGlobalCache.php');
3
5
13{
14 const LOG_LEVEL_FORCED = -1;
15 const LOG_LEVEL_NONE = 0;
16 const LOG_LEVEL_SHY = 1;
19 const INI_HEADER_CACHE = 'cache';
20 const INI_FIELD_ACTIVATE_GLOBAL_CACHE = 'activate_global_cache';
21 const INI_FIELD_GLOBAL_CACHE_SERVICE_TYPE = 'global_cache_service_type';
22 const INI_HEADER_CACHE_ACTIVATED_COMPONENTS = 'cache_activated_components';
23 const INI_FIELD_LOG_LEVEL = 'log_level';
31 protected $activated_components = array();
35 protected $active = false;
43 protected $memcached_nodes = [];
44
45
49 public function readFromIniFile(ilIniFile $ilIniFile)
50 {
51 $this->checkIniHeader($ilIniFile);
52 $this->setActive($ilIniFile->readVariable(self::INI_HEADER_CACHE, self::INI_FIELD_ACTIVATE_GLOBAL_CACHE));
53 $this->setService($ilIniFile->readVariable(self::INI_HEADER_CACHE, self::INI_FIELD_GLOBAL_CACHE_SERVICE_TYPE));
54 $this->setLogLevel($ilIniFile->readVariable(self::INI_HEADER_CACHE, self::INI_FIELD_LOG_LEVEL));
55 if (!$this->isActive()) {
57 } else {
58 $cache_components = $ilIniFile->readGroup(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS);
59 if (is_array($cache_components)) {
60 foreach ($cache_components as $comp => $v) {
61 if ($v) {
62 $this->addActivatedComponent($comp);
63 }
64 }
65 }
66 }
67 }
68
69
73 public function writeToIniFile(ilIniFile $ilIniFile)
74 {
75 $ilIniFile->setVariable(self::INI_HEADER_CACHE, self::INI_FIELD_ACTIVATE_GLOBAL_CACHE, $this->isActive() ? '1' : '0');
76 $ilIniFile->setVariable(self::INI_HEADER_CACHE, self::INI_FIELD_GLOBAL_CACHE_SERVICE_TYPE, $this->getService());
77 $ilIniFile->setVariable(self::INI_HEADER_CACHE, self::INI_FIELD_LOG_LEVEL, $this->getLogLevel());
78
79 $ilIniFile->removeGroup(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS);
80 $ilIniFile->addGroup(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS);
81 foreach (ilGlobalCache::getAvailableComponents() as $comp) {
82 $ilIniFile->setVariable(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS, $comp, $this->isComponentActivated($comp) ? '1' : '0');
83 }
84 if ($ilIniFile->write()) {
85 ilGlobalCache::log('saved new settings: ' . $this->__toString(), self::LOG_LEVEL_FORCED);
86 }
87 }
88
89
90 public function activateAll()
91 {
92 foreach (ilGlobalCache::getAvailableComponents() as $comp) {
93 $this->addActivatedComponent($comp);
94 }
95 }
96
97
101 public function addActivatedComponent($component)
102 {
103 $this->activated_components[] = $component;
104 $this->activated_components = array_unique($this->activated_components);
105 }
106
107
108 public function resetActivatedComponents()
109 {
110 $this->activated_components = array();
111 }
112
113
119 public function isComponentActivated($component)
120 {
121 return in_array($component, $this->activated_components);
122 }
123
124
128 public function areAllComponentActivated()
129 {
130 return count($this->activated_components) == count(ilGlobalCache::getAvailableComponents());
131 }
132
133
137 public function getService()
138 {
139 return $this->service;
140 }
141
142
146 public function setService($service)
147 {
148 $this->service = $service;
149 }
150
151
155 public function getActivatedComponents()
156 {
158 }
159
160
165 {
166 $this->activated_components = $activated_components;
167 }
168
169
173 public function isActive()
174 {
175 return $this->active;
176 }
177
178
182 public function setActive($active)
183 {
184 $this->active = $active;
185 }
186
187
191 protected function checkIniHeader(ilIniFile $ilIniFile)
192 {
193 if (!$ilIniFile->readGroup(self::INI_HEADER_CACHE)) {
194 $ilIniFile->addGroup(self::INI_HEADER_CACHE);
195 }
196 if (!$ilIniFile->readGroup(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS)) {
197 $ilIniFile->addGroup(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS);
198 }
199 }
200
201
205 public function getLogLevel()
206 {
207 return $this->log_level;
208 }
209
210
214 public function setLogLevel($log_level)
215 {
216 $this->log_level = $log_level;
217 }
218
219
220 public function __toString()
221 {
222 $service = 'Service: ' . ($this->getService() > 0 ? ilGlobalCache::lookupServiceClassName($this->getService()) : 'none');
223 $activated = 'Activated Components: ' . implode(', ', $this->getActivatedComponents());
224 $log_level = 'Log Level: ' . $this->getLogLevelName();
225
226 return implode("\n", array( '', '', $service, $activated, $log_level, '' ));
227 }
228
229
233 protected function getLogLevelName()
234 {
235 return $this->lookupLogLevelName($this->getLogLevel());
236 }
237
238
244 protected function lookupLogLevelName($level)
245 {
246 $r = new ReflectionClass($this);
247 foreach ($r->getConstants() as $k => $v) {
248 if (strpos($k, 'LOG_LEVEL') === 0 and $v == $level) {
249 return $k;
250 }
251 }
252
253 return '';
254 }
255
256 public function addMemcachedNode(ilMemcacheServer $node_id) : void
257 {
258 $this->memcached_nodes[] = $node_id;
259 }
260
264 public function getMemcachedNodes() : array
265 {
267 }
268}
An exception for terminatinating execution or to throw for unit testing.
Class ilGlobalCacheSettings.
addMemcachedNode(ilMemcacheServer $node_id)
writeToIniFile(ilIniFile $ilIniFile)
checkIniHeader(ilIniFile $ilIniFile)
setActivatedComponents($activated_components)
readFromIniFile(ilIniFile $ilIniFile)
static lookupServiceClassName($service_type)
static log($message, $log_level)
static getAvailableComponents()
INIFile Parser.
write()
save ini-file-data to filesystem @access private
Class ilMemcacheServer.
A configuration for the setup.
Definition: Config.php:11
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...