Subversion Repositories oidplus

Rev

Rev 855 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 - 2022 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. /**
  21.  * This function will be called by OIDplusDatabaseConnection.class.php at method afterConnect().
  22.  * @param OIDplusDatabaseConnection $db is the OIDplusDatabaseConnection class
  23.  * @throws OIDplusException
  24.  */
  25. function oidplus_dbupdate(OIDplusDatabaseConnection $db) {
  26.         // Detect database version
  27.         $res = $db->query("SELECT value FROM ###config WHERE name = 'database_version'");
  28.         $row = $res->fetch_array();
  29.         if ($row == null) {
  30.                 // Note: The config setting "database_version" is inserted in setup/sql/...sql, not in the OIDplus core init
  31.                 throw new OIDplusConfigInitializationException(_L('Cannot determine database version (the entry "database_version" inside the table "###config" is probably missing)'));
  32.         }
  33.         $version = $row['value'];
  34.         if (!is_numeric($version)) {
  35.                 throw new OIDplusConfigInitializationException(_L('Entry "database_version" inside the table "###config" seems to be wrong (expect number between 200 and 999)'));
  36.         }
  37.  
  38.         // Upgrade from old versions
  39.         try {
  40.                 if ($version == 200) {
  41.                         // Update 200 => 201
  42.                         require_once __DIR__.'/update200.inc.php';
  43.                         $version = oidplus_dbupdate_200($db);
  44.                 }
  45.                 if ($version == 201) {
  46.                         // Update 201 => 202
  47.                         require_once __DIR__.'/update201.inc.php';
  48.                         $version = oidplus_dbupdate_201($db);
  49.                 }
  50.                 if ($version == 202) {
  51.                         // Update 202 => 203
  52.                         require_once __DIR__.'/update202.inc.php';
  53.                         $version = oidplus_dbupdate_202($db);
  54.                 }
  55.                 if ($version == 203) {
  56.                         // Update 203 => 204
  57.                         require_once __DIR__.'/update203.inc.php';
  58.                         $version = oidplus_dbupdate_203($db);
  59.                 }
  60.                 if ($version == 204) {
  61.                         // Update 204 => 205
  62.                         require_once __DIR__.'/update204.inc.php';
  63.                         $version = oidplus_dbupdate_204($db);
  64.                 }
  65.                 if ($version == 205) {
  66.                         // Update 205 => 1000
  67.                         require_once __DIR__.'/update205.inc.php';
  68.                         $version = oidplus_dbupdate_205($db);
  69.                 }
  70.                 if ($version == 1000) {
  71.                         // ... in the future, add updates here! ...
  72.                 }
  73.         } catch (Exception $e) {
  74.                 throw new OIDplusException(_L('Database update from version %1 failed: %2',$version,$e->getMessage()));
  75.         }
  76.  
  77.         // Don't allow if the database version if newer than we expect
  78.         if ($version != 1000) {
  79.                 require_once __DIR__.'/update205.inc.php';
  80.                 $version = oidplus_dbupdate_205($db);
  81.         }
  82. }
  83.