ILIAS  release_8 Revision v8.23
class.ilNoMajorVersionSkippedConditionObjective.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
21 use ILIAS\Setup;
22 use ILIAS\Data;
23 
24 class ilNoMajorVersionSkippedConditionObjective implements Setup\Objective
25 {
26  protected Data\Factory $data_factory;
27 
28  public function __construct(Data\Factory $data_factory)
29  {
30  $this->data_factory = $data_factory;
31  }
32 
33  public function getHash(): string
34  {
35  return hash(
36  "sha256",
37  get_class($this)
38  );
39  }
40 
41  public function getLabel(): string
42  {
43  return "No major version is skipped in update.";
44  }
45 
46  public function isNotable(): bool
47  {
48  return true;
49  }
50 
51  public function getPreconditions(Setup\Environment $environment): array
52  {
53  return [
55  ];
56  }
57 
58  public function achieve(Setup\Environment $environment): Setup\Environment
59  {
60  $factory = $environment->getResource(Setup\Environment::RESOURCE_SETTINGS_FACTORY);
61  $settings = $factory->settingsFor("common");
62 
63  // TODO ILIAS 9: This special case can vanish with ILIAS 9. It exists to make sure that
64  // installations on version 7.0 or greater can update to ILIAS 8. This is checked by
65  // looking into the version string (which is only updated starting with 8 and had a
66  // very old value previously) and the db_version (which is 5751 with ILIAS 7.0).
68  if ($current_version_string === "3.2.3 2004-11-22" && (int) $settings->get("db_version") >= 5751) {
69  return $environment;
70  }
71 
72  $current_version = $this->data_factory->version($current_version_string);
73  $target_version = $this->data_factory->version(ILIAS_VERSION_NUMERIC);
74 
75  if (($target_version->getMajor() - $current_version->getMajor()) > 1) {
76  throw new Setup\NotExecutableException(
77  "Updates may only be performed from one major version to the " .
78  "next, no major versions may be skipped."
79  );
80  }
81 
82  return $environment;
83  }
84 
85  public function isApplicable(Setup\Environment $environment): bool
86  {
87  return true;
88  }
89 }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
const ILIAS_VERSION_NUMERIC
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An environment holds resources to be used in the setup process.
Definition: Environment.php:27
$factory
Definition: metadata.php:75