pressidium / pressidium-cookie-consent

๐Ÿช Lightweight, user-friendly and customizable cookie consent banner to help you comply with the EU GDPR cookie law and CCPA regulations.
https://wordpress.org/plugins/pressidium-cookie-consent/
GNU General Public License v2.0
48 stars 2 forks source link

Fixed the "Multiple primary key defined" error on plugin reactivation #33

Closed mohammad425 closed 11 months ago

mohammad425 commented 11 months ago

Prior to this commit, when reactivating the plugin, a SQL error occurred due to the attempt to redefine a primary key. The error was specifically caused by the ALTER TABLE statement trying to change the primary key of the "pressidium_cookie_consents" table, which already existed in the database.

Multiple primary key defined

To resolve this issue, a check was implemented to verify the existence of the table before attempting any alterations. The new table_exists method was added to the codebase. Now, when the create method is called, it first checks if the target table already exists in the database. If it does, the method exits gracefully, avoiding any conflicting SQL statements.

This modification ensures that the table is only created if it doesn't exist, preventing the "Multiple primary key defined" error on plugin reactivation.

over-engineer commented 11 months ago

Hey, @mohammad425 ๐Ÿ‘‹

Thanks for reporting this and opening a PR; itโ€™s much appreciated!

Iโ€™ve reproduced the error you mentioned. After reviewing your PR, Iโ€™m ready to merge it into the codebase ๐Ÿ™‚

over-engineer commented 11 months ago

@mohammad425 Iโ€™ve merged this into the next branch. Your changes will be included in the next release. Thanks for taking the time to open this PR ๐Ÿ™‚