<?php declare(strict_types=1);
namespace Tonur\SeoFilterLandingpages;
use Shopware\Core\Framework\Plugin;
use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
class TonurSeoFilterLandingpages6 extends Plugin
{
public function uninstall(UninstallContext $context): void
{
parent::uninstall($context);
if ($context->keepUserData()) {
return;
}
$connection = $this->container->get(Connection::class);
$connection->executeUpdate('DROP TABLE IF EXISTS `repertus_seo_filter_landingpage_translation`');
$connection->executeUpdate('DROP TABLE IF EXISTS `repertus_seo_filter_landingpage_sales_channel`');
$connection->executeUpdate('DROP TABLE IF EXISTS `repertus_seo_filter_landingpage_property`');
$connection->executeUpdate('DROP TABLE IF EXISTS `repertus_seo_filter_landingpage_parameter`');
$connection->executeUpdate('DROP TABLE IF EXISTS `repertus_seo_filter_landingpage_manufacturer`');
$connection->executeUpdate('DROP TABLE IF EXISTS `repertus_seo_filter_landingpage_language`');
$connection->executeUpdate('DROP TABLE IF EXISTS `repertus_seo_filter_landingpage`');
$connection->executeUpdate('DELETE FROM `seo_url_template` WHERE `entity_name` = "repertus_seo_filter_landingpage"');
if ($this->columnAlreadyExistsInTable('landingpages', 'sales_channel')) {
$connection->executeUpdate('ALTER TABLE `sales_channel` DROP COLUMN `landingpages`');
}
if ($this->columnAlreadyExistsInTable('landingpages', 'property_group_option')) {
$connection->executeUpdate('ALTER TABLE `property_group_option` DROP COLUMN `landingpages`');
}
if ($this->columnAlreadyExistsInTable('landingpages', 'product_manufacturer')) {
$connection->executeUpdate('ALTER TABLE `product_manufacturer` DROP COLUMN `landingpages`');
}
}
protected function columnAlreadyExistsInTable($column, $table)
{
$connection = $this->container->get(Connection::class);
$result = $connection->fetchAssoc("SELECT ttc.* FROM (SELECT 1 as id) tmp LEFT JOIN $table ttc ON tmp.id = ttc.id LIMIT 1");
return array_key_exists($column, $result);
}
}