Subversion Repositories oidplus

Rev

Rev 360 | Rev 511 | 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 2020 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.  * @param string $version is the current version (this script MUST increase the number by 1 when it is done)
  24.  * @throws OIDplusException
  25.  */
  26. function oidplus_dbupdate_201_202(OIDplusDatabaseConnection $db, string &$version) {
  27.     if ($db->transaction_supported()) $db->transaction_begin();
  28.    
  29.     // Change bit(1) types to boolean/tinyint(1)
  30.     if ($db->getSlang()::id() == 'pgsql') {
  31.         $db->query("alter table ###config  alter protected    drop default");
  32.         $db->query("alter table ###config  alter protected    type boolean using get_bit(protected   ,0)::boolean");
  33.         $db->query("alter table ###config  alter protected    set default false");
  34.    
  35.         $db->query("alter table ###config  alter visible      drop default");
  36.         $db->query("alter table ###config  alter visible      type boolean using get_bit(visible     ,0)::boolean");
  37.         $db->query("alter table ###config  alter visible      set default false");
  38.    
  39.         $db->query("alter table ###asn1id  alter standardized drop default");
  40.         $db->query("alter table ###asn1id  alter standardized type boolean using get_bit(standardized,0)::boolean");
  41.         $db->query("alter table ###asn1id  alter standardized set default false");
  42.    
  43.         $db->query("alter table ###asn1id  alter well_known   drop default");
  44.         $db->query("alter table ###asn1id  alter well_known   type boolean using get_bit(well_known  ,0)::boolean");
  45.         $db->query("alter table ###asn1id  alter well_known   set default false");
  46.    
  47.         $db->query("alter table ###iri     alter longarc      drop default");
  48.         $db->query("alter table ###iri     alter longarc      type boolean using get_bit(longarc     ,0)::boolean");
  49.         $db->query("alter table ###iri     alter longarc      set default false");
  50.    
  51.         $db->query("alter table ###iri     alter well_known   drop default");
  52.         $db->query("alter table ###iri     alter well_known   type boolean using get_bit(well_known  ,0)::boolean");
  53.         $db->query("alter table ###iri     alter well_known   set default false");
  54.    
  55.         $db->query("alter table ###objects alter confidential type boolean using get_bit(confidential,0)::boolean");
  56.    
  57.         $db->query("alter table ###ra      alter privacy      drop default");
  58.         $db->query("alter table ###ra      alter privacy      type boolean using get_bit(privacy     ,0)::boolean");
  59.         $db->query("alter table ###ra      alter privacy      set default false");
  60.     } else if ($db->getSlang()::id() == 'mysql') {
  61.         $db->query("alter table ###config  modify protected    boolean");
  62.         $db->query("alter table ###config  modify visible      boolean");
  63.         $db->query("alter table ###asn1id  modify standardized boolean");
  64.         $db->query("alter table ###asn1id  modify well_known   boolean");
  65.         $db->query("alter table ###iri     modify longarc      boolean");
  66.         $db->query("alter table ###iri     modify well_known   boolean");
  67.         $db->query("alter table ###objects modify confidential boolean");
  68.         $db->query("alter table ###ra      modify privacy      boolean");
  69.     }
  70.    
  71.     // Rename log_user.user to log_user.username, since user is a keyword in PostgreSQL and MSSQL
  72.     if ($db->getSlang()::id() == 'pgsql') {
  73.         $db->query("alter table ###log_user rename column \"user\" to \"username\"");
  74.     } else if ($db->getSlang()::id() == 'mysql') {
  75.         $db->query("alter table ###log_user change `user` `username` varchar(255) NOT NULL");
  76.     }
  77.    
  78.     $version = 202;
  79.     $db->query("UPDATE ###config SET value = ? WHERE name = 'database_version'", array($version));
  80.    
  81.     if ($db->transaction_supported()) $db->transaction_commit();
  82. }