Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No database selected during /contao/install when using download archive #736

Closed
fritzmg opened this issue Mar 25, 2017 · 21 comments
Closed
Assignees
Labels
Milestone

Comments

@fritzmg
Copy link
Contributor

fritzmg commented Mar 25, 2017

  1. Download the Contao Managed Edition 4.3.7 from contao.org
  2. Extract and run /contao/install.
  3. Accept the license.

On the subsequent screens (entering the install tool password plus entering the database details) the following error message will be displayed at the bottom of the page:

Fatal error: Uncaught PDOException: SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected in \vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php:104 
Stack trace: 
#0 \vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php(104): PDO->query('SHOW FULL TABLE...') 
#1 \vendor\doctrine\dbal\lib\Doctrine\DBAL\Connection.php(852): Doctrine\DBAL\Driver\PDOConnection->query('SHOW FULL TABLE...') 
#2 \vendor\doctrine\dbal\lib\Doctrine\DBAL\Connection.php(785): Doctrine\DBAL\Connection->executeQuery('SHOW FULL TABLE...', Array, Array) 
#3 \vendor\doctrine\dbal\lib\Doctrine\DBAL\Schema\AbstractSchemaManager.php(219): Doctrine\DBAL\Connection->fetchAll('SHOW FULL TABLE...') 
#4 \vendor\doctrine\dbal\lib\Doctrine\DBAL\Schema\AbstractSchemaManager.php(207): Doctrine\DBAL\Schema\AbstractSchemaManager->listTableNames() 
#5 \vendor\contao\core-bundle\src\EventListener\ in \vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php on line 99

Testing environment:

  • Windows 10
  • XAMPP
  • PHP 7.1.1 (FastCGI)

Not sure if this ticket belongs to the core-bundle, the installation-bundle or the managed-edition. The error only seems to happen with the managed edition during installation and the error is genereated within the EventListener of the core-bundle.

The error message is appended after the </html> from the install tool.

@leofeyer
Copy link
Member

I cannot reproduce the issue and it has not occurred at my presentation on the Contao Nordtag, either.

@fritzmg
Copy link
Contributor Author

fritzmg commented Mar 25, 2017

Yeah haven't seen any other reports yet either. May be it is Windows specific, I'll try to debug.

@fritzmg
Copy link
Contributor Author

fritzmg commented Mar 26, 2017

The error happens here:

    /**
     * Checks whether the controller can be run.
     *
     * @return bool
     */
    private function canRunController()
    {
        /** @var Config $config */
        $config = $this->framework->getAdapter(Config::class);
        return $config->isComplete()
            && !$config->get('disableCron')
            && $this->connection->getSchemaManager()->tablesExist(['tl_cron'])
        ;
    }

https://github.com/contao/core-bundle/blob/4.3.7/src/EventListener/CommandSchedulerListener.php#L73

The CommandSchedulerListener is querying a table - but that won't be possible during /contao/install if the database connection has not been set up yet.

@leofeyer how did you test? This problem only occurs if you download Contao from contao.org (and it needs to be a fresh installation). It won't occur with composer create-project, since the database connection will be set up during that process.

@fritzmg fritzmg changed the title No database selected during /contao/install in managed edition No database selected during /contao/install when using download archive Mar 26, 2017
@leofeyer
Copy link
Member

This has been fixed in e5527fb already.

@fritzmg
Copy link
Contributor Author

fritzmg commented Apr 25, 2017

This is still happening in Contao 4.3.8 (Managed Edition downloaded from contao.org).

screen shot 2017-04-25 at 09 23 00

@fritzmg
Copy link
Contributor Author

fritzmg commented Apr 25, 2017

$this->connection->isConnected()

returns true, even though no database connection is present.

@fritzmg
Copy link
Contributor Author

fritzmg commented Apr 25, 2017

Doctrine\DBAL\Connection::isConnected returns

/**
 * Whether an actual connection to the database is established.
 *
 * @return boolean
 */
public function isConnected()
{
    return $this->_isConnected;
}

https://github.com/doctrine/dbal/blob/v2.5.12/lib/Doctrine/DBAL/Connection.php#L551

and this variable will be set to true here:

$this->_conn = $this->_driver->connect($this->_params, $user, $password, $driverOptions);
$this->_isConnected = true;

https://github.com/doctrine/dbal/blob/v2.5.12/lib/Doctrine/DBAL/Connection.php#L361

I am guessing that a connection can already be established with these default parameters:

parameters:
    database_host: localhost
    database_port: ~
    database_user: ~
    database_password: ~
    database_name: ~

# Doctrine configuration
doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                driver: pdo_mysql
                host: "%database_host%"
                port: "%database_port%"
                user: "%database_user%"
                password: "%database_password%"
                dbname: "%database_name%"
                charset: UTF8

https://github.com/contao/manager-bundle/blob/4.3.8/src/Resources/contao-manager/doctrine.yml

However, you are of course not able to do anything with that connection (due to the missing, username, password and database name).

@fritzmg
Copy link
Contributor Author

fritzmg commented Apr 25, 2017

I am guessing this happens under the following circumstances:

  • A MySQL server is available at the default localhost address and the default port 3306.
  • The MySQL USER_PRIVILIGES table contains a record with a GRANTEE of ''@'%' or ''@'localhost' for example. It doesn't matter, that this user has not actual privileges. But it does make it possible to connect to the MySQL server.

@leofeyer
Copy link
Member

That's a server misconfiguration IMHO.

@fritzmg
Copy link
Contributor Author

fritzmg commented Apr 25, 2017

Yeah, I am assuming it's just something XAMPP does by default, I am not sure though.

@fritzmg
Copy link
Contributor Author

fritzmg commented Apr 25, 2017

According to the MySQL documentation these anonymous accounts are created by default - but it advises you to remove them: https://dev.mysql.com/doc/refman/5.7/en/default-privileges.html

@fritzmg
Copy link
Contributor Author

fritzmg commented May 20, 2017

A related problem happens when you install an extension that has TL_CRON entries defined (e.g. notification_center). When opening the install tool after installation, you might see something like

Fatal error: Uncaught PDOException: SQLSTATE[42S02]: Base table or view not found:
1146 Table 'contao4.tl_nc_gateway' doesn't exist in …

at the bottom of the install tool for example, before the database is updated.

May be the front end cron should not be integrated into the install tool at all.

@leofeyer
Copy link
Member

The command scheduler checks if there is a database connection and if the tables have been created: https://github.com/contao/core-bundle/blob/release/4.4.0/src/EventListener/CommandSchedulerListener.php#L71-L75

@fritzmg
Copy link
Contributor Author

fritzmg commented May 29, 2017

The command scheduler checks if there is a database connection and if the tables have been created: https://github.com/contao/core-bundle/blob/release/4.4.0/src/EventListener/CommandSchedulerListener.php#L71-L75

It only checks for tl_cron. If you install an extension which registers a TL_CRON hook and has its own database tables or fields and in that hook the extension accesses these tables or fields, you will get a fatal error at the bottom of the install tool, because the command scheduler is executed there.

Imho the command scheduler should net get executed at all by the install tool.

@leofeyer
Copy link
Member

Then those extensions are not set up correctly, because they don't check if their tables exist.

@fritzmg
Copy link
Contributor Author

fritzmg commented May 29, 2017

Then those extensions are not set up correctly, because they don't check if their tables exist.

Hm, is an extension supposed to check for their tables and fields in every hook?

@leofeyer
Copy link
Member

Of course. The install tool triggers a bunch of hooks and if you subscribe to one of it and want to access the database, you should check if it exists.

@fritzmg
Copy link
Contributor Author

fritzmg commented May 30, 2017

The install tool triggers a bunch of hooks and if you subscribe to one of it and want to access the database, you should check if it exists.

Yes, though in the past the command scheduler was not executed within the install tool, thus it was safe to register TL_CRON hooks that require a properly updated database. May be this should be added to the UPGRADE.md.

@fritzmg
Copy link
Contributor Author

fritzmg commented May 30, 2017

This change was introduced in Contao 4.1.0 as far as I can see. Previously there was no CommandSchedulerListener on the onKernelTerminate event.

@aschempp
Copy link
Member

see contao/installation-bundle#54

@leofeyer
Copy link
Member

leofeyer commented Jun 5, 2017

Changed in fd36131.

leofeyer added a commit that referenced this issue May 8, 2020
Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Fixes #736
| Docs PR or issue | -

<!--
Bugfixes should be based on the 4.4 or 4.9 branch and features on the master
branch. Select the correct branch in the "base:" drop-down menu above.

Replace this notice with a short README for your feature/bugfix. This will help
people to understand your PR and can be used as a start for the documentation.
-->

Commits
-------

5eca1512 Add a "rawValue" property to the TextArea class
69e58704 Also remove the str_replace() when returning the raw value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants