Skip to content

Commit

Permalink
Failsafe assets installation (#439)
Browse files Browse the repository at this point in the history
* Catch errors when dist files do no exist

* fix code style

* Only install assets on activate and install
  • Loading branch information
peterojo authored Dec 15, 2023
1 parent e208e75 commit 217a3a5
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/AdyenPaymentShopware6.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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')) {
Expand Down

0 comments on commit 217a3a5

Please sign in to comment.