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
 * upgrade.php
21
 * 
22
 * @category     Module
23
 * @package      Module_form
24
 * @subpackage   upgrade
25
 * @author       Dietmar Wöllbrink <dietmar.woellbrink@websitebaker.org>
26
 * @author       Werner v.d.Decken <wkl@isteam.de>
27
 * @copyright    Werner v.d.Decken <wkl@isteam.de>
28
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
29
 * @version      0.0.1
30
 * @revision     $Revision: 1890 $
31
 * @link         $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/form/upgrade.php $
32
 * @lastmodified $Date: 2013-03-19 11:45:14 +0100 (Tue, 19 Mar 2013) $
33
 * @since        File available since 17.01.2013
34
 * @description  xyz
35
 * 
36
 */
37

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

    
46
//if(!function_exists('mod_form_upgrade')){
47
	function mod_form_upgrade($bDebug=false) {
48
		global $OK ,$FAIL;
49
		$database=WbDatabase::getInstance();
50
		$msg = array();
51
		$callingScript = $_SERVER["SCRIPT_NAME"];
52
		// check if upgrade startet by upgrade-script to echo a message
53
		$tmp = 'upgrade-script.php';
54
		$globalStarted = substr_compare($callingScript, $tmp,(0-strlen($tmp)),strlen($tmp)) === 0;
55
// check for missing tables, if true stop the upgrade
56
		$aTable = array('mod_form_fields','mod_form_settings','mod_form_submissions');
57
		$aPackage = UpgradeHelper::existsAllTables($aTable);
58
		if( sizeof($aPackage) > 0){
59
			$msg[] =  'TABLE '.implode(' missing! '.$FAIL.'<br />TABLE ',$aPackage).' missing! '.$FAIL;
60
			$msg[] = 'Form upgrade failed'." $FAIL";
61
			if($globalStarted) {
62
				echo '<strong>'.implode('<br />',$msg).'</strong><br />';
63
			}
64
			return ( ($globalStarted==true ) ? $globalStarted : $msg);
65
		} else {
66
			for($x=0; $x<sizeof($aTable);$x++) {
67
				if(($sOldType = $database->getTableEngine($database->TablePrefix.$aTable[$x]))) {
68
					if(('myisam' != strtolower($sOldType))) {
69
						if(!$database->query('ALTER TABLE `'.$database->TablePrefix.$aTable[$x].'` Engine = \'MyISAM\' ')) {
70
							$msg[] = $database->get_error();
71
						} else{
72
							$msg[] = 'TABLE `'.$database->TablePrefix.$aTable[$x].'` changed to Engine = \'MyISAM\''." $OK";
73
						}
74
					} else {
75
						$msg[] = 'TABLE `'.$database->TablePrefix.$aTable[$x].'` has Engine = \'MyISAM\''." $OK";
76
					}
77
				} else {
78
					$msg[] = $database->get_error();
79
				}
80
			}
81
			$table_name = $database->TablePrefix.'mod_form_settings';
82
			$field_name = 'perpage_submissions';
83
			$description = "INT NOT NULL DEFAULT '10' AFTER `max_submissions`";
84
			if(!$database->field_exists($table_name,$field_name)) {
85
				$database->field_add($table_name, $field_name, $description);
86
				$msg[] = 'Add field `perpage_submissions` AFTER `max_submissions`';
87
			} else {
88
				$msg[] = 'Field `perpage_submissions` already exists'." $OK";
89
			}
90
// only for upgrade-script
91
			if($globalStarted) {
92
				if($bDebug) {
93
					echo '<strong>'.implode('<br />',$msg).'</strong><br />';
94
				}
95
			}
96
		}
97
		$msg[] = 'Form upgrade successfull finished ';
98
		if($globalStarted) {
99
			echo "<strong>Form upgrade successfull finished $OK</strong><br />";
100
		}
101
		return ( ($globalStarted==true ) ? $globalStarted : $msg);
102
	}
103
//}
104
// ------------------------------------
105

    
106
$bDebugModus = ((isset($bDebugModus)) ? $bDebugModus : false);
107
if( is_array($msg = mod_form_upgrade($bDebugModus))) {
108
	echo '<strong>'.implode('<br />',$msg).'</strong><br />';
109
}
(23-23/25)