contao / installation-bundle

[READ-ONLY] Contao Installation Bundle
GNU Lesser General Public License v3.0
8 stars 9 forks source link

Install Tool does not work in dev environment #72

Closed fritzmg closed 6 years ago

fritzmg commented 6 years ago

Reproduction

  1. Create a new Contao installation via composer create-project contao/managed-edition.
  2. Create a fresh, empty database.
  3. Open the install tool via example.org/app_dev.php/contao/install.
  4. Accept the license, then enter a password.
  5. Enter the database credentials and save the settings.

On the next step you will see the following error message:

Variable "sql_message" does not exist.

This is because the Twig template main.html.twig uses

{% if sql_message is not empty %}

However, at this point sql_message is a non-existing variable. It would be defined here - but in a fresh installation the function returns here - thus the variable is never defined for the Twig rendering context.

Using is not empty on non-existent variables will lead to the Variable "…" does not exist error in the dev environment (it will not yield this error in the prod environment). See also https://straightupcraft.com/articles/testing-if-something-exists-is-defined-length-is-not-null-is-not-empty

You should use

{% if sql_message|default %}

instead.

Toflar commented 6 years ago

{% if sql_message is defined %} :)

fritzmg commented 6 years ago

{% if sql_message is defined %} :)

That's not enough. You want to check if sql_message is defined and not empty in this case - since it could be defined, but empty. hence

{% if sql_message|default %}
leofeyer commented 6 years ago

Why not add the variable to the default context?

https://github.com/contao/installation-bundle/blob/264566ecdc70cd9b9b3a0518fac05ba582396daa/src/Controller/InstallationController.php#L45

leofeyer commented 6 years ago

Fixed in cd68833f39bf35f013e067dd49a4649188a19778.