ILIAS  release_7 Revision v7.30-3-g800a261c036
MigrationObjective.php
Go to the documentation of this file.
1<?php
2
4
6
11{
15 protected $migration;
19 protected $steps;
20
25 public function __construct(Setup\Migration $migration, int $steps = null)
26 {
27 $this->migration = $migration;
28 $this->steps = $steps ?? $migration->getDefaultAmountOfStepsPerRun();
29 }
30
35 public function getHash() : string
36 {
37 return hash("sha256", self::class . '' . get_class($this->migration));
38 }
39
43 public function getLabel() : string
44 {
45 return $this->migration->getLabel();
46 }
47
52 public function isNotable() : bool
53 {
54 return true;
55 }
56
60 public function getPreconditions(Setup\Environment $environment) : array
61 {
62 return $this->migration->getPreconditions($environment);
63 }
64
68 public function achieve(Setup\Environment $environment) : Setup\Environment
69 {
74 $key = (new \ReflectionClass($this->migration))->getShortName();
75 $confirmation = $io->confirmExplicit(
76 "Do you really want to run the following migration? Make sure you have a backup\n" .
77 "of all your data. You will run this migration on your own risk.\n\n" .
78 "Please type '$key' to confirm and start.",
79 $key
80 );
81 if (!$confirmation) {
82 $io->error("Migration '$key' aborted.");
83 return $environment;
84 }
85 $io->inform("Preparing Migration: This may take quite a long time (e.g. all files are collected.");
86 $this->migration->prepare($environment);
87 $io->inform("Preparing Migration: done.");
88
90 $remaining = $this->migration->getRemainingAmountOfSteps();
91 if ($steps === Setup\Migration::INFINITE || $remaining < $steps) {
92 $steps = $remaining;
93 }
94 $io->inform("Trigger {$steps} step(s) in {$this->getLabel()}");
95 $step = 0;
96 $io->startProgress($steps);
97
98 while ($step < $steps) {
99 $io->advanceProgress();
100 $this->migration->step($environment);
101 $step++;
102 }
103 $io->stopProgress();
104 $remaining = $this->migration->getRemainingAmountOfSteps();
105 if ($remaining == 0) {
106 $io->inform("Migration '{$key}' has no remaining steps left.");
107 }
108 else {
109 $io->inform("{$remaining} step(s) remaining. Run again to proceed.");
110 }
111
112 return $environment;
113 }
114
118 public function isApplicable(Setup\Environment $environment) : bool
119 {
120 $this->migration->prepare($environment);
121
122 return $this->migration->getRemainingAmountOfSteps() > 0;
123 }
124}
An exception for terminatinating execution or to throw for unit testing.
isApplicable(Setup\Environment $environment)
@inheritDoc
__construct(Setup\Migration $migration, int $steps=null)
MigrationObjective constructor.
getPreconditions(Setup\Environment $environment)
@inheritdocs
An environment holds resources to be used in the setup process.
Definition: Environment.php:12
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:13
An objective is a desired state of the system that is supposed to be created by the setup.
Definition: Objective.php:15
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...