<?php declare(strict_types=1);
namespace Twigel\SportBadges;
use Doctrine\DBAL\Exception;
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 Twigel\SportBadges\Migration\Migration1669810672TwigelCreateBadgesTable;
class TwigelSportBadges extends Plugin
{
/**
* @throws Exception
* @param InstallContext $installContext
* @return void
*/
public function install(InstallContext $installContext): void
{
parent::install($installContext);
$this->applyUpdates(
$installContext->getContext(),
null,
$installContext->getCurrentPluginVersion()
);
(new Migration1669810672TwigelCreateBadgesTable())->update($this->container->get('Doctrine\DBAL\Connection'));
}
/**
* @param UninstallContext $uninstallContext
* @return void
* @throws Exception
*/
public function uninstall(UninstallContext $uninstallContext): void
{
parent::uninstall($uninstallContext);
if ($uninstallContext->keepUserData()) {
return;
}
(new Migration1669810672TwigelCreateBadgesTable())->updateDestructive($this->container->get('Doctrine\DBAL\Connection'));
}
private function applyUpdates(Context $context, $oldVersion = null, $newVersion = null): void
{
$versionClosures = [
'1.0.0' => function () use ($context) {
return true;
}
];
foreach ($versionClosures as $version => $versionClosure) {
if ($oldVersion === null ||
(version_compare($oldVersion, $version, '<')
&& version_compare($version, $newVersion, '<='))
) {
if (!$versionClosure($this)) {
return;
}
}
}
}
}