terminal42 / contao-notification_center

The most popular notification configuration extension for the Contao Open Source CMS!
64 stars 38 forks source link

fatal error visible in install tool in Contao 4 after installation #125

Closed fritzmg closed 7 years ago

fritzmg commented 7 years ago

Reproduction

  1. Install Contao 4 (managed or standard).
  2. Configure your database and web server accordingly.
  3. Run the Install Tool to set up the database.
  4. Run composer require terminal42/notification_center.
  5. Run the Install Tool again to update the database.

At the bottom you will see

Fatal error: Uncaught PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'contao4.tl_nc_gateway' doesn't exist in …/contao4/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:104 Stack trace: 
#0 …/contao4/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php(104): PDO->query('SELECT * FROM t...') 
#1 …/contao4/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(852): Doctrine\DBAL\Driver\PDOConnection->query('SELECT * FROM t...') 
#2 …/contao4/vendor/contao/core-bundle/src/Resources/contao/library/Contao/Database/Statement.php(284): Doctrine\DBAL\Connection->executeQuery('SELECT * FROM t...') 
#3 …/contao4/vendor/contao/core-bundle/src/Resources/contao/library/Contao/Database/Statement.php(257): Contao\Database\Statement->query() 
#4 …/contao4/vendor/contao/core-bundle/src/Resources/contao/library/Contao/Model.php(1089): Contao\Database\Statement->execute(Array) 
#5 …/contao4/vendor/contao/core-bundle in …/contao4/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php on line 99

Cause

In Contao 4.1.0 an onKernelTerminate event was introduced which executes the command scheduler: https://github.com/contao/core-bundle/pull/380

This in turn means, that any TL_CRON hook is executed also in the install tool. Thus, if the hook tries to access database fields that are not existent yet, a fatal error will occur. As discussed here any such hook needs to check if the database fields and tables exist.

fritzmg commented 7 years ago

This is probably not necessary anymore with Contao 4.4.0: https://github.com/contao/core-bundle/issues/736#issuecomment-306182210

With Contao 4.4.0 that error might only occur in the front end or back end when the extension is initially installed and the database has not been updated yet. However, in such a case the website is likely in a maintenance mode anyway.