<?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
{
parent::uninstall($context);
if ($context->keepUserData()) {
return;
}
$connection = $this->container->get(Connection::class);
$configuredLayouts = $this->getConfiguredLayouts($connection);
$unassignedLayouts = $this->getUnassignedLayouts($connection);
// delete hbdev_config (config table)
$connection->executeUpdate('
DROP TABLE `hbdev_config`;
');
// Delete unassigned HB layouts in shopware
$this->deleteHbdevLayouts($connection, $unassignedLayouts);
if (count($configuredLayouts) === 0) {
// delete hbdev_layout (helper table)
$connection->executeUpdate('
DROP TABLE `hbdev_layout`;
');
}
}
/**
* Delete all HB layouts
*
* @param $connection
* @param $layouts
* @return void
*/
private function deleteHbdevLayouts($connection, $layouts)
{
foreach ($layouts as $layout) {
$connection->delete('cms_page', ['id' => $layout]);
$connection->delete('hbdev_layout', ['cms_page_id' => $layout]);
}
}
}