Added support for interpolation in MySQL host, user, database, queries and file imports
This commit is contained in:
parent
40afb58ff7
commit
095b7d7f14
|
@ -51,8 +51,8 @@ class Mysql implements \PHPCI\Plugin
|
||||||
if (isset($buildSettings['mysql'])) {
|
if (isset($buildSettings['mysql'])) {
|
||||||
$sql = $buildSettings['mysql'];
|
$sql = $buildSettings['mysql'];
|
||||||
|
|
||||||
$this->host = !empty($sql['host']) ? $sql['host'] : $this->host;
|
$this->host = !empty($sql['host']) ? $sql['host'] : $this->phpci->interpolate($this->host);
|
||||||
$this->user = !empty($sql['user']) ? $sql['user'] : $this->user;
|
$this->user = !empty($sql['user']) ? $sql['user'] : $this->phpci->interpolate($this->user);
|
||||||
$this->pass = array_key_exists('pass', $sql) ? $sql['pass'] : $this->pass;
|
$this->pass = array_key_exists('pass', $sql) ? $sql['pass'] : $this->pass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,10 +71,12 @@ class Mysql implements \PHPCI\Plugin
|
||||||
foreach ($this->queries as $query) {
|
foreach ($this->queries as $query) {
|
||||||
if (!is_array($query)) {
|
if (!is_array($query)) {
|
||||||
// Simple query
|
// Simple query
|
||||||
$this->pdo->query($query);
|
$this->pdo->query($this->phpci->interpolate($query));
|
||||||
} else if (isset($query['import'])) {
|
} else if (isset($query['import'])) {
|
||||||
// SQL file execution
|
// SQL file execution
|
||||||
$this->executeFile($query['import']);
|
$this->executeFile($query['import']);
|
||||||
|
} else {
|
||||||
|
throw new \Exception("Invalid command");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (\Exception $ex) {
|
} catch (\Exception $ex) {
|
||||||
|
@ -88,15 +90,15 @@ class Mysql implements \PHPCI\Plugin
|
||||||
protected function executeFile($query)
|
protected function executeFile($query)
|
||||||
{
|
{
|
||||||
if (!isset($query['file'])) {
|
if (!isset($query['file'])) {
|
||||||
throw new \Exception("Import statement must contiain an 'file' key");
|
throw new \Exception("Import statement must contain a 'file' key");
|
||||||
}
|
}
|
||||||
|
|
||||||
$import_file = $this->phpci->buildPath . $query['file'];
|
$import_file = $this->phpci->buildPath . $this->phpci->interpolate($query['file']);
|
||||||
if (!is_readable($import_file)) {
|
if (!is_readable($import_file)) {
|
||||||
throw new \Exception("Cannot open SQL import file: $import_file");
|
throw new \Exception("Cannot open SQL import file: $import_file");
|
||||||
}
|
}
|
||||||
|
|
||||||
$database = isset($query['database'])? $query['database']: null;
|
$database = isset($query['database'])? $this->phpci->interpolate($query['database']): null;
|
||||||
|
|
||||||
$import_command = $this->getImportCommand($import_file, $database);
|
$import_command = $this->getImportCommand($import_file, $database);
|
||||||
if (!$this->phpci->executeCommand($import_command)) {
|
if (!$this->phpci->executeCommand($import_command)) {
|
||||||
|
|
Loading…
Reference in a new issue