Project

General

Profile

« Previous | Next » 

Revision 1889

Added by Dietmar over 11 years ago

  1. bugfix solved sections block update
    ! update sections table change some varchar to int(11)
    + upgradeHelper class for better module upgrade

View differences:

upgrade-script.php
74 74
// database tables including in WB package
75 75
$aPackage = array (
76 76
    'settings','groups','addons','pages','sections','search','users',
77
    'mod_captcha_control','mod_jsadmin','mod_menu_link','mod_output_filter','mod_wrapper','mod_wysiwyg',
78
//    'mod_code','mod_droplets',
79
//    'mod_form_fields','mod_form_settings','mod_form_submissions',
80
//    'mod_news_comments','mod_news_groups','mod_news_posts','mod_news_settings',
77
    'mod_captcha_control','mod_jsadmin','mod_menu_link','mod_output_filter','mod_wrapper','mod_wysiwyg'
81 78
);
82 79

  
83 80
$OK            = ' <span class="ok">OK</span> ';
......
207 204
 * @return
208 205
 */
209 206
function add_modify_field_in_database($sTable,$sField,$sDescription){
210
	global $database,$OK,$FAIL,$bDebugModus;
207
	global $OK,$FAIL,$bDebugModus;
208
	$database=WbDatabase::getInstance();
211 209
	$aDebugMessage = array();
212 210
	if(!$database->field_exists($sTable,$sField)) {
213 211
		$aDebugMessage[] = "<span>Adding field $sField to $sTable table</span>";
......
222 220
return;
223 221
}
224 222

  
225
/**
226
 * check existings tables for upgrade or install
227
 *
228
 * check_wb_tables()
229
 *
230
 * @return
231
 */
232
function check_wb_tables()
233
{
234
	global $database,$aPackage;
235

  
236
// if prefix inludes '_' or '%'
237
	$search_for = addcslashes ( TABLE_PREFIX, '%_' );
238
	$get_result = $database->query( 'SHOW TABLES LIKE "'.$search_for.'%"');
239

  
240
	// $get_result = $database->query( "SHOW TABLES FROM ".DB_NAME);
241
	$all_tables = array();
242
	$aTable = array();
243
	if($get_result->numRows() > 0)
244
	{
245
		while ($data = $get_result->fetchRow()) {
246
		    $tmp = preg_replace('/^'.preg_quote(TABLE_PREFIX, '/').'/s', '', $data[0]);
247
		    if(in_array($tmp,$aPackage)) {
248
		        $all_tables[] = $tmp;
249
		    } else {
250
		        $aTable[] = $tmp;
251
		    }
252
		}
253
	}
254

  
255
	return array_merge ( $all_tables, $aTable );
256
}
257

  
258
// check existing tables
259
$all_tables = check_wb_tables();
260

  
261 223
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
262 224
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
263 225
<head>
......
402 364
	exit();
403 365
}
404 366

  
405
// check again all tables, to get a new array
406
// if(sizeof($all_tables) < sizeof($aTable)) { $all_tables = check_wb_tables(); }
407 367
/**********************************************************
408 368
 *  - check tables coming with WebsiteBaker
409 369
 */
410
    $check_text = 'total ';
411
    // $check_tables = mysqlCheckTables( DB_NAME ) ;
412
    $aTable = array();
413
    foreach ($all_tables as $data) {
414
        $tmp = str_replace(TABLE_PREFIX, '', $data);
415
        if(in_array($tmp,$aPackage)) {
416
            $aTable[] = $tmp;
417
        }
418
    }
419

  
420
    if( (sizeof($all_tables) >= sizeof($aPackage)) && (sizeof($aTable) == sizeof($aPackage)) )
421
    {
422
        echo '<h4 style="margin-left:0;">NOTICE: Your database '.$database->DbName.' has '.sizeof($all_tables).' '.$check_text.' tables from '.sizeof($aPackage).' included in package '.$OK.'</h4>';
423
    }
424
    else
425
    {
370
	$aMissingTables = UpgradeHelper::existsAllTables($aPackage);
371
	if( sizeof($aMissingTables) == 0){
372
        echo '<h4 style="margin-left:0;">NOTICE: '.sizeof($aPackage).' total tables included in package are successful installed your database `'.$database->DbName.'` '.$OK.'</h4>';
373
    } else {
426 374
        status_msg('<strong>:</strong><br />can\'t run Upgrade, missing tables', 'warning', 'div');
427 375
        echo '<h4>Missing required tables. You can install them in backend->addons->modules.<br />';
428 376
        echo 'Or if you uploaded per FTP install possible by backend->addons->modules->advanced.<br />';
429 377
        echo 'First rename or delete the upgrade-script.php, so the script can\'t start automatically by backend<br />';
430
        echo 'After installing missing tables upload and run again upgrade-script.php</h4>';
431
        $result = array_diff ( $aPackage, $aTable );
432

  
433
        echo '<h4 class="warning"><br />';
434
        while ( list ( $key, $val ) = each ( $result ) )
435
        {
436
            echo 'TABLE ´'.TABLE_PREFIX.$val.'´ '.$FAIL.'<br>';
437
        }
438

  
439
        echo '<br /></h4>';
378
        echo 'After installing missing tables upload and run again upgrade-script.php<br /><br /></h4>';
379
        echo '<h4 class="warning">';
380
        echo 'Missing required tables.<br /><br />';
381
        echo 'TABLE `'.implode('` missing! '.$FAIL.'<br />TABLE `',$aMissingTables).'` missing! '.$FAIL;
382
        echo '<br /><br /></h4>';
440 383
        echo '<br /><br />';
441 384
        if(isset($_SERVER['SCRIPT_NAME'])) {
442 385
        	echo '<form action="'.$_SERVER['SCRIPT_NAME'].'/">';
......
465 408
    $aDebugMessage[] = '<div style="margin-left:2em;">';
466 409
    $aDebugMessage[] = "<br /><span><strong>Adding default_theme to settings table</strong></span>";
467 410
    // db_update_key_value('settings', 'default_theme', $DEFAULT_THEME);
468
    $aDebugMessage[] = (db_update_key_value( 'settings', 'default_theme', $DEFAULT_THEME ) ? " $OK<br />" : " $FAIL!<br />");
411
    $cfg = array(
412
    	'default_theme' => defined('DEFAULT_THEME')&& (DEFAULT_THEME!='') ? DEFAULT_THEME : $DEFAULT_THEME
413
    );
414
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
469 415
    $aDebugMessage[] = '</div>';
470 416

  
471 417
if($bDebugModus) {
472 418
    echo implode(PHP_EOL,$aDebugMessage);
473 419
}
474 420
$aDebugMessage = array();
475
echo'<h3>Step '.(++$stepID).': Updating tables included in package</h3>';
421
echo'<h3>Step '.(++$stepID).': Updating core table included in package</h3>';
476 422
    /**********************************************************
477 423
     *  - Adding field sec_anchor to settings table
478 424
     */
......
480 426
    echo "<h4>Adding/updating entries on table settings</h4>";
481 427
    $aDebugMessage[] = "<span>Adding/updating sec_anchor to settings table</span>";
482 428
    $cfg = array(
483
    	'sec_anchor' => defined('SEC_ANCHOR') ? SEC_ANCHOR : 'section_'
429
    	'sec_anchor' => defined('SEC_ANCHOR')&& (SEC_ANCHOR!='') ? SEC_ANCHOR : 'section_'
484 430
    );
485 431
   $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
486 432

  
......
489 435
     */
490 436
    $aDebugMessage[] = "<span>Adding/updating redirect timer to settings table</span>";
491 437
    $cfg = array(
492
    	'redirect_timer' => defined('REDIRECT_TIMER') ? REDIRECT_TIMER : '1500'
438
    	'redirect_timer' => defined('REDIRECT_TIMER')&& (REDIRECT_TIMER!='') ? REDIRECT_TIMER : '1500'
493 439
    );
494 440
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
495 441

  
496 442
    /**********************************************************
443
     *  - Adding default_time_formatr to settings table
444
     */
445
    $aDebugMessage[] = "<span>Adding/updating default_time_format to settings table</span>";
446
    $cfg = array(
447
    	'default_time_format' => defined('DEFAULT_TIME_FORMAT')&& (DEFAULT_TIME_FORMAT!='') ? DEFAULT_TIME_FORMAT : 'h:i A'
448
    );
449
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
450

  
451
    /**********************************************************
497 452
     *  - Adding rename_files_on_upload to settings table
498 453
     */
499 454
    $aDebugMessage[] = "<span>Adding/Updating rename_files_on_upload to settings table</span>";
500 455
    $cfg = array(
501
    	'rename_files_on_upload' => (defined('RENAME_FILES_ON_UPLOAD') ? RENAME_FILES_ON_UPLOAD : 'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx,js')
456
        'rename_files_on_upload' => (defined('RENAME_FILES_ON_UPLOAD')&& (RENAME_FILES_ON_UPLOAD!='') ? RENAME_FILES_ON_UPLOAD : 'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx,js')
502 457
    );
503 458
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
504 459

  
......
507 462
     */
508 463
    $aDebugMessage[] = "<span>Adding/updating mediasettings to settings table</span>";
509 464
    $cfg = array(
510
    	'mediasettings' => (defined('MEDIASETTINGS') ? MEDIASETTINGS : ''),
465
    	'mediasettings' => (defined('MEDIASETTINGS')&& (MEDIASETTINGS!='') ? MEDIASETTINGS : ''),
511 466
    );
512 467

  
513 468
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
......
528 483
     */
529 484
    $aDebugMessage[] = "<span>Adding/updating page_icon_dir to settings table</span>";
530 485
    $cfg = array(
531
    	'page_icon_dir' => (defined('PAGE_ICON_DIR') ? PAGE_ICON_DIR : '/templates/*/title_images'),
486
    	'page_icon_dir' => (defined('PAGE_ICON_DIR')&& (PAGE_ICON_DIR!='') ? PAGE_ICON_DIR : '/templates/*/title_images'),
532 487
    );
533 488

  
534 489
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
......
547 502
     */
548 503
    $aDebugMessage[] = "<span>Adding/updating wbmail_signature to settings table</span>";
549 504
    $cfg = array(
550
    	'wbmail_signature' => (defined('WBMAIL_SIGNATURE') ? WBMAIL_SIGNATURE : '')
505
    	'wbmail_signature' => (defined('WBMAIL_SIGNATURE')&& (WBMAIL_SIGNATURE!='') ? WBMAIL_SIGNATURE : '')
551 506
    );
552 507

  
553 508
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
......
596 551
	    echo ($database->query($sql)) ? " $OK<br />" : " $FAIL!<br />";
597 552
	}
598 553

  
599
    echo "<h4>Adding/updating field on table mod_menu_link</h4>";
554
	echo "<h4>Adding/updating field on table mod_menu_link</h4>";
600 555
	/**********************************************************
601 556
     *  - Add field "redirect_type" to table "mod_menu_link"
602 557
     *  has to be moved later to upgrade.php in modul menu_link, because modul can be removed
......
604 559
	$table_name = TABLE_PREFIX.'mod_menu_link';
605 560
	$field_name = 'redirect_type';
606 561
	$description = "INT NOT NULL DEFAULT '301' AFTER `target_page_id`";
607
    add_modify_field_in_database($table_name,$field_name,$description);
562
	add_modify_field_in_database($table_name,$field_name,$description);
608 563

  
609 564
    if($bDebugModus) {
610 565
        echo implode(PHP_EOL,$aDebugMessage);
......
618 573
	$table_name = TABLE_PREFIX.'pages';
619 574
	$field_name = 'page_trail';
620 575
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT ''";
621
    add_modify_field_in_database($table_name,$field_name,$description);
576
	add_modify_field_in_database($table_name,$field_name,$description);
622 577

  
623 578
	/**********************************************************
624 579
     *  - Add field "page_icon" to table "pages"
......
725 680
	$aDebugMessage[] = "<span>Modify field module on sections table</span>";
726 681
	$aDebugMessage[] = ($database->field_modify($table_name, 'module', $description) ? " $OK<br />" : " $FAIL!<br />");
727 682
	$aDebugMessage[] = "<span>Modify field block on sections table</span>";
683
	$description = "int(11) NOT NULL DEFAULT '1'";
728 684
	$aDebugMessage[] = ($database->field_modify($table_name, 'block', $description) ? " $OK<br />" : " $FAIL!<br />");
685
	$description = "int(11) NOT NULL DEFAULT '0'";
729 686
	$aDebugMessage[] = "<span>Modify field publ_start on sections table</span>";
730 687
	$aDebugMessage[] = ($database->field_modify($table_name, 'publ_start', $description) ? " $OK<br />" : " $FAIL!<br />");
731 688
	$aDebugMessage[] = "<span>Modify field publ_end on sections table</span>";
......
786 743

  
787 744
}
788 745

  
789
if(version_compare(WB_REVISION, '1800', '<'))
746
if(version_compare(WB_REVISION, REVISION, '<'))
790 747
{
791 748
    $aDebugMessage = array();
792
    /**********************************************************
793
     * This part with changing in mod_wysiwyg will be removed in the final version
794
     * special workout for the tester
795
     *  - Remove/add PRIMARY KEY from/to "section_id" from table "mod_wysiwygs"
796
     */
797
    $aDebugMessage[] = '<div style="margin-left:2em;">';
798

  
799
    $sTable = TABLE_PREFIX.'mod_wysiwyg';
800
    $field_name = 'wysiwyg_id';
801
    if($database->field_exists($sTable, 'wysiwyg_id')) {
802
        if($database->index_exists($sTable, 'PRIMARY')) {
803
            $aDebugMessage[] = "<span>Remove PRIMARY KEY from table mod_wysiwyg.wysiwyg_id</span>";
804
            $aDebugMessage[] = $database->index_remove($sTable, 'PRIMARY') ? " $OK<br />" : " $FAIL!<br />";
805
        }
806
        $aDebugMessage[] = "<span>Remove field 'wysiwyg_id' from table mod_wysiwyg</span>";
807
        $aDebugMessage[] = $database->field_remove($sTable, 'wysiwyg_id') ? " $OK<br />" : " $FAIL!<br />";
808
    }
809

  
810
    $aDebugMessage[] = "<br /><span>Create PRIMARY KEY ( `section_id` ) on table mod_wysiwygs.</span>";
811
    $aDebugMessage[] = $database->index_add($sTable, '', 'section_id', 'PRIMARY') ? " $OK<br />" : " $FAIL!<br />";
812
    $aDebugMessage[] = '</div>';
813

  
814
    if($bDebugModus) {
815
    // $aDebugMessage[] =
816
        echo implode(PHP_EOL,$aDebugMessage);
817
    }
818
}
819

  
820
if(version_compare(WB_REVISION, REVISION, '<='))
821
{
822
    $aDebugMessage = array();
823 749
    echo '<h3>Step '.(++$stepID).': Updating group_id in table users</h3>';
824 750
    /**********************************************************
825 751
    * Updating group_id in table users
......
955 881
			$msg = '<br /><br />Following files are deprecated, outdated or a security risk and
956 882
				    can not be removed automatically.<br /><br />Please delete them
957 883
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
958
	        status_msg($msg, 'error warning', 'div');
884
			status_msg($msg, 'error warning', 'div');
959 885
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
960 886

  
961 887
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
......
968 894
			</html>";
969 895
			exit;
970 896
		}
971
    }
897
	}
972 898

  
973 899

  
974 900
	/**********************************************************
......
1039 965
	 * upgrade modules if newer version is available
1040 966
	 * $aModuleList list of proofed modules
1041 967
	 */
1042
	$aModuleList = array('news','wysiwyg','form');
968
//	$aModuleList = array('wysiwyg','news','form','captcha_control','output_filter');
969
	$aModuleList = array('wysiwyg','form');
1043 970
	if(sizeof($aModuleList)) 
1044 971
	{
1045 972
	    echo '<h3>Step '.(++$stepID).': Upgrade proofed modules</h3>';
......
1097 1024
	if( ($handle = opendir(WB_PATH.'/modules/')) ) {
1098 1025
		while(false !== ($file = readdir($handle))) {
1099 1026
			if($file != '' && substr($file, 0, 1) != '.' && is_dir(WB_PATH.'/modules/'.$file) ) {
1100
                $iFound++;
1027
				$iFound++;
1101 1028
				$iLoaded = load_module(WB_PATH.'/modules/'.$file ) ? $iLoaded+1 : $iLoaded;
1102
			   // 	upgrade_module($file, true);
1029
// 	upgrade_module($file, true);
1103 1030
			}
1104 1031
		}
1105 1032
		closedir($handle);
1106 1033
	}
1107 1034
	echo '<strong><span>'.$iLoaded.' Modules reloaded,</span> found '.$iFound.' directories in folder /modules/</strong><br />';
1108 1035

  
1109
    $iFound = 0;
1110
    $iLoaded = 0;
1036
	$iFound = 0;
1037
	$iLoaded = 0;
1111 1038
	////delete templates
1112 1039
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
1113 1040
	// Load all templates
......
1115 1042
		while(false !== ($file = readdir($handle))) {
1116 1043
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
1117 1044

  
1118
                $iFound++;
1045
				$iFound++;
1119 1046
				$iLoaded = (load_template(WB_PATH.'/templates/'.$file)==true) ? $iLoaded+1 : $iLoaded;
1120 1047

  
1121 1048
			}
......
1124 1051
	}
1125 1052
	echo '<strong><span>'.$iLoaded.' Templates reloaded,</span> found '.$iFound.' directories in folder /templates/</strong><br />';
1126 1053

  
1127
    $iFound = 0;
1128
    $iLoaded = 0;
1054
	$iFound = 0;
1055
	$iLoaded = 0;
1129 1056
	////delete languages
1130 1057
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
1131 1058
	// Load all languages
1132 1059
	if( ($handle = opendir(WB_PATH.'/languages/')) ) {
1133 1060
		while(false !== ($file = readdir($handle))) {
1134 1061
			if($file != '' AND (preg_match('#^([A-Z]{2}.php)#', basename($file)))) {
1135
                $iFound++;
1062
				$iFound++;
1136 1063
				$iLoaded = load_language(WB_PATH.'/languages/'.$file) ? $iLoaded+1 : $iLoaded;
1137 1064
			}
1138 1065
		}
1139 1066
		closedir($handle);
1140 1067
	}
1141 1068
	echo '<strong><span>'.$iLoaded.' Languages reloaded,</span> found '.$iFound.' files in folder /languages/</strong><br />';
1142
    echo '</div>';
1069
	echo '</div>';
1143 1070

  
1144 1071
/**********************************************************
1145 1072
 *  - install new droplets
1146 1073

  

Also available in: Unified diff