@@ -250,29 +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- /* I left this in place for a fallback that should NEVER! happen.
264- * if we reach this point it means that there is NO default db server for the client
265- * AND the webserver has NO db service enabled.
266- * We have to abort the aps installation here... so I added a return false
267- * although this does not present any error message to the user.
268- */
269- return false ;
270-
271- /*$mysql_db_server_id = $websrv['server_id'];
272- $settings['main_database_host'] = 'localhost';
273- $mysql_db_remote_access = 'n';
274- $mysql_db_remote_ips = '';*/
275- }
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 );
259+ $ dbserver_config = $ web_config = $ app ->getconf ->get_server_config ($ app ->functions ->intval ($ mysql_db_server_id ), 'server ' );
260+ $ settings ['main_database_host ' ] = $ dbserver_config ['ip_address ' ];
261+ $ mysql_db_remote_access = 'y ' ;
262+ $ webserver_config = $ app ->getconf ->get_server_config ($ app ->functions ->intval ($ websrv ['server_id ' ]), 'server ' );
263+ $ mysql_db_remote_ips = $ webserver_config ['ip_address ' ];
264+ } else { // Error choosing database server, nothing to do
265+ return false ;
266+ }
276267 }
277268
278269 if (empty ($ settings ['main_database_name ' ])) {
0 commit comments