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
 * upgrade.php
19
 *
20
 * @category     Module
21
 * @package      Module_form
22
 * @subpackage   upgrade
23
 * @author       Dietmar Wöllbrink <dietmar.woellbrink@websitebaker.org>
24
 * @author       Werner v.d.Decken <wkl@isteam.de>
25
 * @copyright    Werner v.d.Decken <wkl@isteam.de>
26
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
27
 * @version      0.0.1
28
 * @revision     $Revision: 2 $
29
 * @link         $HeadURL: svn://isteam.dynxs.de/wb/2.10.x/branches/main/modules/form/upgrade.php $
30
 * @lastmodified $Date: 2017-07-02 17:14:29 +0200 (Sun, 02 Jul 2017) $
31
 * @since        File available since 17.01.2013
32
 * @description  xyz
33
 *
34
 */
35

    
36
/* -------------------------------------------------------- */
37
// Must include code to stop this file being accessed directly
38
if(!defined('WB_URL')) {
39
    require_once(dirname(dirname(dirname(__FILE__))).'/framework/globalExceptionHandler.php');
40
    throw new IllegalFileException();
41
}
42
/* -------------------------------------------------------- */
43

    
44
//if(!function_exists('mod_form_upgrade')){
45
    function mod_form_upgrade($bDebug=false) {
46
        global $OK ,$FAIL, $callingScript, $globalStarted;
47
        $oDb = ( @$GLOBALS['database'] ?: null );
48
        $msg = array();
49
        if (is_writable(WB_PATH.'/temp/cache')) {
50
            Translate::getInstance()->clearCache();
51
        }
52
        $getMissingTables = (function (array $aTablesList) use ( $oDb )
53
        {
54
            $aTablesList = array_flip($aTablesList);
55
            $sPattern =  $oDb->escapeString( TABLE_PREFIX, '%_' );
56
            $sql = 'SHOW TABLES LIKE \''.$sPattern.'%\'';
57
            if (($oTables = $oDb->query( $sql ))) {
58
                while ($aTable = $oTables->fetchRow(MYSQLI_NUM)) {
59
                    $sTable =  preg_replace('/^'.preg_quote(TABLE_PREFIX, '/').'/s', '', $aTable[0]);
60
                    if (isset($aTablesList[$sTable])) {
61
                        unset($aTablesList[$sTable]);
62
                    }
63
                }
64
            }
65
            return array_flip($aTablesList);
66
        });
67

    
68
// check for missing tables, if true stop the upgrade
69
        $aTable = array('mod_form_fields','mod_form_settings','mod_form_submissions');
70
        $aPackage = $getMissingTables($aTable);
71

    
72
        if( sizeof($aPackage) > 0){
73
            $msg[] =  'TABLE '.implode(' missing! '.$FAIL.'<br />TABLE ',$aPackage).' missing! '.$FAIL;
74
            $msg[] = 'Form upgrade failed'." $FAIL";
75
            if(!$globalStarted) {
76
//                echo '<strong>'.implode('<br />',$msg).'</strong><br />';
77
            }
78
            return ( ($globalStarted==true ) ? $globalStarted : $msg);
79
        } else {
80
            for($x=0; $x<sizeof($aTable);$x++) {
81
                if(($sOldType = $oDb->getTableEngine(TABLE_PREFIX.$aTable[$x]))) {
82
                    if(('myisam' != strtolower($sOldType))) {
83
                        if(!$oDb->query('ALTER TABLE `'.TABLE_PREFIX.$aTable[$x].'` Engine = \'MyISAM\' ')) {
84
                            $msg[] = $oDb->get_error();
85
                        } else{
86
                            $msg[] = 'TABLE `'.TABLE_PREFIX.$aTable[$x].'` changed to Engine = \'MyISAM\''." $OK";
87
                        }
88
                    } else {
89
                        $msg[] = 'TABLE `'.TABLE_PREFIX.$aTable[$x].'` has Engine = \'MyISAM\''." $OK";
90
                    }
91
                } else {
92
//                    $msg[] = $oDb->get_error();
93
                }
94
            }
95

    
96
            $table_name = TABLE_PREFIX.'mod_form_settings';
97
            $field_name = 'perpage_submissions';
98
            $description = "INT NOT NULL DEFAULT '10' AFTER `max_submissions`";
99
            if(!$oDb->field_exists($table_name,$field_name)) {
100
                $oDb->field_add($table_name, $field_name, $description);
101
                $msg[] = 'Add field `perpage_submissions` AFTER `max_submissions`';
102
            } else {
103
                $msg[] = 'Field `perpage_submissions` already exists'." $OK";
104
            }
105
// only for upgrade-script
106
            if (!$globalStarted) {
107
                if($bDebug) {
108
                    $msg[] = '<strong>'.implode('<br />',$msg).'</strong><br />';
109
                }
110
            }
111
        }
112
        $msg[] = 'Form upgrade successfull finished ';
113
        if(!$globalStarted) {
114
            $msg[] = "<strong>Form upgrade successfull finished $OK</strong><br />";
115
        }
116
        $msg = [];
117
        return ( ($globalStarted==true ) ? $globalStarted : $msg);
118
    }
119
//}
120
// ------------------------------------
121

    
122
    $bDebugModus = ((isset($bDebugModus)) ? $bDebugModus : false);
123
    $callingScript = $_SERVER["SCRIPT_NAME"];
124
    // check if upgrade startet by upgrade-script to echo a message
125
    $globalStarted = preg_match('/upgrade\-script\.php$/', $callingScript);
126

    
127
/*
128
    $tmp = 'upgrade-script.php';
129
    $globalStarted = substr_compare($callingScript, $tmp,(0-strlen($tmp)),strlen($tmp)) === 0;
130
*/
131
if( is_array($msg = mod_form_upgrade($bDebugModus))) {
132
    if (!$globalStarted) {print implode("\n", $msg)."\n";}
133
//    echo '<strong>'.implode('<br />',$msg).'</strong><br />';
134
}
135

    
(26-26/28)