Subversion Repositories oidplus

Rev

Rev 855 | Rev 1080 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 855 Rev 1050
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 * OIDplus 2.0
4
 * OIDplus 2.0
5
 * Copyright 2019 - 2022 Daniel Marschall, ViaThinkSoft
5
 * Copyright 2019 - 2022 Daniel Marschall, ViaThinkSoft
6
 *
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with 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
9
 * You may obtain a copy of the License at
10
 *
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
17
 * limitations under the License.
18
 */
18
 */
19
 
19
 
-
 
20
use ViaThinkSoft\OIDplus\OIDplusDatabaseConnection;
-
 
21
use ViaThinkSoft\OIDplus\OIDplusConfigInitializationException;
-
 
22
use ViaThinkSoft\OIDplus\OIDplusException;
-
 
23
 
20
/**
24
/**
21
 * This function will be called by OIDplusDatabaseConnection.class.php at method afterConnect().
25
 * This function will be called by OIDplusDatabaseConnection.class.php at method afterConnect().
22
 * @param OIDplusDatabaseConnection $db is the OIDplusDatabaseConnection class
26
 * @param OIDplusDatabaseConnection $db is the OIDplusDatabaseConnection class
23
 * @throws OIDplusException
27
 * @throws \ViaThinkSoft\OIDplus\OIDplusException
24
 */
28
 */
25
function oidplus_dbupdate(OIDplusDatabaseConnection $db) {
29
function oidplus_dbupdate(OIDplusDatabaseConnection $db) {
26
        // Detect database version
30
        // Detect database version
27
        $res = $db->query("SELECT value FROM ###config WHERE name = 'database_version'");
31
        $res = $db->query("SELECT value FROM ###config WHERE name = 'database_version'");
28
        $row = $res->fetch_array();
32
        $row = $res->fetch_array();
29
        if ($row == null) {
33
        if ($row == null) {
30
                // Note: The config setting "database_version" is inserted in setup/sql/...sql, not in the OIDplus core init
34
                // 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)'));
35
                throw new OIDplusConfigInitializationException(_L('Cannot determine database version (the entry "database_version" inside the table "###config" is probably missing)'));
32
        }
36
        }
33
        $version = $row['value'];
37
        $version = $row['value'];
34
        if (!is_numeric($version)) {
38
        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)'));
39
                throw new OIDplusConfigInitializationException(_L('Entry "database_version" inside the table "###config" seems to be wrong (expect number between 200 and 999)'));
36
        }
40
        }
37
 
41
 
38
        // Upgrade from old versions
42
        // Upgrade from old versions
39
        try {
43
        try {
40
                if ($version == 200) {
44
                if ($version == 200) {
41
                        // Update 200 => 201
45
                        // Update 200 => 201
42
                        require_once __DIR__.'/update200.inc.php';
46
                        require_once __DIR__.'/update200.inc.php';
43
                        $version = oidplus_dbupdate_200($db);
47
                        $version = oidplus_dbupdate_200($db);
44
                }
48
                }
45
                if ($version == 201) {
49
                if ($version == 201) {
46
                        // Update 201 => 202
50
                        // Update 201 => 202
47
                        require_once __DIR__.'/update201.inc.php';
51
                        require_once __DIR__.'/update201.inc.php';
48
                        $version = oidplus_dbupdate_201($db);
52
                        $version = oidplus_dbupdate_201($db);
49
                }
53
                }
50
                if ($version == 202) {
54
                if ($version == 202) {
51
                        // Update 202 => 203
55
                        // Update 202 => 203
52
                        require_once __DIR__.'/update202.inc.php';
56
                        require_once __DIR__.'/update202.inc.php';
53
                        $version = oidplus_dbupdate_202($db);
57
                        $version = oidplus_dbupdate_202($db);
54
                }
58
                }
55
                if ($version == 203) {
59
                if ($version == 203) {
56
                        // Update 203 => 204
60
                        // Update 203 => 204
57
                        require_once __DIR__.'/update203.inc.php';
61
                        require_once __DIR__.'/update203.inc.php';
58
                        $version = oidplus_dbupdate_203($db);
62
                        $version = oidplus_dbupdate_203($db);
59
                }
63
                }
60
                if ($version == 204) {
64
                if ($version == 204) {
61
                        // Update 204 => 205
65
                        // Update 204 => 205
62
                        require_once __DIR__.'/update204.inc.php';
66
                        require_once __DIR__.'/update204.inc.php';
63
                        $version = oidplus_dbupdate_204($db);
67
                        $version = oidplus_dbupdate_204($db);
64
                }
68
                }
65
                if ($version == 205) {
69
                if ($version == 205) {
66
                        // Update 205 => 1000
70
                        // Update 205 => 1000
67
                        require_once __DIR__.'/update205.inc.php';
71
                        require_once __DIR__.'/update205.inc.php';
68
                        $version = oidplus_dbupdate_205($db);
72
                        $version = oidplus_dbupdate_205($db);
69
                }
73
                }
70
                if ($version == 1000) {
74
                if ($version == 1000) {
71
                        // Update 1000 => 1001
75
                        // Update 1000 => 1001
72
                        require_once __DIR__.'/update1001.inc.php';
76
                        require_once __DIR__.'/update1001.inc.php';
73
                        $version = oidplus_dbupdate_1001($db);
77
                        $version = oidplus_dbupdate_1001($db);
74
                }
78
                }
75
        } catch (Exception $e) {
79
        } catch (\Exception $e) {
76
                throw new OIDplusException(_L('Database update from version %1 failed: %2',$version,$e->getMessage()));
80
                throw new OIDplusException(_L('Database update from version %1 failed: %2',$version,$e->getMessage()));
77
        }
81
        }
78
 
82
 
79
        // Don't allow if the database version if newer than we expect
83
        // Don't allow if the database version if newer than we expect
80
        if ($version > 1001) {
84
        if ($version > 1001) {
81
                throw new OIDplusException(_L('The version of the database is newer than the program version. Please upgrade your program version.'));
85
                throw new OIDplusException(_L('The version of the database is newer than the program version. Please upgrade your program version.'));
82
        }
86
        }
83
}
87
}
84
 
88