Subversion Repositories oidplus

Rev

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

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 - 2021 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.  
  22. /**
  23.  * This function will be called by OIDplusDatabaseConnection.class.php at method afterConnect().
  24.  * @param OIDplusDatabaseConnection $db is the OIDplusDatabaseConnection class
  25.  * @return int new version set
  26.  * @throws \ViaThinkSoft\OIDplus\OIDplusException
  27.  */
  28. function oidplus_dbupdate_201(OIDplusDatabaseConnection $db): int {
  29.         if ($db->transaction_supported()) $db->transaction_begin();
  30.         try {
  31.                 // Change bit(1) types to boolean/tinyint(1)
  32.                 if ($db->getSlang()->id() == 'pgsql') {
  33.                         $db->query("alter table ###config  alter protected    drop default");
  34.                         $db->query("alter table ###config  alter protected    type boolean using get_bit(protected   ,0)::boolean");
  35.                         $db->query("alter table ###config  alter protected    set default false");
  36.  
  37.                         $db->query("alter table ###config  alter visible      drop default");
  38.                         $db->query("alter table ###config  alter visible      type boolean using get_bit(visible     ,0)::boolean");
  39.                         $db->query("alter table ###config  alter visible      set default false");
  40.  
  41.                         $db->query("alter table ###asn1id  alter standardized drop default");
  42.                         $db->query("alter table ###asn1id  alter standardized type boolean using get_bit(standardized,0)::boolean");
  43.                         $db->query("alter table ###asn1id  alter standardized set default false");
  44.  
  45.                         $db->query("alter table ###asn1id  alter well_known   drop default");
  46.                         $db->query("alter table ###asn1id  alter well_known   type boolean using get_bit(well_known  ,0)::boolean");
  47.                         $db->query("alter table ###asn1id  alter well_known   set default false");
  48.  
  49.                         $db->query("alter table ###iri     alter longarc      drop default");
  50.                         $db->query("alter table ###iri     alter longarc      type boolean using get_bit(longarc     ,0)::boolean");
  51.                         $db->query("alter table ###iri     alter longarc      set default false");
  52.  
  53.                         $db->query("alter table ###iri     alter well_known   drop default");
  54.                         $db->query("alter table ###iri     alter well_known   type boolean using get_bit(well_known  ,0)::boolean");
  55.                         $db->query("alter table ###iri     alter well_known   set default false");
  56.  
  57.                         $db->query("alter table ###objects alter confidential type boolean using get_bit(confidential,0)::boolean");
  58.  
  59.                         $db->query("alter table ###ra      alter privacy      drop default");
  60.                         $db->query("alter table ###ra      alter privacy      type boolean using get_bit(privacy     ,0)::boolean");
  61.                         $db->query("alter table ###ra      alter privacy      set default false");
  62.                 } else if ($db->getSlang()->id() == 'mysql') {
  63.                         $db->query("alter table ###config  modify protected    boolean");
  64.                         $db->query("alter table ###config  modify visible      boolean");
  65.                         $db->query("alter table ###asn1id  modify standardized boolean");
  66.                         $db->query("alter table ###asn1id  modify well_known   boolean");
  67.                         $db->query("alter table ###iri     modify longarc      boolean");
  68.                         $db->query("alter table ###iri     modify well_known   boolean");
  69.                         $db->query("alter table ###objects modify confidential boolean");
  70.                         $db->query("alter table ###ra      modify privacy      boolean");
  71.                 }
  72.  
  73.                 // Rename log_user.user to log_user.username, since user is a keyword in PostgreSQL and MSSQL
  74.                 if ($db->getSlang()->id() == 'pgsql') {
  75.                         $db->query("alter table ###log_user rename column \"user\" to \"username\"");
  76.                 } else if ($db->getSlang()->id() == 'mysql') {
  77.                         $db->query("alter table ###log_user change `user` `username` varchar(255) NOT NULL");
  78.                 }
  79.  
  80.                 $version = 202;
  81.                 $db->query("UPDATE ###config SET value = ? WHERE name = 'database_version'", array("$version"));
  82.  
  83.                 if ($db->transaction_supported()) $db->transaction_commit();
  84.         } catch (\Exception $e) {
  85.                 if ($db->transaction_supported()) $db->transaction_rollback();
  86.                 throw new $e;
  87.         }
  88.  
  89.         return $version;
  90. }
  91.