Commit b609f931 authored by Sebastian Kummer's avatar Sebastian Kummer

Merge pull request #330 in ZP/z-push from...

Merge pull request #330 in ZP/z-push from bugfix/ZP-1005-sqlstatemachine.php-runs-in-a-constant to develop

* commit 'ca77ba8b':
  ZP-1005 Check if database name is confirm the SQL naming standards.
parents 2d05c5ff ca77ba8b
...@@ -84,6 +84,10 @@ class SqlStateMachine implements IStateMachine { ...@@ -84,6 +84,10 @@ class SqlStateMachine implements IStateMachine {
throw new FatalMisconfigurationException("SqlStateMachine(): missing configuration for the state sql. Check STATE_SQL_* values in the configuration."); throw new FatalMisconfigurationException("SqlStateMachine(): missing configuration for the state sql. Check STATE_SQL_* values in the configuration.");
} }
if (!preg_match('/[0-9a-zA-Z$_]+/', STATE_SQL_DATABASE)) {
throw new FatalMisconfigurationException(sprintf("SqlStateMachine(): invalid database name '%s'. The name may contain ASCII 7bit letters, numbers and the '$' and '_' signs. Please change your configuration.", STATE_SQL_DATABASE));
}
$this->options = array(); $this->options = array();
if (trim(STATE_SQL_OPTIONS)) { if (trim(STATE_SQL_OPTIONS)) {
$this->options = unserialize(STATE_SQL_OPTIONS); $this->options = unserialize(STATE_SQL_OPTIONS);
...@@ -492,8 +496,6 @@ class SqlStateMachine implements IStateMachine { ...@@ -492,8 +496,6 @@ class SqlStateMachine implements IStateMachine {
* @return int * @return int
*/ */
public function GetStateVersion() { public function GetStateVersion() {
ZLog::Write(LOGLEVEL_DEBUG, "SqlStateMachine->GetStateVersion().");
$sth = null; $sth = null;
$record = null; $record = null;
$version = IStateMachine::STATEVERSION_01; $version = IStateMachine::STATEVERSION_01;
...@@ -727,7 +729,6 @@ class SqlStateMachine implements IStateMachine { ...@@ -727,7 +729,6 @@ class SqlStateMachine implements IStateMachine {
* @throws UnavailableException * @throws UnavailableException
*/ */
protected function checkDbAndTables() { protected function checkDbAndTables() {
ZLog::Write(LOGLEVEL_DEBUG, "SqlStateMachine->checkDbAndTables(): Checking if database and tables are available.");
try { try {
$sqlStmt = sprintf("SHOW TABLES FROM %s", STATE_SQL_DATABASE); $sqlStmt = sprintf("SHOW TABLES FROM %s", STATE_SQL_DATABASE);
$sth = $this->getDbh(false)->prepare($sqlStmt); $sth = $this->getDbh(false)->prepare($sqlStmt);
...@@ -768,7 +769,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -768,7 +769,7 @@ class SqlStateMachine implements IStateMachine {
$sqlStmt = sprintf("CREATE DATABASE %s", STATE_SQL_DATABASE); $sqlStmt = sprintf("CREATE DATABASE %s", STATE_SQL_DATABASE);
$sth = $dbh->prepare($sqlStmt); $sth = $dbh->prepare($sqlStmt);
$sth->execute(); $sth->execute();
ZLog::Write(LOGLEVEL_DEBUG, "SqlStateMachine->createDB(): Database created succesfully."); ZLog::Write(LOGLEVEL_DEBUG, "SqlStateMachine->createDB(): Database created successfully.");
$this->createTables(); $this->createTables();
$this->clearConnection($dbh); $this->clearConnection($dbh);
return true; return true;
...@@ -796,7 +797,7 @@ class SqlStateMachine implements IStateMachine { ...@@ -796,7 +797,7 @@ class SqlStateMachine implements IStateMachine {
)); ));
$sth = $this->getDbh()->prepare($sqlStmt); $sth = $this->getDbh()->prepare($sqlStmt);
$sth->execute(); $sth->execute();
ZLog::Write(LOGLEVEL_DEBUG, "SqlStateMachine->createTables(): tables created succesfully."); ZLog::Write(LOGLEVEL_DEBUG, "SqlStateMachine->createTables(): tables created successfully.");
return true; return true;
} }
catch (PDOException $ex) { catch (PDOException $ex) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment