<?php declare(strict_types=1);
namespace Hbdev\HbdevLegalText;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Doctrine\DBAL\Connection;
use Hbdev\HbdevLegalText\Traits\ConfiguredLayoutsTrait;
class HbdevLegalText extends Plugin
{
use ConfiguredLayoutsTrait;
public function uninstall(UninstallContext $context): void
{
$connection = $this->container->get(Connection::class);
$configuredLayouts = $this->getConfiguredLayouts($connection);
// delete hbdev_config (config table)
$connection->executeUpdate('
TRUNCATE TABLE `hbdev_config`;
');
if (count($configuredLayouts) === 0) {
$hbdevLayouts = $this->getHbdevLayouts($connection);
// Delete HB layouts in shopware
$this->deleteHbdevLayouts($connection, $hbdevLayouts);
// delete hbdev_layout (helper table)
$connection->executeUpdate('
TRUNCATE TABLE `hbdev_layout`;
');
}
}
/**
* Delete all HB layouts
*
* @param $connection
* @return void
*/
private function deleteHbdevLayouts($connection, $layouts)
{
foreach ($layouts as $layout) {
$connection->delete('cms_page', ['id' => $layout['cms_page_id']]);
}
}
}