Skip to content

Commit

Permalink
Fix multi-currency autoload issue when plugin gets updated (#9681)
Browse files Browse the repository at this point in the history
Co-authored-by: Hector Lovo <[email protected]>
  • Loading branch information
ricardo and lovo-h authored Nov 7, 2024
1 parent 636e1f0 commit c580223
Show file tree
Hide file tree
Showing 121 changed files with 31 additions and 16 deletions.
5 changes: 5 additions & 0 deletions changelog/fix-9676-multi-currency-autoload
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fix
Comment: Keep multi-currency module in the same path to avoid autoload errors.


2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
},
"autoload": {
"psr-4": {
"WCPay\\MultiCurrency\\": "multi-currency/src",
"WCPay\\MultiCurrency\\": "includes/multi-currency",
"WCPay\\Vendor\\": "lib/packages",
"WCPay\\": "src"
},
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,12 @@ public function init_settings_pages( $settings_pages ): array {
return $settings_pages;
}

// Due to autoloader limitations, we shouldn't initiate MCCY settings if the plugin was just upgraded:
// https://github.com/Automattic/woocommerce-payments/issues/9676.
if ( did_action( 'upgrader_process_complete' ) ) {
return $settings_pages;
}

if ( $this->payments_account->is_provider_connected() ) {
$settings = new Settings( $this );
$settings->init_hooks();
Expand Down
5 changes: 5 additions & 0 deletions includes/multi-currency/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# WooPayments multi-currency directory

This directory contains the multi-currency module, which has been decoupled and extracted from the gateway code.

The module is responsible for handling all multi-currency functionality, both back-end and front-end.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@

<rule ref="WordPress.Files.FileName">
<exclude-pattern>tests/*</exclude-pattern>
<exclude-pattern>multi-currency/src</exclude-pattern>
<exclude-pattern>includes/multi-currency/*</exclude-pattern>
<exclude-pattern>src</exclude-pattern>
</rule>

Expand Down
4 changes: 2 additions & 2 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@
<code>WC_Subscriptions_Product</code>
</UndefinedClass>
</file>
<file src="multi-currency/src/Compatibility/WooCommerceProductAddOns.php">
<file src="includes/multi-currency/Compatibility/WooCommerceProductAddOns.php">
<UndefinedClass occurrences="2">
<code>\WC_Product_Addons_Helper</code>
<code>\WC_Product_Addons_Helper</code>
</UndefinedClass>
</file>
<file src="multi-currency/src/Compatibility/WooCommerceNameYourPrice.php">
<file src="includes/multi-currency/Compatibility/WooCommerceNameYourPrice.php">
<UndefinedClass occurrences="2">
<code>\WC_Name_Your_Price_Helpers</code>
<code>\WC_Name_Your_Price_Helpers</code>
Expand Down
6 changes: 3 additions & 3 deletions tasks/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ rm( 'dist/*.map' );
// copy the directories to the release folder
cp( '-Rf', filesToCopy, targetFolder );

// copy the multi-currency files
mkdir( '-p', targetFolder + '/multi-currency' );
cp( '-R', 'multi-currency/src', targetFolder + '/multi-currency/src' );
// The '/includes/multi-currency/client' directory is removed because '/includes/multi-currency/*' should contain only server-side files.
// Furthermore, the './client' directory is already included in 'dist' during the build step.
rm( '-rf', targetFolder + '/includes/multi-currency/client' );

const output = fs.createWriteStream(
releaseFolder + '/' + pluginSlug + '.zip'
Expand Down
4 changes: 2 additions & 2 deletions tests/js/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ module.exports = {
moduleDirectories: [
'node_modules',
'<rootDir>/client',
'<rootDir>/multi-currency/client',
'<rootDir>/includes/multi-currency/client',
],
moduleNameMapper: {
'^react$': '<rootDir>/node_modules/react',
'^react-dom$': '<rootDir>/node_modules/react-dom',
'^moment$': '<rootDir>/node_modules/moment',
'^moment-timezone$': '<rootDir>/node_modules/moment-timezone',
'^wcpay(.*)$': '<rootDir>/client$1',
'^multi-currency(.*)$': '<rootDir>/multi-currency/client$1',
'^multi-currency(.*)$': '<rootDir>/includes/multi-currency/client$1',
'^iti/utils$': '<rootDir>/node_modules/intl-tel-input/build/js/utils',
'^assets(.*?)(\\?.*)?$': '<rootDir>/assets$1',
'^@woocommerce/blocks-registry$':
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"paths": {
"assets/*": [ "../assets/*" ],
"wcpay/*": [ "./*" ],
"multi-currency/*": [ "../multi-currency/client/*" ],
"multi-currency/*": [ "../includes/multi-currency/client/*" ],
"iti/utils": [ "../node_modules/intl-tel-input/build/js/utils" ],
"react": [ "../node_modules/@types/react" ]
},
Expand Down
11 changes: 5 additions & 6 deletions webpack/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ module.exports = {
'subscription-edit-page': './client/subscription-edit-page.js',
tos: './client/tos/index.js',
'payment-gateways': './client/payment-gateways/index.js',
'multi-currency': './multi-currency/client/index.js',
'multi-currency': './includes/multi-currency/client/index.js',
'multi-currency-switcher-block':
'./multi-currency/client/blocks/currency-switcher.js',
'./includes/multi-currency/client/blocks/currency-switcher.js',
'multi-currency-analytics':
'./multi-currency/client/analytics/index.js',
'./includes/multi-currency/client/analytics/index.js',
order: './client/order/index.js',
'subscriptions-empty-state':
'./client/subscriptions-empty-state/index.js',
Expand Down Expand Up @@ -115,15 +115,14 @@ module.exports = {
extensions: [ '.ts', '.tsx', '.json', '.js', '.jsx' ],
modules: [
path.join( process.cwd(), 'client' ),
path.join( process.cwd(), 'multi-currency', 'client' ),
path.join( process.cwd(), 'includes/multi-currency/client' ),
'node_modules',
],
alias: {
assets: path.resolve( process.cwd(), 'assets' ),
'multi-currency': path.resolve(
process.cwd(),
'multi-currency',
'client'
'includes/multi-currency/client'
),
wcpay: path.resolve( process.cwd(), 'client' ),
iti: path.resolve(
Expand Down

0 comments on commit c580223

Please sign in to comment.