ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilDatabaseDumpedToDirectoryObjective.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
25 {
26  public function __construct(protected string $target, protected MysqlDumper $dumper)
27  {
28  }
29 
33  public function getHash(): string
34  {
35  return hash("sha256", self::class . $this->target);
36  }
37 
41  public function getLabel(): string
42  {
43  return "Dump database to $this->target/" . MysqlIfsnopDumper::FILE_NAME;
44  }
45 
49  public function isNotable(): bool
50  {
51  return true;
52  }
53 
57  public function getPreconditions(Environment $environment): array
58  {
59  return [
62  ];
63  }
64 
68  public function achieve(Environment $environment): Environment
69  {
70  if (file_exists($this->target)) {
71  $this->deleteDirRecursive($this->target);
72  }
73  mkdir($this->target, 0755);
74 
75  $client_ini = $environment->getResource(Environment::RESOURCE_CLIENT_INI);
76  $host = $client_ini->readVariable("db", "host");
77  $user = $client_ini->readVariable("db", "user");
78  $password = $client_ini->readVariable("db", "pass");
79  $name = $client_ini->readVariable("db", "name");
80  $port = $client_ini->readVariable("db", "port");
81 
82  $this->dumper->createDump($host, $user, $password, $name, $port, $this->target);
83 
84  return $environment;
85  }
86 
90  public function isApplicable(Environment $environment): bool
91  {
92  return is_writable(pathinfo($this->target, PATHINFO_DIRNAME));
93  }
94 
95  protected function deleteDirRecursive(string $path): void
96  {
97  $files = new RecursiveIteratorIterator(
98  new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS),
99  RecursiveIteratorIterator::CHILD_FIRST
100  );
101 
102  foreach ($files as $file_info) {
103  if ($file_info->isDir()) {
104  rmdir($file_info->getRealPath());
105  continue;
106  }
107  unlink($file_info->getRealPath());
108  }
109 
110  rmdir($path);
111  }
112 }
An objective is a desired state of the system that is supposed to be created by the setup...
Definition: Objective.php:30
getLabel()
Get a label that describes this objective.
getHash()
Get a hash for this objective.The hash of two objectives must be the same, if they are the same objec...
__construct(protected string $target, protected MysqlDumper $dumper)
$path
Definition: ltiservices.php:29
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
isNotable()
Get to know if this is an interesting objective for a human.
achieve(Environment $environment)
Objectives can be achieved.They might add resources to the environment when they have been achieved...
An environment holds resources to be used in the setup process.
Definition: Environment.php:27
getPreconditions(Environment $environment)
Objectives might depend on other objectives.if the objective is not achievableObjective[] ...