Project

General

Profile

1
<?php
2
/*
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18

    
19
/**
20
 * cmdUpgrade.php
21
 *
22
 * @category     Addons
23
 * @package      Addons_wrapper
24
 * @copyright    Manuela v.d.Decken <manuela@isteam.de>
25
 * @author       Manuela v.d.Decken <manuela@isteam.de>
26
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
27
 * @version      3.0.1
28
 * @lastmodified $Date: 2017-07-02 17:14:29 +0200 (Sun, 02 Jul 2017) $
29
 * @since        File available since 2015-12-17
30
 * @description  xyz
31
 */
32
/* -------------------------------------------------------- */
33
// Must include code to stop this file being accessed directly
34
if (!defined('WB_PATH')) { throw new Exception('Cannot access the addon \"'.basename(__DIR__).'\" directly'); }
35
/* -------------------------------------------------------- */
36

    
37
    $sSqlDumpFile = $sAddonPath.'/install-struct.sql';
38
    if (is_readable($sSqlDumpFile)) {
39
        // upgrade database tables
40
        $database->SqlImport($sSqlDumpFile, TABLE_PREFIX, __FILE__);
41
    }
42
// sanitize mod_wrapper.url
43
    $msg = '';
44
    $sql = 'SELECT `section_id`, `url` FROM `'.TABLE_PREFIX.'mod_wrapper` '
45
         . 'WHERE `url` NOT LIKE \'http%\'';
46
    if (($oInstances = $database->query($sql))) {
47
        while (($aInstance = $oInstances->fetchRow(MYSQLI_ASSOC))) {
48
            // add WB_URL to relative URLs
49
            $sNewUrl = WB_URL.'/'.ltrim($aInstance['url'], '\\/');
50
            $sql = 'UPDATE `'.TABLE_PREFIX.'mod_wrapper` '
51
                 . 'SET `url`=\''.$database->escapeString($sNewUrl).'\' '
52
                 . 'WHERE `section_id`='.(int)$aInstance['section_id'];
53
            if (!$database->query($sql)) {
54
                $msg = $database->get_error();
55
                break;
56
            }
57
        }
58
    } else { $msg = $database->get_error(); }
59
// replace local host by SYSVAR-Tag in mod_wrapper.url
60
    $sql = 'SELECT `section_id`, `url` FROM `'.TABLE_PREFIX.'mod_wrapper`';
61
    if (($oInstances = $database->query($sql))) {
62
        while (($aInstance = $oInstances->fetchRow(MYSQLI_ASSOC))) {
63
            // add WB_URL to relative URLs
64
            $sNewUrl = preg_replace(
65
                '/^'.preg_quote(str_replace('\\', '/', WB_URL).'/', '/').'/si',
66
                '{SYSVAR:AppUrl}',
67
                ltrim(str_replace('\\', '/', $aInstance['url']), '/')
68
            );
69
            $sql = 'UPDATE `'.TABLE_PREFIX.'mod_wrapper` '
70
                 . 'SET `url`=\''.$database->escapeString($sNewUrl).'\' '
71
                 . 'WHERE `section_id`='.(int)$aInstance['section_id'];
72
            if (!$database->query($sql)) {
73
                $msg = $database->get_error();
74
                break;
75
            }
76
        }
77
    } else { $msg = $database->get_error(); }
78

    
79
// end of file
80

    
(6-6/7)