Rev 1219 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
360 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
511 | daniel-mar | 5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
360 | daniel-mar | 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 | |||
1050 | daniel-mar | 20 | use ViaThinkSoft\OIDplus\OIDplusDatabaseConnection; |
21 | |||
386 | daniel-mar | 22 | /** |
23 | * This function will be called by OIDplusDatabaseConnection.class.php at method afterConnect(). |
||
24 | * @param OIDplusDatabaseConnection $db is the OIDplusDatabaseConnection class |
||
830 | daniel-mar | 25 | * @return int new version set |
1050 | daniel-mar | 26 | * @throws \ViaThinkSoft\OIDplus\OIDplusException |
386 | daniel-mar | 27 | */ |
1130 | daniel-mar | 28 | function oidplus_dbupdate_201(OIDplusDatabaseConnection $db): int { |
830 | daniel-mar | 29 | if ($db->transaction_supported()) $db->transaction_begin(); |
1231 | daniel-mar | 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"); |
||
558 | daniel-mar | 36 | |
1231 | daniel-mar | 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"); |
||
558 | daniel-mar | 40 | |
1231 | daniel-mar | 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"); |
||
558 | daniel-mar | 44 | |
1231 | daniel-mar | 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"); |
||
558 | daniel-mar | 48 | |
1231 | daniel-mar | 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"); |
||
558 | daniel-mar | 52 | |
1231 | daniel-mar | 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"); |
||
558 | daniel-mar | 56 | |
1231 | daniel-mar | 57 | $db->query("alter table ###objects alter confidential type boolean using get_bit(confidential,0)::boolean"); |
558 | daniel-mar | 58 | |
1231 | daniel-mar | 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 | } |
||
558 | daniel-mar | 72 | |
1231 | daniel-mar | 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 | } |
||
558 | daniel-mar | 79 | |
1231 | daniel-mar | 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; |
||
830 | daniel-mar | 87 | } |
558 | daniel-mar | 88 | |
830 | daniel-mar | 89 | return $version; |
90 | } |