ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilGlobalCacheSetupAgent.php
Go to the documentation of this file.
1 <?php declare(strict_types=1);
2 
3 /* Copyright (c) 2019 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
5 use ILIAS\Setup;
7 
8 class ilGlobalCacheSetupAgent implements Setup\Agent
9 {
13  protected $refinery;
14 
15  public function __construct(
17  ) {
18  $this->refinery = $refinery;
19  }
20 
24  public function hasConfig() : bool
25  {
26  return true;
27  }
28 
33  {
34  return $this->refinery->custom()->transformation(function ($data) {
35  $settings = new \ilGlobalCacheSettings();
36  if (
37  $data === null ||
38  !isset($data["components"]) ||
39  !$data["components"] ||
40  !isset($data["service"]) ||
41  $data["service"] === "none" ||
42  (
43  $data["service"] === "memcached" &&
44  (!isset($data["memcached_nodes"]) || count($data["memcached_nodes"]) === 0)
45  )
46  ) {
47  $settings->setActive(false);
48  } else {
49  $settings->setActive(true);
50  switch ($data["service"]) {
51  case "static":
52  $settings->setService(\ilGlobalCache::TYPE_STATIC);
53  break;
54  case "xcache":
55  $settings->setService(\ilGlobalCache::TYPE_XCACHE);
56  break;
57  case "memcached":
58  array_walk($data["memcached_nodes"], function (array $node) use ($settings) {
59  $settings->addMemcachedNode($this->getMemcachedServer($node));
60  });
61  $settings->setService(\ilGlobalCache::TYPE_MEMCACHED);
62  break;
63  case "apc":
64  $settings->setService(\ilGlobalCache::TYPE_APC);
65  break;
66  default:
67  throw new \InvalidArgumentException(
68  "Unknown caching service: '{$data["service"]}'"
69  );
70  }
71  $settings->resetActivatedComponents();
72  if ($data["components"] === "all") {
73  $settings->activateAll();
74  } else {
75  foreach ($data["components"] as $cmp => $active) {
76  if ($active) {
77  $settings->addActivatedComponent($cmp);
78  }
79  }
80  }
81  }
82 
83  return $settings;
84  });
85  }
86 
87  protected function getMemcachedServer(array $node) : ilMemcacheServer
88  {
89  $m = new ilMemcacheServer();
90  $m->setStatus(boolval($node["active"]) === true ? ilMemcacheServer::STATUS_ACTIVE : ilMemcacheServer::STATUS_INACTIVE);
91  $m->setHost((string) $node["host"]);
92  $m->setPort((int) $node["port"]);
93  $m->setWeight((int) $node["weight"]);
94 
95  return $m;
96  }
97 
101  public function getInstallObjective(Setup\Config $config = null) : Setup\Objective
102  {
104  }
105 
109  public function getUpdateObjective(Setup\Config $config = null) : Setup\Objective
110  {
111  if ($config !== null) {
113  }
114  return new Setup\Objective\NullObjective();
115  }
116 
120  public function getBuildArtifactObjective() : Setup\Objective
121  {
122  return new Setup\Objective\NullObjective();
123  }
124 
128  public function getStatusObjective(Setup\Metrics\Storage $storage) : Setup\Objective
129  {
130  return new ilGlobalCacheMetricsCollectedObjective($storage);
131  }
132 
136  public function getMigrations() : array
137  {
138  return [];
139  }
140 
141  public function getNamedObjective(string $name, Setup\Config $config = null) : Setup\Objective
142  {
143  if ($name == "flushAll") {
145  }
146  throw new InvalidArgumentException(
147  "There is no named objective '$name'"
148  );
149  }
150 }
$data
Definition: storeScorm.php:23
An objective is a desired state of the system that is supposed to be created by the setup...
Definition: Objective.php:14
getStatusObjective(Setup\Metrics\Storage $storage)
getNamedObjective(string $name, Setup\Config $config=null)
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68
if($format !==null) $name
Definition: metadata.php:230
getUpdateObjective(Setup\Config $config=null)
Builds data types.
Definition: Factory.php:19
__construct(Refinery\Factory $refinery)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getInstallObjective(Setup\Config $config=null)
A transformation is a function from one datatype to another.
Class ilMemcacheServer.
A configuration for the setup.
Definition: Config.php:10