<?php declare(strict_types=1);
namespace MbdusArticleSort;
use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\DataAbstractionLayer\Indexing\EntityIndexerRegistry;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\Framework\Plugin\Context\UpdateContext;
class MbdusArticleSort extends Plugin
{
public function activate(ActivateContext $activateContext): void
{
$entityIndexerRegistry = $this->container->get(EntityIndexerRegistry::class);
$entityIndexerRegistry->sendIndexingMessage(['product.indexer']);
}
public function uninstall(UninstallContext $uninstallContext): void
{
parent::uninstall($uninstallContext);
/** @var Connection */
$connection = $this->container->get(Connection::class);
$sql="SELECT COUNT(1)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'product'
AND table_schema = DATABASE()
AND column_name = 'mbdusSort'";
$check = $connection->fetchOne($sql);
if (!empty ( $check )) {
try{
$sql = "ALTER TABLE product DROP mbdusSort;";
$connection->executeQuery($sql);
}catch (\Exception $ex) {
//
}
}
try{
$sql = "DELETE FROM migration WHERE class='MbdusArticleSort\Migration\Migration1629789536AddInheritance'";
$connection->executeQuery($sql);
}catch (\Exception $ex) {
//
}
//MbdusArticleSort\Migration\Migration1629789536AddInheritance
}
/**
* @param UpdateContext $updateContext
*/
public function update(UpdateContext $updateContext): void
{
/** @var Connection */
$connection = $this->container->get(Connection::class);
try{
$sql = "DELETE FROM `mbdus_productcategoriessort` WHERE `kind` = 2;";
$connection->executeStatement($sql);
}catch (\Exception $ex) {
//
}
parent::update($updateContext);
}
}