<?php declare(strict_types=1);
namespace S360Experts;
use Shopware\Core\Framework\Plugin;
use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Shopware\Core\Framework\DataAbstractionLayer\Indexing\EntityIndexerRegistry;
class S360Experts extends Plugin
{
public function activate(ActivateContext $activateContext): void
{
$entityIndexerRegistry = $this->container->get(EntityIndexerRegistry::class);
$entityIndexerRegistry->sendIndexingMessage(['product.indexer']);
$entityIndexerRegistry = $this->container->get(EntityIndexerRegistry::class);
$entityIndexerRegistry->sendIndexingMessage(['category.indexer']);
}
public function install(InstallContext $installContext): void
{
parent::install($installContext);
}
public function uninstall(UninstallContext $uninstallContext): void
{
if ($uninstallContext->keepUserData()) {
return;
}
$this->removeUserData();
}
private function removeUserData()
{
$connection = $this->container->get(Connection::class);
$connection->executeUpdate('ALTER TABLE `product` DROP COLUMN `experts`');
$connection->executeUpdate('ALTER TABLE `category` DROP COLUMN `experts`');
$connection->executeQuery('DROP TABLE IF EXISTS `s360_expert_category`');
$connection->executeQuery('DROP TABLE IF EXISTS `s360_expert_product`');
$connection->executeQuery('DROP TABLE IF EXISTS `s360_experts_expert_translation`');
$connection->executeQuery('DROP TABLE IF EXISTS `s360_experts_expert`');
}
}