Skip to content

Commit

Permalink
Allow ports in host name field - addresses #293
Browse files Browse the repository at this point in the history
  • Loading branch information
CatoTH committed Sep 14, 2018
1 parent 94f16ce commit 32b6ccc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Bugfix: Underlined text was not rendered as such in the PHP-based PDF renderer.
- The WYSIWYG-editor CKEDITOR was updated, including some bug fixes.
- Temporary files for PDF and ODS generation are not stored in /tmp/ anymore, as there are hosters that block access to this directory. Instead, runtime/tmp is used.
- In the installation, host names including ports (like localhost:3306) are now supported for the database connection.

### Version 4.0.1 (2018-09-02)

Expand Down
20 changes: 18 additions & 2 deletions models/forms/AntragsgruenInitDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class AntragsgruenInitDb extends Model
public $sqlHost;
public $sqlUsername;
public $sqlPassword;
public $sqlPort = 3306;
public $sqlDB;
public $sqlTablePrefix = '';

Expand Down Expand Up @@ -84,6 +85,11 @@ public function setAttributes($values, $safeOnly = true)
} else {
$this->prettyUrls = true;
}
if (strpos($this->sqlHost, ':') !== false) {
list($host, $port) = explode(':', $this->sqlHost);
$this->sqlHost = $host;
$this->sqlPort = IntVal($port);
}
}

/**
Expand All @@ -104,6 +110,9 @@ private function setMysqlFromEnv()
$this->sqlDB = $_ENV['ANTRAGSGRUEN_MYSQL_DB'];
$this->sqlHost = $_ENV['ANTRAGSGRUEN_MYSQL_HOST'];
$this->sqlType = 'mysql';
if (isset($_ENV['ANTRAGSGRUEN_MYSQL_PORT'])) {
$this->sqlPort = IntVal($_ENV['ANTRAGSGRUEN_MYSQL_PORT']);
}
}

/**
Expand Down Expand Up @@ -136,6 +145,9 @@ private function setDatabaseFromParams($params)
if ($parts[0] === 'host') {
$this->sqlHost = $parts[1];
}
if ($parts[0] === 'port') {
$this->sqlPort = $parts[1];
}
}
}
}
Expand All @@ -148,8 +160,12 @@ private function setDatabaseFromParams($params)
protected function getDBConfig()
{
if ($this->sqlType == 'mysql') {
$dsn = 'mysql:host=' . $this->sqlHost . ';dbname=' . $this->sqlDB;
if ($this->sqlPort !== 3306) {
$dsn .= ';port=' . $this->sqlPort;
}
return [
'dsn' => 'mysql:host=' . $this->sqlHost . ';dbname=' . $this->sqlDB,
'dsn' => $dsn,
'emulatePrepare' => true,
'username' => $this->sqlUsername,
'password' => $this->sqlPassword,
Expand All @@ -164,7 +180,7 @@ protected function getDBConfig()
public function overwriteYiiConnection()
{
$connConfig = $this->getDBConfig();
$connConfig['class'] = \yii\db\Connection::class;
$connConfig['class'] = Connection::class;
\yii::$app->set('db', $connConfig);
}

Expand Down

0 comments on commit 32b6ccc

Please sign in to comment.