From cc13fcc341bcade1a33f7d86dc7c5478762711e7 Mon Sep 17 00:00:00 2001
From: Elmar Ludwig <elmar.ludwig@uni-osnabrueck.de>
Date: Tue, 31 Aug 2021 10:15:50 +0200
Subject: [PATCH] always validate schema version

---
 app/controllers/web_migrate.php    | 2 --
 cli/migrate.php                    | 2 --
 lib/migrations/DBSchemaVersion.php | 3 ++-
 3 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/app/controllers/web_migrate.php b/app/controllers/web_migrate.php
index af229590f2c..2637578d98d 100644
--- a/app/controllers/web_migrate.php
+++ b/app/controllers/web_migrate.php
@@ -17,8 +17,6 @@ class WebMigrateController extends StudipController
 
         parent::before_filter($action, $args);
 
-        DBSchemaVersion::validateSchemaVersion();
-
         $this->target   = Request::int('target');
         $this->branch   = Request::get('branch', '0');
         $this->version  = new DBSchemaVersion('studip', $this->branch);
diff --git a/cli/migrate.php b/cli/migrate.php
index 0fe6bc35c43..618132a8b82 100755
--- a/cli/migrate.php
+++ b/cli/migrate.php
@@ -53,8 +53,6 @@ if (isset($_SERVER['argv'])) {
         }
     }
 
-    DBSchemaVersion::validateSchemaVersion();
-
     $version = new DBSchemaVersion($domain, $branch);
     $migrator = new Migrator($path, $version, $verbose);
 
diff --git a/lib/migrations/DBSchemaVersion.php b/lib/migrations/DBSchemaVersion.php
index 8217ec06edb..61894be0787 100644
--- a/lib/migrations/DBSchemaVersion.php
+++ b/lib/migrations/DBSchemaVersion.php
@@ -45,6 +45,7 @@ class DBSchemaVersion implements SchemaVersion
         $this->domain = $domain;
         $this->branch = $branch;
         $this->versions = [0];
+        $this->validateSchemaVersion();
         $this->initSchemaInfo();
     }
 
@@ -158,7 +159,7 @@ class DBSchemaVersion implements SchemaVersion
     /**
      * Validate correct structure of schema_version table.
      */
-    public static function validateSchemaVersion()
+    private function validateSchemaVersion()
     {
         $db = DBManager::get();
         $result = $db->query("SHOW TABLES LIKE 'schema_versions'");
-- 
GitLab