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

Adding this plugin breaks Mautic completly through SQL error (even without being installed) #290

Open
Moongazer opened this issue Dec 2, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@Moongazer
Copy link

Mautic Version

4.2.x series

PHP version

7.4.30

What browsers are you seeing the problem on?

Firefox

What happened?

CustomObjectsBundle: v1.0.0 (installed via composer)
Mautic: v4.4.5 (installed via composer)
Using DDEV

Adding this plugin the first time to an installation breaks Mautic completely through a SQL error (see below). Not the dashboard nor any other page is accessible anymore. This happens before reaching over to the plugin-configuration page to enable/install this plugin.

It happened already in Mautic v4.4.3, just updated to v4.4.5 because there have been some PRs regarding this plugin.

Reason:
It seems some SQL queries already expecting the table custom_object to be present, also the plugin was not installed yet and had no chance to update the database (to create the plugin related tables).

How can we reproduce this issue?

Step 1: Install Mautic via composer and login to see everything is working
Step 1: Install the plugin via composer require acquia/mc-cs-plugin-custom-objects
Step 2: Clear the cache php bin/console cache:clear
Step 3: Trying to open the Mautic dashboard or any other page will result in the message "Uh oh! I think I broke it. If I do it again, please report me to the system administrator!"

Relevant log output

[2022-12-02 15:22:22] mautic.CRITICAL: Uncaught PHP Exception Doctrine\DBAL\Exception\TableNotFoundException: "An exception occurred while executing 'SELECT c0_.is_published AS is_published_0, c0_.date_added AS date_added_1, c0_.created_by AS created_by_2, c0_.created_by_user AS created_by_user_3, c0_.date_modified AS date_modified_4, c0_.modified_by AS modified_by_5, c0_.modified_by_user AS modified_by_user_6, c0_.checked_out AS checked_out_7, c0_.checked_out_by AS checked_out_by_8, c0_.checked_out_by_user AS checked_out_by_user_9, c0_.id AS id_10, c0_.alias AS alias_11, c0_.name_singular AS name_singular_12, c0_.name_plural AS name_plural_13, c0_.description AS description_14, c0_.lang AS lang_15, c0_.type AS type_16, c0_.category_id AS category_id_17, c0_.relationship_object AS relationship_object_18, c0_.master_object AS master_object_19 FROM custom_object c0_ LEFT JOIN categories c1_ ON c0_.category_id = c1_.id WHERE c0_.is_published = ?' with params [1]:  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db.custom_object' doesn't exist" at /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 61 {"exception":"[object] (Doctrine\\DBAL\\Exception\\TableNotFoundException(code: 0): An exception occurred while executing 'SELECT c0_.is_published AS is_published_0, c0_.date_added AS date_added_1, c0_.created_by AS created_by_2, c0_.created_by_user AS created_by_user_3, c0_.date_modified AS date_modified_4, c0_.modified_by AS modified_by_5, c0_.modified_by_user AS modified_by_user_6, c0_.checked_out AS checked_out_7, c0_.checked_out_by AS checked_out_by_8, c0_.checked_out_by_user AS checked_out_by_user_9, c0_.id AS id_10, c0_.alias AS alias_11, c0_.name_singular AS name_singular_12, c0_.name_plural AS name_plural_13, c0_.description AS description_14, c0_.lang AS lang_15, c0_.type AS type_16, c0_.category_id AS category_id_17, c0_.relationship_object AS relationship_object_18, c0_.master_object AS master_object_19 FROM custom_object c0_ LEFT JOIN categories c1_ ON c0_.category_id = c1_.id WHERE c0_.is_published = ?' with params [1]:\n\nSQLSTATE[42S02]: Base table or view not found: 1146 Table 'db.custom_object' doesn't exist at /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:61, Doctrine\\DBAL\\Driver\\PDO\\Exception(code: 42S02): SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db.custom_object' doesn't exist at /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDO/Exception.php:18, PDOException(code: 42S02): SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db.custom_object' doesn't exist at /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:117)"} {"hostname":"medizen-mautic-web","pid":7275}


### Code of Conduct

- [X] I confirm that I have read and agree to follow this project's Code of Conduct
@Moongazer Moongazer added the bug Something isn't working label Dec 2, 2022
@escopecz
Copy link
Contributor

escopecz commented Dec 2, 2022

Please run bin/console mautic:plugins:install do add the required tables. The plugin executes on dashboard as it adds menu item for each custom object for example. But the queries should be executed only when the plugin is enabled. See

https://github.com/acquia/mc-cs-plugin-custom-objects/blob/staging/EventListener/MenuSubscriber.php#L45

So either you have installed it before or there is some DB call that is not checked against the plugin being published. If you find such place please let us know!

I'd suggest to install the plugin properly to fix this particular issue until the problematic query is found.

@Moongazer
Copy link
Author

Moongazer commented Dec 2, 2022

Yes, running bin/console mautic:plugins:install solved it, thanks.

I'm pretty new to Mautic, not really sure how it works internally. All I can provide you for now are 2 stack-traces calling 2 different Mautic URLs where the error occurred (just reproduced it). I guess CustomObjectPermissions is the predator here.

Calling https://medizen-mautic.ddev.site/s/dashboard:
mautic-customobjects-error-01

Calling https://medizen-mautic.ddev.site/s/contacts:
mautic-customobjects-error-02

Hope that helps already a bit, if not please let me know and I will see what I can do.

@escopecz
Copy link
Contributor

escopecz commented Dec 5, 2022

This is very helpful. We need to add

if (!$this->isEnabled()) {
    return;
}

at
https://github.com/acquia/mc-cs-plugin-custom-objects/blob/staging/Security/Permissions/CustomObjectPermissions.php#L59

If anyone would have spare 10 minutes to create the PR please do.

@Moongazer
Copy link
Author

Very glad to see active dev/community here, and happy to contribute.
But the PR rules was displayed to late, thats why the branch naming is incorrect I guess.

Also I was not able to reset my system to the original state where the error occurred in the first place, to test if the fix is working. The plugin was always enabled already, even if I removed it from the plugin folder and cleared the cache in the hard way rm -rf public/var/cache/. Moving it back to the plugin folder and clearing the cache again, the isEnabled() always returned true, and I could not figure out where it comes from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants