custom/plugins/MbdusArticleSort/src/MbdusArticleSort.php line 11

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace MbdusArticleSort;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Framework\Plugin;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Indexing\EntityIndexerRegistry;
  6. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  7. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  8. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  9. class MbdusArticleSort extends Plugin
  10. {   
  11.     public function activate(ActivateContext $activateContext): void
  12.     {
  13.         $entityIndexerRegistry $this->container->get(EntityIndexerRegistry::class);
  14.         $entityIndexerRegistry->sendIndexingMessage(['product.indexer']);
  15.     }
  16.     
  17.     public function uninstall(UninstallContext $uninstallContext): void
  18.     {
  19.         parent::uninstall($uninstallContext);
  20.         
  21.         /** @var Connection */
  22.         $connection $this->container->get(Connection::class);
  23.         
  24.         $sql="SELECT COUNT(1)
  25.             FROM INFORMATION_SCHEMA.COLUMNS
  26.             WHERE table_name = 'product'
  27.             AND table_schema = DATABASE()
  28.             AND column_name = 'mbdusSort'";
  29.         $check $connection->fetchOne($sql);
  30.         if (!empty ( $check )) {
  31.             try{
  32.                 $sql "ALTER TABLE product DROP mbdusSort;";
  33.                 $connection->executeQuery($sql);
  34.             }catch (\Exception $ex) {
  35.                 //
  36.             }
  37.         }
  38.        
  39.         try{
  40.             $sql "DELETE FROM migration WHERE class='MbdusArticleSort\Migration\Migration1629789536AddInheritance'";
  41.             $connection->executeQuery($sql);
  42.         }catch (\Exception $ex) {
  43.             //
  44.         }
  45.         //MbdusArticleSort\Migration\Migration1629789536AddInheritance
  46.     }
  47.     
  48.     /**
  49.      * @param UpdateContext $updateContext
  50.      */
  51.     public function update(UpdateContext $updateContext): void
  52.     {   
  53.         /** @var Connection */
  54.         $connection $this->container->get(Connection::class);
  55.         
  56.         try{
  57.             $sql "DELETE FROM `mbdus_productcategoriessort` WHERE `kind` = 2;";
  58.             $connection->executeStatement($sql);
  59.         }catch (\Exception $ex) {
  60.             //
  61.         }
  62.         
  63.         parent::update($updateContext);
  64.     }
  65. }