Project

General

Profile

« Previous | Next » 

Revision 2012

Added by darkviper almost 11 years ago

! upgrade-script:: now repairs mismatched pagelinks from older versions
! upgrade-script:: /temp/TranslationTable/cache/ will be deleted now during upgrade
+ UpgradeHelper::checkSetupFiles() the old config.php will be changed into setup.ini.php now.

View differences:

branches/2.8.x/CHANGELOG
11 11
! = Update/Change
12 12
===============================================================================
13 13

  
14
03 Nov-2013 Build 2012 Manuela v.d.Decken(DarkViper)
15
! upgrade-script:: now repairs mismatched pagelinks from older versions
16
! upgrade-script:: /temp/TranslationTable/cache/ will be deleted now during upgrade
17
+ UpgradeHelper::checkSetupFiles() the old config.php will be changed into setup.ini.php now.
14 18
03 Nov-2013 Build 2011 Manuela v.d.Decken(DarkViper)
15 19
! WbDatabase added method fetchObject()
16 20
! WbAdaptor little typofixes
branches/2.8.x/wb/upgrade-script.php
34 34
 * @deprecated   
35 35
 * @description  xyz
36 36
 */
37
include_once(dirname(__FILE__).'/framework/UpgradeHelper.php');
38

  
37 39
// --- delete fatal disturbing files before upgrade starts -------------------------------
38 40
$aPreDeleteFiles = array(
39 41
// list of files
......
58 60
	}
59 61
	if($sMsg) {
60 62
	// stop script if there's an error occured
61
		$sMsg = 'Fatal error occured during initial startup.<br /><br />'.PHP_EOL.$sMsg
62
		      . '<br />'.PHP_EOL.'Please delete all of the files above manually and '
63
		      . 'then <a href="http://'.$_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"].'" '
64
		      . 'title="restart">klick here to restart the upgrade-script</a>.<br />'.PHP_EOL;
65
		die($sMsg);
63
		$sMsg = $sMsg.'<br />'.PHP_EOL.'Please delete all of the files above manually!';
64
		UpgradeHelper::dieWithMessage($sMsg);
66 65
	}
67 66
}
68 67
unset($aPreDeleteFiles);
......
70 69
// ---------------------------------------------------------------------------------------
71 70
// Include config file
72 71
$config_file = dirname(__FILE__).'/config.php';
73
if(file_exists($config_file) && !defined('WB_URL'))
74
{
75
	require($config_file);
72
if (is_readable($config_file) && !defined('WB_URL')) {
73
	require_once($config_file);
76 74
}
77
if(!class_exists('admin', false))
78
{ 
75
UpgradeHelper::checkSetupFiles($config_file);
76

  
77
if (!class_exists('admin', false)) {
79 78
	include(WB_PATH.'/framework/class.admin.php');
80 79
}
81 80
$admin = new admin('Addons', 'modules', false, false);
......
915 914
     */
916 915
	echo '<h4>Upgrade pages directory '.PAGES_DIRECTORY.'/  access files</h4>';
917 916

  
917
	/**********************************************************
918
	 * Repair inconsistent PageTree
919
	 */
920
	$iCount = UpgradeHelper::sanitizePagesTreeLinkStructure();
921
	if (false === $iCount) {
922
		echo '<span><strong>Repair PageTree links </strong></span> '.$FAIL.'<br />';
923
	} else {
924
		echo '<span><strong>'.$iCount.' PageTree links repaired.</strong></span> '.$OK.'<br />';
925
	}
918 926
    /**********************************************************
919 927
     *  - Reformat/rebuild all existing access files
920 928
     */
......
1153 1161
		closedir($handle);
1154 1162
	}
1155 1163
	echo '<strong><span>'.$iLoaded.' Templates reloaded,</span> found '.$iFound.' directories in folder /templates/</strong><br />';
1156

  
1157 1164
	$iFound = 0;
1158 1165
	$iLoaded = 0;
1159 1166
	////delete languages
......
1169 1176
		closedir($handle);
1170 1177
	}
1171 1178
	echo '<strong><span>'.$iLoaded.' Languages reloaded,</span> found '.$iFound.' files in folder /languages/</strong><br />';
1179
	$sTransCachePath = WB_PATH.'/temp/TranslationTable/cache/';
1180
	if (is_writeable($sTransCachePath)) {
1181
		if (rm_full_dir($sTransCachePath, true)) {
1182
			echo '<strong><span>Translation Cache cleaned</span></strong> '.$OK.'<br />';
1183
		} else {
1184
			echo '<strong><span>Clean Translation Cache</span></strong> '.$FAIL.'<br />';
1185
		}
1186
	}
1172 1187
	echo '</div>';
1173 1188

  
1174 1189
/**********************************************************
branches/2.8.x/wb/admin/interface/version.php
51 51

  
52 52
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
53 53
if(!defined('VERSION')) define('VERSION', '2.8.3');
54
if(!defined('REVISION')) define('REVISION', '2011');
54
if(!defined('REVISION')) define('REVISION', '2012');
55 55
if(!defined('SP')) define('SP', '');
branches/2.8.x/wb/framework/UpgradeHelper.php
45 45
		$aTablesList = array_flip($aTablesList);
46 46
		$oDb = WbDatabase::getInstance();
47 47
		$sPattern = addcslashes ( $oDb->TablePrefix, '%_' );
48
		if(($oTables = $oDb->query( 'SHOW TABLES LIKE "'.$sPattern.'%"'))) {
49
			while($aTable = $oTables->fetchRow(MYSQL_NUM)) {
48
		if (($oTables = $oDb->query( 'SHOW TABLES LIKE "'.$sPattern.'%"'))) {
49
			while ($aTable = $oTables->fetchRow(MYSQL_NUM)) {
50 50
				$sTable =  preg_replace('/^'.preg_quote($oDb->TablePrefix, '/').'/s', '', $aTable[0]);
51
				if(isset($aTablesList[$sTable])) {
51
				if (isset($aTablesList[$sTable])) {
52 52
					unset($aTablesList[$sTable]);
53 53
				}
54 54
			}
......
64 64
	{
65 65
		return self::getMissingTables($aTablesList);
66 66
	}
67
/**
68
 * Sanitize and repair Pagetree links
69
 * @return boolean|int number of updated records or false on error
70
 */
71
	public static function sanitizePagesTreeLinkStructure()
72
	{
73
		$oDb = WbDatabase::getInstance();
74
		$iCounter = 0;
75
		$aPages = array();
76
		try {
77
			$sql = 'SELECT `page_id`, `link`, `page_trail` '
78
				 . 'FROM `'.$oDb->TablePrefix.'pages` '
79
				 . 'ORDER BY `page_id`';
80
			$oPages = $oDb->doQuery($sql);
81
			// read 'page_id', 'link' and 'page_trail' from all pages
82
			while ($aPage = $oPages->fetchRow(MYSQL_ASSOC)) {
83
				// extact filename only from complete link
84
				$aPages[$aPage['page_id']]['filename'] = preg_replace('/.*?\/([^\/]*$)/', '\1', $aPage['link']);
85
				$aPages[$aPage['page_id']]['page_trail'] = $aPage['page_trail'];
86
				$aPages[$aPage['page_id']]['link'] = $aPage['link'];
87
			}
88
			foreach ($aPages as $iKey=>$aRecord) {
89
			// iterate all pages
90
				$aTmp = array();
91
				$aIds = explode(',', $aRecord['page_trail']);
92
				// rebuild link from filenames using page_trail
93
				foreach($aIds as $iId) {
94
					$aTmp[] = $aPages[$iId]['filename'];
95
				}
96
				$sLink = '/'.implode('/', $aTmp);
97
				if ($sLink != $aPages[$iKey]['link']) {
98
				// update page if old link is different to new generated link
99
					$sql = 'UPDATE `'.$oDb->TablePrefix.'pages` '
100
						 . 'SET `link`=\''.$sLink.'\' '
101
						 . 'WHERE `page_id`='.$iKey;
102
					$oDb->doQuery($sql);
103
					$iCounter++;
104
				}
105
			}
106
		} catch(WbDatabaseException $e) {
107
			return false;
108
		}
109
		return $iCounter;
110
	}
111
/**
112
 *
113
 * @param string $sMsg Message to show
114
 */
115
	public static function dieWithMessage($sMsg)
116
	{
117
		$sMsg = 'Fatal error occured during initial startup.<br /><br />'.PHP_EOL.$sMsg
118
			  . '<br />'.PHP_EOL.'Please correct these errors and then '
119
			  . '<a href="http://'.$_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"].'" '
120
			  . 'title="restart">klick here to restart the upgrade-script</a>.<br />'.PHP_EOL;
121
		die($sMsg);
122
	}
123
/**
124
 *
125
 * @param string $sAppPath path to the current installation
126
 * @return boolean
127
 */
128
	public static function checkSetupFiles($sAppPath)
129
	{
130
		if (defined('DB_PASSWORD')) {
131
		// old config.php is active
132
			if (!is_writable($sAppPath.'config.php') || !is_writable($sAppPath.'config.php.new') || !is_writable($sAppPath.'setup.ini.php.new'))
133
			{
134
			// stop script if there's an error occured
135
				$sMsg = 'Following files must exist and be writable to run upgrade:<br />'
136
				      . '<ul><li>config.php</li>'.(file_exists($sAppPath.'config.php.new') ? '<li>config.php.new</li>' : '')
137
				      . '<li>setup.ini.php.new</li></ul>';
138
				self::dieWithMessage($sMsg);
139
			} else { // ok, let's change the files now!
140
				if (file_exists($aAppPath.'setup.ini.php')) {
141
				// if 'setup.ini.php' exists
142
					if (!is_writeable($aAppPath.'setup.ini.php')) {
143
					// but it's not writable
144
						$sMsg = 'The file \'setup.ini.php\' already exists but is not writeable!';
145
						self::dieWithMessage($sMsg);
146
					}
147
				} else {
148
				// try to rename 'setup.ini.php.new' into 'setup.ini.php'
149
					if (!rename($aAppPath.'setup.ini.php.new', $aAppPath.'setup.ini.php')) {
150
						$sMsg = 'Can not rename \''.$aAppPath.'setup.ini.php.new\' into \''.$aAppPath.'setup.ini.php\' !!<br />'
151
						      . 'Create an empty file \''.$aAppPath.'setup.ini.php\' and make it writeable for the server!';
152
						self::dieWithMessage($sMsg);
153
					}
154
				}
155
			// now first read constants from old config.php
156
				$sContent = file_get_contents($sAppPath.'config.php');
157
				$sPattern = '/^\s*define\s*\(\s*([\'\"])(.*?)\1\s*,.*;\s*$/m';
158
				if (preg_match_all($sPattern, $sContent, $aMatches)) {
159
				// get all already defined consts
160
					$aAllConsts = get_defined_constants(true);
161
					$aSetupConsts = array();
162
				// collect the needed values from defined consts
163
					foreach($aMatches[2] as $sConstName) {
164
						$aSetupConsts[$sConstName] = (isset($aAllConsts['user'][$sConstName]) ? $aAllConsts['user'][$sConstName] : '');
165
					}
166
				// try to sanitize available values
167
					$aSetupConsts['DB_TYPE'] = ((isset($aSetupConsts['DB_TYPE']) && $aSetupConsts['DB_TYPE'] != '') ? $aSetupConsts['DB_TYPE'] : 'mysql');
168
					$aSetupConsts['DB_PORT'] = ((isset($aSetupConsts['DB_PORT']) && $aSetupConsts['DB_PORT'] != '') ? $aSetupConsts['DB_PORT'] : '3306');
169
					$aSetupConsts['DB_CHARSET'] = (isset($aSetupConsts['DB_CHARSET']) ? $aSetupConsts['DB_CHARSET'] : '');
170
					$aSetupConsts['DB_CHARSET'] = preg_replace('/[^0-9a-z]*/i', '', $aSetupConsts['DB_CHARSET']);
171
					$aSetupConsts['TABLE_PREFIX'] = (isset($aSetupConsts['TABLE_PREFIX']) ? $aSetupConsts['TABLE_PREFIX'] : '');
172
					$aSetupConsts['ADMIN_DIRECTORY'] = trim(str_replace('\\', '/', preg_replace('/^'.preg_quote(WB_PATH, '/').'/', '', ADMIN_PATH)), '/').'/';
173
					$aSetupConsts['WB_URL'] = rtrim(str_replace('\\', '/', WB_URL), '/').'/';
174
				// Try and write settings to config file
175
					if (writeSetupIni($sAppPath, $aSetupConsts)) {
176
						if (writeConfig($sAppPath)) {
177
							return true;
178
						} else {
179
							$sMsg ='Error writing \''.$sAppPath.'config.php\'!';
180
						}
181
					} else {
182
						$sMsg ='Error writing \''.$sAppPath.'setup.ini.php\'!';
183
					}
184
				} else {
185
					$sMsg = 'No valid content found in \''.$sAppPath.'config.php\'!';
186
				}
187
				self::dieWithMessage($sMsg);
188
			}
189
		} else {
190
			$sFileContent = file_get_contents($sAppPath.'config.php');
191
			if (preg_match('/\s*define\s*\(.*\)\s*;/i', $sFileContent)) {
192
			// if config.php does not contain any defines
193
				if (is_writable($sAppPath.'config.php')) {
194
				// overwrite config.php with default content for compatibility
195
					if (self::writeConfig($sAppPath.'config.php')) {
196
						return true;
197
					} else  {
198
						$sMsg ='Error writing \''.$sAppPath.'config.php\'!';
199
					}
200
				} else {
201
					$sMsg ='File is not writable \''.$sAppPath.'config.php\'!';
202
				}
203
				self::dieWithMessage($sMsg);
204
			}
205
		}
206
	}
207
/**
208
 *
209
 * @param string $sAppPath the path where setup.ini.php is located
210
 * @param array  $aSetupValues
211
 * @return boolean
212
 */
213
	public static function writeSetupIni($sAppPath, array $aSetupValues)
214
	{
215
		$sSetupContent =
216
			";<?php die('sorry, illegal file access'); ?>#####\n"
217
		   .";################################################\n"
218
		   ."; WebsiteBaker configuration file\n"
219
		   ."; auto generated ".date('Y-m-d h:i:s A e ')."\n"
220
		   .";################################################\n"
221
		   ."[Constants]\n"
222
		   ."DEBUG   = false\n"
223
		   ."AppUrl  = \"".$aSetupValues['WB_URL']."\"\n"
224
		   ."AcpDir  = \"".$aSetupValues['ADMIN_DIRECTORY']."\"\n"
225
		   .";##########\n"
226
		   ."[DataBase]\n"
227
		   ."type    = \"".$aSetupValues['DB_TYPE']."\"\n"
228
		   ."user    = \"".$aSetupValues['DB_USERNAME']."\"\n"
229
		   ."pass    = \"".$aSetupValues['DB_PASSWORD']."\"\n"
230
		   ."host    = \"".$aSetupValues['DB_HOST']."\"\n"
231
		   ."port    = \"".$aSetupValues['DB_PORT']."3306\"\n"
232
		   ."name    = \"".$aSetupValues['DB_NAME']."\"\n"
233
		   ."charset = \"".$aSetupValues['DB_CHARSET']."\"\n"
234
		   ."table_prefix = \"".$aSetupValues['TABLE_PREFIX']."\"\n"
235
		   .";\n"
236
		   .";################################################\n";
237
		$sSetupFile = $sAppPath.'setup.ini.php';
238
		if (file_put_contents($sSetupFile, $sSetupContent)) {
239
			return true;
240
		}
241
		return false;
242
	}
243
/**
244
 * 
245
 * @param string $sAppPath the path where config.php is located
246
 * @return boolean
247
 */
248
	public static function writeConfig($sAppPath)
249
	{
250
		$sConfigContent = "<?php\n"
251
			."/* this file is for backward compatibility only */\n"
252
			."/* never put any code in this file! */\n"
253
			."include_once(dirname(__FILE__).'/framework/initialize.php');\n";
254
		$sConfigFile = $sAppPath.'config.php';
255
		if (file_put_contents($sConfigFile, $sConfigContent)) {
256
			return true;
257
		}
258
		return false;
259
	}
67 260

  
68

  
69 261
} // end of class UpgradeHelper
70 262

  

Also available in: Unified diff