public function setupDatabaseTables()
    {
        $logger = $this->getLogger();
        $database = $this->getDatabase();

        $databaseHandle = $database->getDatabaseConnection();
        $tableDefinition = $database->getTableDefinition();

        $tables = array_keys($tableDefinition);
        foreach ($tables as $tableName) {
            $logger->writeln('<info>Table "' . $tableName . '"</info>');

            $statement = $databaseHandle->prepare('SHOW TABLES LIKE :table');
            $statement->bindParam(':table', $tableName, \PDO::PARAM_STR);
            $statement->execute();

            if ($statement->rowCount() == 1) {
                $logger->writeln('<info>=> Exists. Skip it</info>');
                continue;
            }

            // Table does not exists. Try to create it
            $createTableResult = $databaseHandle->query($tableDefinition[$tableName]);

            if ($createTableResult === false) {
                $databaseError = $databaseHandle->errorInfo();
                $message = 'Table "%s" could not be created. %s (%s)';
                $message = sprintf($message, $tableName, $databaseError[2], $databaseError[1]);
                throw new \Exception($message, 1398100879);

            } else {
                $logger->writeln('<info>Not exists. Created</info>');
            }
        }

        return true;
    }
public function setupDatabaseTables()
    {
        $logger = $this->getLogger();
        $database = $this->getDatabase();

        $databaseHandle = $database->getDatabaseConnection();
        $tableDefinition = $database->getTableDefinition();

        $tables = array_keys($tableDefinition);
        foreach ($tables as $tableName) {
            $logger->writeln('<info>Table "' . $tableName . '"</info>');

            $statement = $databaseHandle->prepare('SHOW TABLES LIKE :table');
            $statement->bindParam(':table', $tableName, \PDO::PARAM_STR);
            $statement->execute();

            if ($statement->rowCount() == 1) {
                $logger->writeln('<info>=> Exists. Skip it</info>');
                continue;
            }

            // Table does not exists. Try to create it
            $createTableResult = $databaseHandle->query($tableDefinition[$tableName]);

            if ($createTableResult === false) {
                $databaseError = $databaseHandle->errorInfo();
                $message = 'Table "%s" could not be created. %s (%s)';
                $message = sprintf($message, $tableName, $databaseError[2], $databaseError[1]);
                throw new \Exception($message, 1398100879);

            } else {
                $logger->writeln('<info>Not exists. Created</info>');
            }
        }

        return true;
    }
public function setupDatabaseTables ( ) { $ logger = $ this -> getLogger ( ) ; $ database = $ this -> getDatabase ( ) ; $ databaseHandle = $ database -> getDatabaseConnection ( ) ; $ tableDefinition = $ database -> getTableDefinition ( ) ; $ tables = array_keys ( $ tableDefinition ) ; foreach ( $ tables as $ tableName ) { $ logger -> writeln ( '<info>Table "' . $ tableName . '"</info>' ) ; $ statement = $ databaseHandle -> prepare ( 'SHOW TABLES LIKE :table' ) ; $ statement -> bindParam ( ':table' , $ tableName , \ PDO :: PARAM_STR ) ; $ statement -> execute ( ) ; if ( $ statement -> rowCount ( ) == 1 ) { $ logger -> writeln ( '<info>=> Exists. Skip it</info>' ) ; continue ; } // Table does not exists. Try to create it $ createTableResult = $ databaseHandle -> query ( $ tableDefinition [ $ tableName ] ) ; if ( $ createTableResult === false ) { $ databaseError = $ databaseHandle -> errorInfo ( ) ; $ message = 'Table "%s" could not be created. %s (%s)' ; $ message = sprintf ( $ message , $ tableName , $ databaseError [ 2 ] , $ databaseError [ 1 ] ) ; throw new \ Exception ( $ message , 1398100879 ) ; } else { $ logger -> writeln ( '<info>Not exists. Created</info>' ) ; } } return true ; }
Creates the necessary database tables, if they are not exists.

@return bool
@throws \Exception
Creates the necessary database tables if they are not exists .