@@ -250,43 +250,20 @@ public function createDatabaseForPackageInstance(&$settings, $websrv) {
250250 $ mysql_db_remote_access = 'n ' ;
251251 $ mysql_db_remote_ips = '' ;
252252 } else {
253- //* get the default database server of the client
254- $ client = $ app ->db ->queryOneRecord ("SELECT default_dbserver FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ? " , $ websrv ['sys_groupid ' ]);
255- if (is_array ($ client ) && $ client ['default_dbserver ' ] > 0 && $ client ['default_dbserver ' ] != $ websrv ['server_id ' ]) {
256- $ mysql_db_server_id = $ app ->functions ->intval ($ client ['default_dbserver ' ]);
257- $ dbserver_config = $ web_config = $ app ->getconf ->get_server_config ($ app ->functions ->intval ($ mysql_db_server_id ), 'server ' );
258- $ settings ['main_database_host ' ] = $ dbserver_config ['ip_address ' ];
259- $ mysql_db_remote_access = 'y ' ;
260- $ webserver_config = $ app ->getconf ->get_server_config ($ app ->functions ->intval ($ websrv ['server_id ' ]), 'server ' );
261- $ mysql_db_remote_ips = $ webserver_config ['ip_address ' ];
262- } else {
263- // Changing column lookup from default_dbserver to db_servers
264- $ client = $ app ->db ->queryOneRecord ("SELECT db_servers FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ? " , $ websrv ['sys_groupid ' ]);
265- if (is_array ($ client ) && $ client ['db_servers ' ] > 0 && $ client ['db_servers ' ] != $ websrv ['server_id ' ]) {
266- $ mysql_db_server_id = $ app ->functions ->intval ($ client ['db_servers ' ]);
253+ //* If db server is not a web server, get the primary ( first ) database server from the client db_servers
254+ $ client = $ app ->db ->queryOneRecord ("SELECT db_servers FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ? " , $ websrv ['sys_groupid ' ]);
255+ $ dbservers = explode (", " , $ client ['db_servers ' ]); // Explode all db servers to array
256+ $ primary_dbserver = $ dbservers [0 ]; // first db server from list of servers
257+ if (is_array ($ client ) && $ primary_dbserver > 0 && $ primary_dbserver != $ websrv ['server_id ' ]) {
258+ $ mysql_db_server_id = $ app ->functions ->intval ($ primary_dbserver );
267259 $ dbserver_config = $ web_config = $ app ->getconf ->get_server_config ($ app ->functions ->intval ($ mysql_db_server_id ), 'server ' );
268260 $ settings ['main_database_host ' ] = $ dbserver_config ['ip_address ' ];
269261 $ mysql_db_remote_access = 'y ' ;
270262 $ webserver_config = $ app ->getconf ->get_server_config ($ app ->functions ->intval ($ websrv ['server_id ' ]), 'server ' );
271263 $ mysql_db_remote_ips = $ webserver_config ['ip_address ' ];
272- } else { // Really nothing to do if reach this point :)
264+ } else { // Error choosing database server, nothing to do
273265 return false ;
274266 }
275-
276-
277- /* I left this in place for a fallback that should NEVER! happen.
278- * if we reach this point it means that there is NO default db server for the client
279- * AND the webserver has NO db service enabled.
280- * We have to abort the aps installation here... so I added a return false
281- * although this does not present any error message to the user.
282- */
283- //return false;
284-
285- /*$mysql_db_server_id = $websrv['server_id'];
286- $settings['main_database_host'] = 'localhost';
287- $mysql_db_remote_access = 'n';
288- $mysql_db_remote_ips = '';*/
289- }
290267 }
291268
292269 if (empty ($ settings ['main_database_name ' ])) {
0 commit comments