This PR introduces a check on the permission_id FK to ensure that it is not added multiple times on upgrades. It also names the key specifically to ensure future changes to the key can be targeted properly and removes old keys that were added since 3.4.0.
* Add FK check before adding the FK. Also give the FK a name to avoid auto generated names and duplicate keys.
* Remove additional OR
* Remove additional OR
* Final FK check query
* Add foreign key cleanup routine to 3.4.3 db version
* Only check on named foreign key now that we have a cleanup routine in place, use specific phpcignore
* Rework formatting of SQL query
* Change way to fetch and add FK, can't use procedural SQL, needs to be done via statements.
* Add table name to lookup
* Only clean up FK on the wc_download_log table
* Remove erenouse bracket
'file' string as part of plugin information is used for activating plugin in combination with slug, or instead of slug in the case of plugins already installed. Defaults to [slug].php.
This commit adds a new filter, "woocommerce_install_get_tables", to the WC_Install::get_tables() method, enabling WooCommerce extensions to register new, WooCommerce-specific tables, ensuring these tables can be cleaned up automatically should WooCommerce be uninstalled (useful for things like custom table data stores). Nothing gets added by default, but this provides an integration point for plugins like WooCommerce Custom Orders Table.
This commit adds a check to make sure wp_insert_term() returned a term and not an instance of WP_Error before trying to access it. Without this change, the old code could produce the following fatal error:
Uncaught Error: Cannot use object of type WP_Error as array in includes/class-wc-install.php:478
Fixes#19377
This commit casts the 'default_product_cat' option to integer before passing it to `term_exists()`. If we don't do this, `get_option( 'default_product_cat' )` return a string that is passed to `term_exists( $woocommerce_default_category, 'product_cat' )`. `term_exists()` assumes that strings are term names or slugs and search only for this fields to check if the given term exist. So it will return false (unless the term name equals to the term ID which is unlikely) even though the term exists. To make it search for terms IDs to check if the given term exists, it is necessary to pass an integer.
There were two outdated lists of WC tables. One used to drop tables when WC is uninstalled and another one to drop tables when a site is deleted in a multi site environment. This commit creates a new unified list of WC tables, adds the missing tables to this list and introduces a unit test that will fail if the list gets outdated.
WC doesn't support downgrades but the if condition that decides whether or not to call WC_Install::install() and apply database schema changes was checking if the WC version stored in the database is equal to the WC version in the code. This commit changes the check performed inside the if condition to verify if the WC version stored in the database is smaller than the version in the code. This way `dbDelta()` won't be called automatically by WC and revert database schema changes. This is particulary important for clustered providers where the version of the WC code running in one of the containers could be outdated and trigger a database downgrade.
Removed the print_r() call as phpcs was complaining about it and there is no need to output the version values as phpunit will do that if the test fails.