From 0c07ebd62956294beaddb0b0352aa0a1341c1d44 Mon Sep 17 00:00:00 2001 From: Alex P Date: Thu, 17 Feb 2022 18:51:24 +0200 Subject: [PATCH] Use plugin version as asset version --- modules/ppcp-button/services.php | 1 + modules/ppcp-button/src/Assets/SmartButton.php | 14 ++++++++++++-- modules/ppcp-onboarding/services.php | 1 + .../src/Assets/OnboardingAssets.php | 16 +++++++++++++--- modules/ppcp-vaulting/services.php | 3 ++- .../src/Assets/MyAccountPaymentsAssets.php | 14 ++++++++++++-- .../src/Assets/SettingsPageAssets.php | 18 ++++++++---------- .../ppcp-wc-gateway/src/WCGatewayModule.php | 2 +- modules/ppcp-webhooks/services.php | 3 ++- .../Status/Assets/WebhooksStatusPageAssets.php | 16 +++++++++++++--- src/services.php | 8 +++++++- 11 files changed, 72 insertions(+), 24 deletions(-) diff --git a/modules/ppcp-button/services.php b/modules/ppcp-button/services.php index f068cf5bb..9cec5b302 100644 --- a/modules/ppcp-button/services.php +++ b/modules/ppcp-button/services.php @@ -73,6 +73,7 @@ return array( $currency = $container->get( 'api.shop.currency' ); return new SmartButton( $container->get( 'button.url' ), + $container->get( 'ppcp.asset-version' ), $container->get( 'session.handler' ), $settings, $payer_factory, diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php index 35da7c3e8..08e22815b 100644 --- a/modules/ppcp-button/src/Assets/SmartButton.php +++ b/modules/ppcp-button/src/Assets/SmartButton.php @@ -44,6 +44,13 @@ class SmartButton implements SmartButtonInterface { */ private $module_url; + /** + * The assets version. + * + * @var string + */ + private $version; + /** * The Session Handler. * @@ -125,6 +132,7 @@ class SmartButton implements SmartButtonInterface { * SmartButton constructor. * * @param string $module_url The URL to the module. + * @param string $version The assets version. * @param SessionHandler $session_handler The Session Handler. * @param Settings $settings The Settings. * @param PayerFactory $payer_factory The Payer factory. @@ -140,6 +148,7 @@ class SmartButton implements SmartButtonInterface { */ public function __construct( string $module_url, + string $version, SessionHandler $session_handler, Settings $settings, PayerFactory $payer_factory, @@ -155,6 +164,7 @@ class SmartButton implements SmartButtonInterface { ) { $this->module_url = $module_url; + $this->version = $version; $this->session_handler = $session_handler; $this->settings = $settings; $this->payer_factory = $payer_factory; @@ -406,7 +416,7 @@ class SmartButton implements SmartButtonInterface { 'ppcp-hosted-fields', untrailingslashit( $this->module_url ) . '/assets/css/hosted-fields.css', array(), - 1 + $this->version ); } if ( $load_script ) { @@ -414,7 +424,7 @@ class SmartButton implements SmartButtonInterface { 'ppcp-smart-button', untrailingslashit( $this->module_url ) . '/assets/js/button.js', array( 'jquery' ), - '1.3.2', + $this->version, true ); diff --git a/modules/ppcp-onboarding/services.php b/modules/ppcp-onboarding/services.php index 81e25ad31..06ba43187 100644 --- a/modules/ppcp-onboarding/services.php +++ b/modules/ppcp-onboarding/services.php @@ -131,6 +131,7 @@ return array( $login_seller_endpoint = $container->get( 'onboarding.endpoint.login-seller' ); return new OnboardingAssets( $container->get( 'onboarding.url' ), + $container->get( 'ppcp.asset-version' ), $state, $container->get( 'onboarding.environment' ), $login_seller_endpoint diff --git a/modules/ppcp-onboarding/src/Assets/OnboardingAssets.php b/modules/ppcp-onboarding/src/Assets/OnboardingAssets.php index b05bd3023..806df84f5 100644 --- a/modules/ppcp-onboarding/src/Assets/OnboardingAssets.php +++ b/modules/ppcp-onboarding/src/Assets/OnboardingAssets.php @@ -25,6 +25,13 @@ class OnboardingAssets { */ private $module_url; + /** + * The assets version. + * + * @var string + */ + private $version; + /** * The State. * @@ -50,18 +57,21 @@ class OnboardingAssets { * OnboardingAssets constructor. * * @param string $module_url The URL to the module. + * @param string $version The assets version. * @param State $state The State object. * @param Environment $environment The Environment. * @param LoginSellerEndpoint $login_seller_endpoint The LoginSeller endpoint. */ public function __construct( string $module_url, + string $version, State $state, Environment $environment, LoginSellerEndpoint $login_seller_endpoint ) { $this->module_url = untrailingslashit( $module_url ); + $this->version = $version; $this->state = $state; $this->environment = $environment; $this->login_seller_endpoint = $login_seller_endpoint; @@ -79,14 +89,14 @@ class OnboardingAssets { 'ppcp-onboarding', $url, array(), - 1 + $this->version ); $url = untrailingslashit( $this->module_url ) . '/assets/js/settings.js'; wp_register_script( 'ppcp-settings', $url, array(), - 1, + $this->version, true ); @@ -95,7 +105,7 @@ class OnboardingAssets { 'ppcp-onboarding', $url, array( 'jquery' ), - 1, + $this->version, true ); wp_localize_script( diff --git a/modules/ppcp-vaulting/services.php b/modules/ppcp-vaulting/services.php index 0e3e2d7d1..c7b5bac1e 100644 --- a/modules/ppcp-vaulting/services.php +++ b/modules/ppcp-vaulting/services.php @@ -22,7 +22,8 @@ return array( }, 'vaulting.assets.myaccount-payments' => function( ContainerInterface $container ) : MyAccountPaymentsAssets { return new MyAccountPaymentsAssets( - $container->get( 'vaulting.module-url' ) + $container->get( 'vaulting.module-url' ), + $container->get( 'ppcp.asset-version' ) ); }, 'vaulting.payment-tokens-renderer' => static function (): PaymentTokensRenderer { diff --git a/modules/ppcp-vaulting/src/Assets/MyAccountPaymentsAssets.php b/modules/ppcp-vaulting/src/Assets/MyAccountPaymentsAssets.php index 80e9bc3db..36c3a4da3 100644 --- a/modules/ppcp-vaulting/src/Assets/MyAccountPaymentsAssets.php +++ b/modules/ppcp-vaulting/src/Assets/MyAccountPaymentsAssets.php @@ -23,15 +23,25 @@ class MyAccountPaymentsAssets { */ private $module_url; + /** + * The assets version. + * + * @var string + */ + private $version; + /** * MyAccountPaymentsAssets constructor. * * @param string $module_url The URL to the module. + * @param string $version The assets version. */ public function __construct( - string $module_url + string $module_url, + string $version ) { $this->module_url = untrailingslashit( $module_url ); + $this->version = $version; } /** @@ -44,7 +54,7 @@ class MyAccountPaymentsAssets { 'ppcp-vaulting-myaccount-payments', untrailingslashit( $this->module_url ) . '/assets/js/myaccount-payments.js', array( 'jquery' ), - '1', + $this->version, true ); } diff --git a/modules/ppcp-wc-gateway/src/Assets/SettingsPageAssets.php b/modules/ppcp-wc-gateway/src/Assets/SettingsPageAssets.php index fd89636ad..d2c031622 100644 --- a/modules/ppcp-wc-gateway/src/Assets/SettingsPageAssets.php +++ b/modules/ppcp-wc-gateway/src/Assets/SettingsPageAssets.php @@ -25,11 +25,11 @@ class SettingsPageAssets { private $module_url; /** - * The filesystem path to the module dir. + * The assets version. * * @var string */ - private $module_path; + private $version; /** * The bearer. @@ -42,13 +42,13 @@ class SettingsPageAssets { * Assets constructor. * * @param string $module_url The url of this module. - * @param string $module_path The filesystem path to this module. + * @param string $version The assets version. * @param Bearer $bearer The bearer. */ - public function __construct( string $module_url, string $module_path, Bearer $bearer ) { - $this->module_url = $module_url; - $this->module_path = $module_path; - $this->bearer = $bearer; + public function __construct( string $module_url, string $version, Bearer $bearer ) { + $this->module_url = $module_url; + $this->version = $version; + $this->bearer = $bearer; } /** @@ -102,13 +102,11 @@ class SettingsPageAssets { * @param Bearer $bearer The bearer. */ private function register_admin_assets( Bearer $bearer ) { - $gateway_settings_script_path = trailingslashit( $this->module_path ) . 'assets/js/gateway-settings.js'; - wp_enqueue_script( 'ppcp-gateway-settings', trailingslashit( $this->module_url ) . 'assets/js/gateway-settings.js', array(), - file_exists( $gateway_settings_script_path ) ? (string) filemtime( $gateway_settings_script_path ) : null, + $this->version, true ); diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php index ee8746ca5..2649e60af 100644 --- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php +++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php @@ -74,7 +74,7 @@ class WCGatewayModule implements ModuleInterface { if ( $c->has( 'wcgateway.url' ) ) { $assets = new SettingsPageAssets( $c->get( 'wcgateway.url' ), - $c->get( 'wcgateway.absolute-path' ), + $c->get( 'ppcp.asset-version' ), $c->get( 'api.bearer' ) ); $assets->register_assets(); diff --git a/modules/ppcp-webhooks/services.php b/modules/ppcp-webhooks/services.php index 536abaa1b..1b5269ab3 100644 --- a/modules/ppcp-webhooks/services.php +++ b/modules/ppcp-webhooks/services.php @@ -156,7 +156,8 @@ return array( 'webhook.status.assets' => function( ContainerInterface $container ) : WebhooksStatusPageAssets { return new WebhooksStatusPageAssets( - $container->get( 'webhook.module-url' ) + $container->get( 'webhook.module-url' ), + $container->get( 'ppcp.asset-version' ) ); }, diff --git a/modules/ppcp-webhooks/src/Status/Assets/WebhooksStatusPageAssets.php b/modules/ppcp-webhooks/src/Status/Assets/WebhooksStatusPageAssets.php index 27f0c0dd1..9ad6f8e70 100644 --- a/modules/ppcp-webhooks/src/Status/Assets/WebhooksStatusPageAssets.php +++ b/modules/ppcp-webhooks/src/Status/Assets/WebhooksStatusPageAssets.php @@ -26,15 +26,25 @@ class WebhooksStatusPageAssets { */ private $module_url; + /** + * The assets version. + * + * @var string + */ + private $version; + /** * WebhooksStatusPageAssets constructor. * * @param string $module_url The URL to the module. + * @param string $version The assets version. */ public function __construct( - string $module_url + string $module_url, + string $version ) { $this->module_url = untrailingslashit( $module_url ); + $this->version = $version; } /** @@ -47,14 +57,14 @@ class WebhooksStatusPageAssets { 'ppcp-webhooks-status-page-style', untrailingslashit( $this->module_url ) . '/assets/css/status-page.css', array(), - '1' + $this->version ); wp_register_script( 'ppcp-webhooks-status-page', untrailingslashit( $this->module_url ) . '/assets/js/status-page.js', array(), - '1', + $this->version, true ); diff --git a/src/services.php b/src/services.php index f5abda635..e84aee72b 100644 --- a/src/services.php +++ b/src/services.php @@ -14,8 +14,14 @@ use Psr\Container\ContainerInterface; use WpOop\WordPress\Plugin\PluginInterface; return array( - 'ppcp.plugin' => function( ContainerInterface $container ) : PluginInterface { + 'ppcp.plugin' => function( ContainerInterface $container ) : PluginInterface { $factory = new FilePathPluginFactory( new StringVersionFactory() ); return $factory->createPluginFromFilePath( dirname( realpath( __FILE__ ), 2 ) . '/woocommerce-paypal-payments.php' ); }, + 'ppcp.asset-version' => function( ContainerInterface $container ) : string { + $plugin = $container->get( 'ppcp.plugin' ); + assert( $plugin instanceof PluginInterface ); + + return (string) $plugin->getVersion(); + }, );