From 217a3a5b1be0ea56d4db67965562007270e0a128 Mon Sep 17 00:00:00 2001 From: Peter Ojo Date: Fri, 15 Dec 2023 12:43:12 +0100 Subject: [PATCH] Failsafe assets installation (#439) * Catch errors when dist files do no exist * fix code style * Only install assets on activate and install --- src/AdyenPaymentShopware6.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/AdyenPaymentShopware6.php b/src/AdyenPaymentShopware6.php index bb636972..0d0a2cdf 100644 --- a/src/AdyenPaymentShopware6.php +++ b/src/AdyenPaymentShopware6.php @@ -50,31 +50,25 @@ class AdyenPaymentShopware6 extends Plugin { - public function build(ContainerBuilder $container): void - { - parent::build($container); - $this->installJsAssets($container->getParameter('kernel.shopware_version')); - } - public function installJsAssets($shopwareVersion) { $storefrontAssetPath = __DIR__ . '/Resources/app/storefront/dist/storefront/js/adyen-payment-shopware6.js'; $adminAssetPath = __DIR__ . '/Resources/public/administration/js/adyen-payment-shopware6.js'; if (\version_compare($shopwareVersion, '6.5.0.0', '<')) { - $resultStorefront = copy( + $resultStorefront = $this->safeCopyAsset( __DIR__ . '/Resources/app/storefront/dist/storefront/js/adyen-payment-shopware64.js.dist', $storefrontAssetPath ); - $resultAdmin = copy( + $resultAdmin = $this->safeCopyAsset( __DIR__ . '/Resources/public/administration/js/adyen-payment-shopware64.js.dist', $adminAssetPath ); } else { - $resultStorefront = copy( + $resultStorefront = $this->safeCopyAsset( __DIR__ . '/Resources/app/storefront/dist/storefront/js/adyen-payment-shopware65.js.dist', $storefrontAssetPath ); - $resultAdmin = copy( + $resultAdmin = $this->safeCopyAsset( __DIR__ . '/Resources/public/administration/js/adyen-payment-shopware64.js.dist', $adminAssetPath ); @@ -103,6 +97,7 @@ public function install(InstallContext $installContext): void public function activate(ActivateContext $activateContext): void { + $this->installJsAssets($activateContext->getCurrentShopwareVersion()); foreach (PaymentMethods\PaymentMethods::PAYMENT_METHODS as $paymentMethod) { $this->setPaymentMethodIsActive(true, $activateContext->getContext(), new $paymentMethod()); } @@ -568,6 +563,15 @@ private function updateTo3100(UpdateContext $updateContext): void ); } } + + private function safeCopyAsset($source, $destination): bool + { + try { + return copy($source, $destination); + } catch (\Exception $e) { + return false; + } + } } if (file_exists(__DIR__ . '/../vendor/autoload.php')) {