Subversion Repositories oidplus

Rev

Rev 1244 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
  6.  *
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  *
  11.  *     http://www.apache.org/licenses/LICENSE-2.0
  12.  *
  13.  * Unless required by applicable law or agreed to in writing, software
  14.  * distributed under the License is distributed on an "AS IS" BASIS,
  15.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16.  * See the License for the specific language governing permissions and
  17.  * limitations under the License.
  18.  */
  19.  
  20. use ViaThinkSoft\OIDplus\OIDplusDatabaseConnection;
  21. use ViaThinkSoft\OIDplus\OIDplusConfigInitializationException;
  22. use ViaThinkSoft\OIDplus\OIDplusException;
  23.  
  24. /**
  25.  * This function will be called by OIDplusDatabaseConnection.class.php at method afterConnect().
  26.  * @param OIDplusDatabaseConnection $db is the OIDplusDatabaseConnection class
  27.  * @throws \ViaThinkSoft\OIDplus\OIDplusException
  28.  */
  29. function oidplus_dbupdate(OIDplusDatabaseConnection $db) {
  30.         // Detect database version
  31.         $res = $db->query("SELECT value FROM ###config WHERE name = 'database_version'");
  32.         $row = $res->fetch_array();
  33.         if ($row == null) {
  34.                 // Note: The config setting "database_version" is inserted in plugins/*/sqlSlang/*/sql/struct.sql, not in the OIDplus core init
  35.                 throw new OIDplusConfigInitializationException(_L('Cannot determine database version (the entry "database_version" inside the table "###config" is probably missing)'));
  36.         }
  37.         $version = $row['value'];
  38.         if (!is_numeric($version)) {
  39.                 throw new OIDplusConfigInitializationException(_L('Entry "database_version" inside the table "###config" seems to be wrong (needs to be a number)'));
  40.         }
  41.  
  42.         // Upgrade from old versions
  43.         try {
  44.                 if ($version == 200) {
  45.                         // Update 200 => 201
  46.                         require_once __DIR__.'/update200.inc.php';
  47.                         $version = oidplus_dbupdate_200($db);
  48.                 }
  49.                 if ($version == 201) {
  50.                         // Update 201 => 202
  51.                         require_once __DIR__.'/update201.inc.php';
  52.                         $version = oidplus_dbupdate_201($db);
  53.                 }
  54.                 if ($version == 202) {
  55.                         // Update 202 => 203
  56.                         require_once __DIR__.'/update202.inc.php';
  57.                         $version = oidplus_dbupdate_202($db);
  58.                 }
  59.                 if ($version == 203) {
  60.                         // Update 203 => 204
  61.                         require_once __DIR__.'/update203.inc.php';
  62.                         $version = oidplus_dbupdate_203($db);
  63.                 }
  64.                 if ($version == 204) {
  65.                         // Update 204 => 205
  66.                         require_once __DIR__.'/update204.inc.php';
  67.                         $version = oidplus_dbupdate_204($db);
  68.                 }
  69.                 if ($version == 205) {
  70.                         // Update 205 => 1000
  71.                         require_once __DIR__.'/update205.inc.php';
  72.                         $version = oidplus_dbupdate_205($db);
  73.                 }
  74.                 if ($version == 1000) {
  75.                         // Update 1000 => 1001
  76.                         require_once __DIR__.'/update1001.inc.php';
  77.                         $version = oidplus_dbupdate_1001($db);
  78.                 }
  79.                 if ($version == 1001) {
  80.                         // Update 1001 => 1002
  81.                         require_once __DIR__.'/update1002.inc.php';
  82.                         $version = oidplus_dbupdate_1002($db);
  83.                 }
  84.         } catch (\Exception $e) {
  85.                 throw new OIDplusException(_L('Database update from version %1 failed: %2',$version,$e->getMessage()));
  86.         }
  87.  
  88.         // Don't allow if the database version if newer than we expect
  89.         if ($version > 1002) {
  90.                 throw new OIDplusException(_L('The version of the database is newer than the program version. Please upgrade your program version.'));
  91.         }
  92. }
  93.