<?php
declare(strict_types=1);
/*
* Copyright (C) web fabric gmbh - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* Written by Dominik Mank <entwicklung@web-fabric.de>, December 2020
*/
namespace BucsItTimeline;
use BucsItTimeline\DependencyInjection\Compiler\CustomerTimelineEntriesLoaderPass;
use BucsItTimeline\DependencyInjection\Compiler\OrderTimelineEntriesLoaderPass;
use BucsItTimeline\Service\Loader\CustomerTimelineEntryLoaderInterface;
use BucsItTimeline\Service\Loader\OrderTimelineEntryLoaderInterface;
use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\Framework\Plugin\Context\UpdateContext;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class BucsItTimeline extends Plugin
{
public function install(InstallContext $installContext): void
{
$this->installOrUpdate($installContext);
}
public function update(UpdateContext $updateContext): void
{
$this->installOrUpdate($updateContext);
}
//this will be the way to go with shopware >= 6.3.5.0
public function enrichPrivileges(): array
{
return [
'product.viewer' => [
'bucs_timeline_comment:read',
'bucs_timeline_comment:create',
'bucs_timeline_comment:update',
'bucs_timeline_comment:delete',
],
'order.viewer' => [
'bucs_timeline_comment:read',
'bucs_timeline_comment:create',
'bucs_timeline_comment:update',
'bucs_timeline_comment:delete',
]
];
}
private function installOrUpdate(InstallContext $context): void
{
}
public function build(ContainerBuilder $container): void
{
parent::build($container);
$container->addCompilerPass(new CustomerTimelineEntriesLoaderPass());
$container->addCompilerPass(new OrderTimelineEntriesLoaderPass());
$container->registerForAutoconfiguration(OrderTimelineEntryLoaderInterface::class)
->addTag('bucs.timeline.order.entry_loader');
$container->registerForAutoconfiguration(CustomerTimelineEntryLoaderInterface::class)
->addTag('bucs.timeline.customer.entry_loader');
}
public function uninstall(UninstallContext $uninstallContext): void
{
if ($uninstallContext->keepUserData()) {
parent::uninstall($uninstallContext);
return;
}
/** @var Connection $connection */
$connection = $this->container->get(Connection::class);
$connection->beginTransaction();
try {
$connection->executeStatement('DROP TABLE bucs_timeline_comment;');
$connection->executeStatement('DROP TABLE bucs_timeline_custom;');
$connection->executeStatement('DELETE FROM mail_template_type where technical_name in("comment.order.mail.template.type", "comment.customer.mail.template.type")');
$connection->commit();
} catch (\Exception $e) {
$connection->rollBack();
}
}
}