From d4df3b195958b9716ac2810ff5fdbd457e3a2ed0 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Tue, 16 Aug 2022 15:36:16 +1000 Subject: [PATCH] Add in some support for custom database port --- hosting_wpplatform/drush/provision_wordpress.inc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/hosting_wpplatform/drush/provision_wordpress.inc b/hosting_wpplatform/drush/provision_wordpress.inc index 0aa1044..7d327f3 100644 --- a/hosting_wpplatform/drush/provision_wordpress.inc +++ b/hosting_wpplatform/drush/provision_wordpress.inc @@ -184,6 +184,15 @@ function provision_wordpress_regenerate_civicrm_settings() { return; } + $dbHost = drush_get_option('db_host', NULL, 'site'); + $dbPort = drush_get_option('db_port', NULL, 'site') ?? '3306'; + $dbHostParts = explode(':', $dbHost); + // If there is no port specified in the host or the port in $dbHost != the db_port specified used the $dbPort as the db host port. + if ($dbPort !== '3306' && (count($dbHostParts) == 1 || count($dbHostParts) == 2 && $dbHostParts[1] !== $dbPort)) { + $dbHostParts[1] = $dbPort; + } + $dbHost = implode(':', $dbHostParts); + $params = []; $params['crmRoot'] = d()->root . '/wp-content/plugins/civicrm/civicrm/'; $params['templateCompileDir'] = d()->root . '/sites/' . d()->uri . '/wp-content/uploads/civicrm/templates_c'; @@ -192,7 +201,7 @@ function provision_wordpress_regenerate_civicrm_settings() { $params['baseURL'] = "https://" . d()->uri; $params['dbUser'] = addslashes(urlencode(drush_get_option('db_user', NULL, 'site'))); $params['dbPass'] = addslashes(urlencode(drush_get_option('db_passwd', NULL, 'site'))); - $params['dbHost'] = addslashes(implode(':', array_map('urlencode', explode(':', drush_get_option('db_host', NULL, 'site'))))); + $params['dbHost'] = addslashes(implode(':', array_map('urlencode', explode(':', $dbHost)))); $params['dbName'] = addslashes(urlencode(drush_get_option('db_name', NULL, 'site'))); // The '&' prefix is awkward, but we don't know what's already in the file. // At the time of writing, it has ?new_link=true. If that is removed,