ILIAS  trunk Revision v11.0_alpha-1866-gfa368f7776e
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ILIAS\Setup\CLI\ImportFileUnzippedFileObjective Class Reference
+ Inheritance diagram for ILIAS\Setup\CLI\ImportFileUnzippedFileObjective:
+ Collaboration diagram for ILIAS\Setup\CLI\ImportFileUnzippedFileObjective:

Public Member Functions

 __construct (string $zip_path)
 
 getHash ()
 Get a hash for this objective. More...
 
 getLabel ()
 Get a label that describes this objective. More...
 
 isNotable ()
 Get to know if this is an interesting objective for a human. More...
 
 getPreconditions (Environment $environment)
 Objectives might depend on other objectives. More...
 
 achieve (Environment $environment)
 Objectives can be achieved. More...
 
 isApplicable (Environment $environment)
 Get to know whether the objective is applicable. More...
 

Protected Member Functions

 deleteRecursive (string $path, bool $delete_base_dir=false)
 
 extractZip (string $source, string $destination)
 

Protected Attributes

string $zip_path
 

Detailed Description

Definition at line 31 of file ImportFileUnzippedFileObjective.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Setup\CLI\ImportFileUnzippedFileObjective::__construct ( string  $zip_path)

Member Function Documentation

◆ achieve()

ILIAS\Setup\CLI\ImportFileUnzippedFileObjective::achieve ( Environment  $environment)

Objectives can be achieved.

They might add resources to the environment when they have been achieved.

This method needs to be idempotent for a given environment. That means: if this is executed a second time, nothing new should happen. Or the other way round: if the environment already looks like desired, the objective should not take any further actions when this is called.

Exceptions

Implements ILIAS\Setup\Objective.

Definition at line 62 of file ImportFileUnzippedFileObjective.php.

References ILIAS\Setup\CLI\ImportFileUnzippedFileObjective\deleteRecursive(), ILIAS\Setup\CLI\ImportFileUnzippedFileObjective\extractZip(), and ILIAS\Setup\Environment\getConfigFor().

62  : Environment
63  {
64  $tmp_dir = $environment->getConfigFor("tmp_dir");
65  $dirs = [
66  $tmp_dir . DIRECTORY_SEPARATOR . "web_data.zip" => $tmp_dir . DIRECTORY_SEPARATOR . "web_data",
67  $tmp_dir . DIRECTORY_SEPARATOR . "Customizing.zip" => $tmp_dir . DIRECTORY_SEPARATOR . "Customizing",
68  $tmp_dir . DIRECTORY_SEPARATOR . "data.zip" => $tmp_dir . DIRECTORY_SEPARATOR . "data",
69  $tmp_dir . DIRECTORY_SEPARATOR . "dump.zip" => $tmp_dir
70  ];
71 
72  $this->extractZip($this->zip_path, $tmp_dir);
73 
74  foreach ($dirs as $source => $destination) {
75  if (!file_exists($source)) {
76  continue;
77  }
78 
79  $this->extractZip($source, $destination);
80 
81  $this->deleteRecursive($source);
82  }
83 
84  return $environment;
85  }
deleteRecursive(string $path, bool $delete_base_dir=false)
+ Here is the call graph for this function:

◆ deleteRecursive()

ILIAS\Setup\CLI\ImportFileUnzippedFileObjective::deleteRecursive ( string  $path,
bool  $delete_base_dir = false 
)
protected

Definition at line 92 of file ImportFileUnzippedFileObjective.php.

Referenced by ILIAS\Setup\CLI\ImportFileUnzippedFileObjective\achieve().

92  : void
93  {
94  if (is_file($path)) {
95  unlink($path);
96  return;
97  }
98 
99  $files = new RecursiveIteratorIterator(
100  new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS),
101  RecursiveIteratorIterator::CHILD_FIRST
102  );
103 
104  foreach ($files as $file_info) {
105  if ($file_info->isDir()) {
106  rmdir($file_info->getRealPath());
107  continue;
108  }
109  unlink($file_info->getRealPath());
110  }
111 
112  if ($delete_base_dir) {
113  rmdir($path);
114  }
115  }
$path
Definition: ltiservices.php:29
+ Here is the caller graph for this function:

◆ extractZip()

ILIAS\Setup\CLI\ImportFileUnzippedFileObjective::extractZip ( string  $source,
string  $destination 
)
protected

Definition at line 117 of file ImportFileUnzippedFileObjective.php.

References Vendor\Package\$e.

Referenced by ILIAS\Setup\CLI\ImportFileUnzippedFileObjective\achieve().

117  : void
118  {
119  $zip = new ZipArchive();
120  try {
121  $zip->open($source);
122  $zip->extractTo($destination);
123  } catch (\Exception $e) {
124  throw new Setup\UnachievableException("Could not open zip at $source");
125  } finally {
126  $zip->close();
127  }
128  }
+ Here is the caller graph for this function:

◆ getHash()

ILIAS\Setup\CLI\ImportFileUnzippedFileObjective::getHash ( )

Get a hash for this objective.

The hash of two objectives must be the same, if they are the same objective, with the same config on the same environment, i.e. if the one is achieved the other is achieved as well because they are the same.

Implements ILIAS\Setup\Objective.

Definition at line 40 of file ImportFileUnzippedFileObjective.php.

40  : string
41  {
42  return hash("sha256", self::class);
43  }

◆ getLabel()

ILIAS\Setup\CLI\ImportFileUnzippedFileObjective::getLabel ( )

Get a label that describes this objective.

Implements ILIAS\Setup\Objective.

Definition at line 45 of file ImportFileUnzippedFileObjective.php.

45  : string
46  {
47  return "Unzip files from $this->zip_path into temporary directory";
48  }

◆ getPreconditions()

ILIAS\Setup\CLI\ImportFileUnzippedFileObjective::getPreconditions ( Environment  $environment)

Objectives might depend on other objectives.

Exceptions
UnachievableExceptionif the objective is not achievable
Returns
Objective[]

Implements ILIAS\Setup\Objective.

Definition at line 55 of file ImportFileUnzippedFileObjective.php.

55  : array
56  {
57  return [
59  ];
60  }

◆ isApplicable()

ILIAS\Setup\CLI\ImportFileUnzippedFileObjective::isApplicable ( Environment  $environment)

Get to know whether the objective is applicable.

Don't change the environment or cause changes on services in the environment. Just check if this objective needs to be achieved, either currently or at all. In case of doubt whether the objective is applicable or not return true.

Implements ILIAS\Setup\Objective.

Definition at line 87 of file ImportFileUnzippedFileObjective.php.

87  : bool
88  {
89  return file_exists($this->zip_path);
90  }

◆ isNotable()

ILIAS\Setup\CLI\ImportFileUnzippedFileObjective::isNotable ( )

Get to know if this is an interesting objective for a human.

Implements ILIAS\Setup\Objective.

Definition at line 50 of file ImportFileUnzippedFileObjective.php.

50  : bool
51  {
52  return true;
53  }

Field Documentation

◆ $zip_path

string ILIAS\Setup\CLI\ImportFileUnzippedFileObjective::$zip_path
protected

The documentation for this class was generated from the following file: