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