ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
MigrationObjective.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Setup\Objective;
22
23use ILIAS\Setup;
24
29{
31 protected int $steps;
32
33 public function __construct(Setup\Migration $migration, ?int $steps = null)
34 {
35 $this->migration = $migration;
36 $this->steps = $steps ?? $migration->getDefaultAmountOfStepsPerRun();
37 }
38
43 public function getHash(): string
44 {
45 return hash("sha256", self::class . '' . get_class($this->migration));
46 }
47
51 public function getLabel(): string
52 {
53 return $this->migration->getLabel();
54 }
55
60 public function isNotable(): bool
61 {
62 return true;
63 }
64
68 public function getPreconditions(Setup\Environment $environment): array
69 {
70 return $this->migration->getPreconditions($environment);
71 }
72
76 public function achieve(Setup\Environment $environment): Setup\Environment
77 {
82 $key = (new \ReflectionClass($this->migration))->getShortName();
83 $confirmation = $io->confirmExplicit(
84 "Do you really want to run the following migration? Make sure you have a backup\n" .
85 "of all your data. You will run this migration on your own risk.\n\n" .
86 "Please type '$key' to confirm and start.",
87 $key
88 );
89 if (!$confirmation) {
90 $io->error("Migration '$key' aborted.");
91 return $environment;
92 }
93 $io->inform("Preparing Migration: This may take quite a long time (e.g. all files are collected.");
94 $this->migration->prepare($environment);
95 $io->inform("Preparing Migration: done.");
96
98 $remaining = $this->migration->getRemainingAmountOfSteps();
99 if ($steps === Setup\Migration::INFINITE || $remaining < $steps) {
100 $steps = $remaining;
101 }
102 $io->inform("Trigger {$steps} step(s) in {$this->getLabel()}");
103 $step = 0;
104 $io->startProgress($steps);
105
106 while ($step < $steps) {
107 $io->advanceProgress();
108 $this->migration->step($environment);
109 $step++;
110 }
111 $io->stopProgress();
112 $remaining = $this->migration->getRemainingAmountOfSteps();
113 if ($remaining == 0) {
114 $io->inform("Migration '{$key}' has no remaining steps left.");
115 }
116 else {
117 $io->inform("{$remaining} step(s) remaining. Run again to proceed.");
118 }
119
120 return $environment;
121 }
122
126 public function isApplicable(Setup\Environment $environment): bool
127 {
128 $this->migration->prepare($environment);
129
130 return $this->migration->getRemainingAmountOfSteps() > 0;
131 }
132}
__construct(Setup\Migration $migration, ?int $steps=null)
isApplicable(Setup\Environment $environment)
@inheritDoc
getPreconditions(Setup\Environment $environment)
@inheritdocs
An environment holds resources to be used in the setup process.
Definition: Environment.php:28
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
A migration is a potentially long lasting operation that can be broken into discrete steps.
Definition: Migration.php:29
An objective is a desired state of the system that is supposed to be created by the setup.
Definition: Objective.php:31
achieve(Environment $environment)
Objectives can be achieved.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...