<?php declare(strict_types=1);
namespace Ngs\ShopRestrict;
use Doctrine\DBAL\Connection;
use Ngs\ShopRestrict\Service\RestrictedPageService;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\Framework\Plugin\Context\UpdateContext;
class NgsShopRestrict extends Plugin
{
public function install(InstallContext $installContext): void
{
// Do stuff such as creating a new payment method
}
public function uninstall(UninstallContext $uninstallContext): void
{
parent::uninstall($uninstallContext);
if ($uninstallContext->keepUserData()) {
return;
}
$connection = $this->container->get(Connection::class);
$connection->executeUpdate('DROP TABLE IF EXISTS `restricted_page`');
// Remove or deactivate the data created by the plugin
}
public function activate(ActivateContext $activateContext): void
{
parent::activate($activateContext);
//get the config service
$this->container->get(RestrictedPageService::class)->create($activateContext->getContext());
//set the specified values as defaults
}
public function deactivate(DeactivateContext $deactivateContext): void
{
// Deactivate entities, such as a new payment method
// Or remove previously created entities
$this->container->get(RestrictedPageService::class)->delete($deactivateContext->getContext());
}
public function update(UpdateContext $updateContext): void
{
// Update necessary stuff, mostly non-database related
}
public function postInstall(InstallContext $installContext): void
{
}
public function postUpdate(UpdateContext $updateContext): void
{
}
}