@@ -68,6 +68,7 @@ function updateDbAndIni() {
6868 //* Update $conf array with values from the server.ini that shall be preserved
6969 $ tmp = $ inst ->db ->queryOneRecord ("SELECT * FROM " .$ conf ["mysql " ]["database " ].".server WHERE server_id = " .$ conf ['server_id ' ]);
7070 $ ini_array = ini_to_array (stripslashes ($ tmp ['config ' ]));
71+ $ current_db_version = (isset ($ tmp ['dbversion ' ]))?intval ($ tmp ['dbversion ' ]):0 ;
7172
7273 if (count ($ ini_array ) == 0 ) die ('Unable to read server configuration from database. ' );
7374
@@ -78,31 +79,61 @@ function updateDbAndIni() {
7879 $ conf ['services ' ]['db ' ] = ($ tmp ['db_server ' ] == 1 )?true :false ;
7980 $ conf ['services ' ]['vserver ' ] = ($ tmp ['vserver_server ' ] == 1 )?true :false ;
8081 $ conf ['postfix ' ]['vmail_mailbox_base ' ] = $ ini_array ['mail ' ]['homedir_path ' ];
81-
82- //** Delete the old database
83- if ( !$ inst ->db ->query ('DROP DATABASE IF EXISTS ' .$ conf ['mysql ' ]['database ' ]) ) {
84-
82+
83+ //* Do incremental DB updates only on installed ISPConfig versions > 3.0.3
84+ if (compare_ispconfig_version ('3.0.3 ' ,ISPC_APP_VERSION ) >= 0 ) {
85+
86+ swriteln ($ inst ->lng ('Starting incremental database update. ' ));
87+
88+ //* get the version of the db schema from the server table
89+ $ found = true ;
90+ while ($ found == true ) {
91+ $ next_db_version = intval ($ current_db_version + 1 );
92+ $ patch_filename = realpath (dirname (__FILE__ ).'/../ ' ).'/sql/incremental/upd_ ' .str_pad ($ next_db_version , 4 , '0 ' , STR_PAD_LEFT ).'.sql ' ;
93+ if (is_file ($ patch_filename )) {
94+ //* Load patch file into database
95+ if ( !empty ($ conf ["mysql " ]["admin_password " ]) ) {
96+ system ("mysql --default-character-set= " .$ conf ['mysql ' ]['charset ' ]." --force -h ' " .$ conf ['mysql ' ]['host ' ]."' -u ' " .$ conf ['mysql ' ]['admin_user ' ]."' -p' " .$ conf ['mysql ' ]['admin_password ' ]."' " .$ conf ['mysql ' ]['database ' ]." < " .$ patch_filename );
97+ } else {
98+ system ("mysql --default-character-set= " .$ conf ['mysql ' ]['charset ' ]." --force -h ' " .$ conf ['mysql ' ]['host ' ]."' -u ' " .$ conf ['mysql ' ]['admin_user ' ]."' " .$ conf ['mysql ' ]['database ' ]." < " .$ patch_filename );
99+ }
100+ swriteln ($ inst ->lng ('Loading SQL patch file ' ).': ' .$ patch_filename );
101+ $ current_db_version = $ next_db_version ;
102+ } else {
103+ $ found = false ;
104+ }
105+ }
106+
107+ //* update the database version in server table
108+ $ inst ->db ->query ("UPDATE " .$ conf ["mysql " ]["database " ].".server SET dbversion = ' " .$ current_db_version ."' WHERE server_id = " .$ conf ['server_id ' ]);
109+
110+
111+ //* If ISPConfig Version < 3.0.3, we will do a full db update
112+ } else {
113+
114+ swriteln ($ inst ->lng ('Starting full database update. ' ));
115+
116+ //** Delete the old database
117+ if ( !$ inst ->db ->query ('DROP DATABASE IF EXISTS ' .$ conf ['mysql ' ]['database ' ]) ) {
85118 $ inst ->error ('Unable to drop MySQL database: ' .$ conf ['mysql ' ]['database ' ].'. ' );
86- }
87-
88- //** Create the mysql database
89- $ inst ->configure_database ();
90-
91- //** empty all databases
92- $ db_tables = $ inst ->db ->getTables ();
93-
94- foreach ($ db_tables as $ table ) {
119+ }
95120
96- $ inst -> db -> query ( " TRUNCATE $ table " );
97- }
121+ //** Create the mysql database
122+ $ inst -> configure_database ();
98123
99- //** load old data back into database
100- if ( ! empty ( $ conf [ " mysql " ][ " admin_password " ]) ) {
124+ //** empty all databases
125+ $ db_tables = $ inst -> db -> getTables ();
101126
102- system ("mysql --default-character-set= " .$ conf ['mysql ' ]['charset ' ]." --force -h ' " .$ conf ['mysql ' ]['host ' ]."' -u ' " .$ conf ['mysql ' ]['admin_user ' ]."' -p' " .$ conf ['mysql ' ]['admin_password ' ]."' " .$ conf ['mysql ' ]['database ' ]." < existing_db.sql " );
103- } else {
127+ foreach ($ db_tables as $ table ) {
128+ $ inst ->db ->query ("TRUNCATE $ table " );
129+ }
104130
105- system ("mysql --default-character-set= " .$ conf ['mysql ' ]['charset ' ]." --force -h ' " .$ conf ['mysql ' ]['host ' ]."' -u ' " .$ conf ['mysql ' ]['admin_user ' ]."' " .$ conf ['mysql ' ]['database ' ]." < existing_db.sql " );
131+ //** load old data back into database
132+ if ( !empty ($ conf ["mysql " ]["admin_password " ]) ) {
133+ system ("mysql --default-character-set= " .$ conf ['mysql ' ]['charset ' ]." --force -h ' " .$ conf ['mysql ' ]['host ' ]."' -u ' " .$ conf ['mysql ' ]['admin_user ' ]."' -p' " .$ conf ['mysql ' ]['admin_password ' ]."' " .$ conf ['mysql ' ]['database ' ]." < existing_db.sql " );
134+ } else {
135+ system ("mysql --default-character-set= " .$ conf ['mysql ' ]['charset ' ]." --force -h ' " .$ conf ['mysql ' ]['host ' ]."' -u ' " .$ conf ['mysql ' ]['admin_user ' ]."' " .$ conf ['mysql ' ]['database ' ]." < existing_db.sql " );
136+ }
106137 }
107138
108139
@@ -111,6 +142,32 @@ function updateDbAndIni() {
111142 $ old_ini_array = ini_to_array (stripslashes ($ tmp_server_rec ['config ' ]));
112143 unset($ tmp_server_rec );
113144 $ tpl_ini_array = ini_to_array (rf ('tpl/server.ini.master ' ));
145+
146+ //* Update further distribution specific parameters for server config here
147+ //* HINT: Every line added here has to be added in installer_base.lib.php too!!
148+ $ tpl_ini_array ['web ' ]['vhost_conf_dir ' ] = $ conf ['apache ' ]['vhost_conf_dir ' ];
149+ $ tpl_ini_array ['web ' ]['vhost_conf_enabled_dir ' ] = $ conf ['apache ' ]['vhost_conf_enabled_dir ' ];
150+ $ tpl_ini_array ['jailkit ' ]['jailkit_chroot_app_programs ' ] = $ conf ['jailkit ' ]['jailkit_chroot_app_programs ' ];
151+ $ tpl_ini_array ['fastcgi ' ]['fastcgi_phpini_path ' ] = $ conf ['fastcgi ' ]['fastcgi_phpini_path ' ];
152+ $ tpl_ini_array ['fastcgi ' ]['fastcgi_starter_path ' ] = $ conf ['fastcgi ' ]['fastcgi_starter_path ' ];
153+ $ tpl_ini_array ['server ' ]['hostname ' ] = $ conf ['hostname ' ];
154+ $ tpl_ini_array ['server ' ]['ip_address ' ] = @gethostbyname ($ conf ['hostname ' ]);
155+ $ tpl_ini_array ['web ' ]['website_basedir ' ] = $ conf ['web ' ]['website_basedir ' ];
156+ $ tpl_ini_array ['web ' ]['website_path ' ] = $ conf ['web ' ]['website_path ' ];
157+ $ tpl_ini_array ['web ' ]['website_symlinks ' ] = $ conf ['web ' ]['website_symlinks ' ];
158+ $ tpl_ini_array ['cron ' ]['crontab_dir ' ] = $ conf ['cron ' ]['crontab_dir ' ];
159+ $ tpl_ini_array ['web ' ]['security_level ' ] = 20 ;
160+ $ tpl_ini_array ['web ' ]['user ' ] = $ conf ['apache ' ]['user ' ];
161+ $ tpl_ini_array ['web ' ]['group ' ] = $ conf ['apache ' ]['group ' ];
162+ $ tpl_ini_array ['web ' ]['php_ini_path_apache ' ] = $ conf ['apache ' ]['php_ini_path_apache ' ];
163+ $ tpl_ini_array ['web ' ]['php_ini_path_cgi ' ] = $ conf ['apache ' ]['php_ini_path_cgi ' ];
164+ $ tpl_ini_array ['mail ' ]['pop3_imap_daemon ' ] = ($ conf ['dovecot ' ]['installed ' ] == true )?'dovecot ' :'courier ' ;
165+ $ tpl_ini_array ['mail ' ]['mail_filter_syntax ' ] = ($ conf ['dovecot ' ]['installed ' ] == true )?'sieve ' :'maildrop ' ;
166+ $ tpl_ini_array ['dns ' ]['bind_user ' ] = $ conf ['bind ' ]['bind_user ' ];
167+ $ tpl_ini_array ['dns ' ]['bind_group ' ] = $ conf ['bind ' ]['bind_group ' ];
168+ $ tpl_ini_array ['dns ' ]['bind_zonefiles_dir ' ] = $ conf ['bind ' ]['bind_zonefiles_dir ' ];
169+ $ tpl_ini_array ['dns ' ]['named_conf_path ' ] = $ conf ['bind ' ]['named_conf_path ' ];
170+ $ tpl_ini_array ['dns ' ]['named_conf_local_path ' ] = $ conf ['bind ' ]['named_conf_local_path ' ];
114171
115172 // update the new template with the old values
116173 if (is_array ($ old_ini_array )) {
0 commit comments