Skip to content

Commit

Permalink
Feature: MySQL port option (Open-Web-Analytics#500)
Browse files Browse the repository at this point in the history
* Feature: MySQL port option

* Revert "Feature: MySQL port option"

* Feature: MySQL port option

* Removed required validation

* Removed redundant semicolon

* Changed port help text and default value
  • Loading branch information
Maaiins authored Mar 30, 2020
1 parent c4bd6d6 commit 44531db
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 4 deletions.
8 changes: 8 additions & 0 deletions modules/base/classes/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ function applyConfigConstants() {
if (defined('OWA_DB_HOST')) {
$this->set('base', 'db_host', OWA_DB_HOST);
}

if (defined('OWA_DB_PORT')) {
$this->set('base', 'db_port', OWA_DB_PORT);
}

if (defined('OWA_DB_USER')) {
$this->set('base', 'db_user', OWA_DB_USER);
Expand Down Expand Up @@ -570,6 +574,7 @@ private function getDefaultSettingsArray() {
'db_type' => '',
'db_name' => '',
'db_host' => '',
'db_port' => 3306,
'db_user' => '',
'db_password' => '',
'db_force_new_connections' => true,
Expand Down Expand Up @@ -818,6 +823,9 @@ public function createConfigFile($config_values) {
case "define('OWA_DB_HOST'":
fwrite($handle, str_replace("yourdbhostgoeshere", $config_values['db_host'], $line));
break;
case "define('OWA_DB_PORT'":
fwrite($handle, str_replace("3306", $config_values['db_port'], $line));
break;
case "define('OWA_PUBLIC_U":
fwrite($handle, str_replace("http://domain/path/to/owa/", $config_values['public_url'], $line));
break;
Expand Down
7 changes: 6 additions & 1 deletion modules/base/installConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function __construct($params) {
$v1->setValues($this->getParam('db_host'));
$v1->setErrorMessage("Database host is required.");
$this->setValidation('db_host', $v1);

$v2 = owa_coreAPI::validationFactory('required');
$v2->setValues($this->getParam('db_name'));
$v2->setErrorMessage("Database name is required.");
Expand Down Expand Up @@ -95,6 +95,10 @@ function action() {
if ( ! defined( 'OWA_DB_HOST' ) ) {
define('OWA_DB_HOST', $this->getParam( 'db_host' ) );
}

if ( ! defined( 'OWA_DB_PORT' ) ) {
define('OWA_DB_PORT', $this->getParam( 'db_port' ) );
}

if ( ! defined( 'OWA_DB_NAME' ) ) {
define('OWA_DB_NAME', $this->getParam( 'db_name' ) );
Expand All @@ -110,6 +114,7 @@ function action() {

owa_coreAPI::setSetting('base', 'db_type', OWA_DB_TYPE);
owa_coreAPI::setSetting('base', 'db_host', OWA_DB_HOST);
owa_coreAPI::setSetting('base', 'db_port', OWA_DB_PORT);
owa_coreAPI::setSetting('base', 'db_name', OWA_DB_NAME);
owa_coreAPI::setSetting('base', 'db_user', OWA_DB_USER);
owa_coreAPI::setSetting('base', 'db_password', OWA_DB_PASSWORD);
Expand Down
8 changes: 8 additions & 0 deletions modules/base/templates/install_config_entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
</span>
<span class="form-instructions">This is the host that your database resides on. Localhost is ok.</span>
</p>

<p class="form-row">
<span class="form-label">Database Port:</span>
<span class="form-field">
<input type="text"size="30" name="<?php echo $this->getNs();?>db_port" value="<?php echo ($config['db_port'] ? $config['db_port'] : 3306);?>">
</span>
<span class="form-instructions">This optional setting is used to change the port for your database. OWA will use the default port 3306 if you leave this empty.</span>
</p>

<p class="form-row">
<span class="form-label">Database Name:</span>
Expand Down
1 change: 1 addition & 0 deletions modules/base/templates/install_start_embedded.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<input type="hidden" name="<?php echo $this->getNs();?>db_type" value="<?php echo $db_type;?>">
<input type="hidden" name="<?php echo $this->getNs();?>db_name" value="<?php echo $db_name;?>">
<input type="hidden" name="<?php echo $this->getNs();?>db_host" value="<?php echo $db_host;?>">
<input type="hidden" name="<?php echo $this->getNs();?>db_port" value="<?php echo $db_port;?>">
<input type="hidden" name="<?php echo $this->getNs();?>db_user" value="<?php echo $db_user;?>">
<input type="hidden" name="<?php echo $this->getNs();?>db_password" value="<?php echo $db_password;?>">
<input type="hidden" name="<?php echo $this->getNs();?>public_url" value="<?php echo $public_url;?>">
Expand Down
1 change: 1 addition & 0 deletions owa-config-dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
define('OWA_DB_NAME', 'yourdbnamegoeshere'); // name of the database
define('OWA_DB_HOST', 'yourdbhostgoeshere'); // host name of the server housing the database
define('OWA_DB_USER', 'yourdbusergoeshere'); // database user
define('OWA_DB_PORT', '3306'); // port of database
define('OWA_DB_PASSWORD', 'yourdbpasswordgoeshere'); // database user's password

/**
Expand Down
3 changes: 2 additions & 1 deletion owa_coreAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ public static function dbFactory() {
} else {
$connection_class = 'owa_db_'.$db_type;
$db = new $connection_class(
owa_coreAPI::getSetting('base','db_host'),
owa_coreAPI::getSetting('base','db_host'),
owa_coreAPI::getSetting('base','db_port'),
owa_coreAPI::getSetting('base','db_name'),
owa_coreAPI::getSetting('base','db_user'),
owa_coreAPI::getSetting('base','db_password'),
Expand Down
3 changes: 2 additions & 1 deletion owa_db.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ class owa_db extends owa_base {
*/
var $_last_sql_statement;

function __construct($db_host, $db_name, $db_user, $db_password, $open_new_connection = true, $persistant = false) {
function __construct($db_host, $db_port, $db_name, $db_user, $db_password, $open_new_connection = true, $persistant = false) {

$this->connectionParams = array('host' => $db_host,
'port' => $db_port,
'user' => $db_user,
'password' => $db_password,
'name' => $db_name,
Expand Down
9 changes: 8 additions & 1 deletion plugins/db/owa_db_mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,20 @@ function connect() {

$host = $this->getConnectionParam('host');
}

if ($this->getConnectionParam('port')) {
$port = $this->getConnectionParam('port');
} else {
$port = 3306;
}

// get a connection
$this->connection = mysqli_connect(
$host,
$this->getConnectionParam('user'),
$this->getConnectionParam('password'),
$this->getConnectionParam('name')
$this->getConnectionParam('name'),
$port
);

// explicitng set the character set as UTF-8
Expand Down

0 comments on commit 44531db

Please sign in to comment.