<?php declare(strict_types=1);
namespace TwigelHardTheme;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Storefront\Framework\ThemeInterface;
use TwigelHardTheme\Service\CustomFieldService;
class TwigelHardTheme extends Plugin implements ThemeInterface
{
public function install(InstallContext $installContext): void
{
parent::install($installContext);
$this->applyUpdates(
$installContext->getContext(),
null,
$installContext->getCurrentPluginVersion()
);
}
public function uninstall(UninstallContext $uninstallContext): void
{
parent::uninstall($uninstallContext);
if ($uninstallContext->keepUserData()) {
return;
}
(new CustomFieldService(
$this->container->get('custom_field_set.repository'),
$uninstallContext->getContext()
))->remove();
}
private function applyUpdates(Context $context, $oldVersion = null, $newVersion = null)
{
$versionClosures = [
'1.0.0' => function () use ($context) {
(new CustomFieldService(
$this->container->get('custom_field_set.repository'),
$context
))->create();
return true;
}
];
foreach ($versionClosures as $version => $versionClosure) {
if ($oldVersion === null ||
(version_compare($oldVersion, $version, '<')
&& version_compare($version, $newVersion, '<='))
) {
if (!$versionClosure($this)) {
return false;
}
}
}
return true;
}
}