custom/plugins/BucsItTimeline/src/BucsItTimeline.php line 24

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * Copyright (C) web fabric gmbh - All Rights Reserved
  5.  * Unauthorized copying of this file, via any medium is strictly prohibited
  6.  * Proprietary and confidential
  7.  * Written by Dominik Mank <entwicklung@web-fabric.de>, December 2020
  8.  */
  9. namespace BucsItTimeline;
  10. use BucsItTimeline\DependencyInjection\Compiler\CustomerTimelineEntriesLoaderPass;
  11. use BucsItTimeline\DependencyInjection\Compiler\OrderTimelineEntriesLoaderPass;
  12. use BucsItTimeline\Service\Loader\CustomerTimelineEntryLoaderInterface;
  13. use BucsItTimeline\Service\Loader\OrderTimelineEntryLoaderInterface;
  14. use Doctrine\DBAL\Connection;
  15. use Shopware\Core\Framework\Plugin;
  16. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  17. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  18. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  19. use Symfony\Component\DependencyInjection\ContainerBuilder;
  20. class BucsItTimeline extends Plugin
  21. {
  22.     public function install(InstallContext $installContext): void
  23.     {
  24.         $this->installOrUpdate($installContext);
  25.     }
  26.     public function update(UpdateContext $updateContext): void
  27.     {
  28.         $this->installOrUpdate($updateContext);
  29.     }
  30.     //this will be the way to go with shopware >= 6.3.5.0
  31.     public function enrichPrivileges(): array
  32.     {
  33.         return [
  34.             'product.viewer' => [
  35.                 'bucs_timeline_comment:read',
  36.                 'bucs_timeline_comment:create',
  37.                 'bucs_timeline_comment:update',
  38.                 'bucs_timeline_comment:delete',
  39.             ],
  40.             'order.viewer' => [
  41.                 'bucs_timeline_comment:read',
  42.                 'bucs_timeline_comment:create',
  43.                 'bucs_timeline_comment:update',
  44.                 'bucs_timeline_comment:delete',
  45.             ]
  46.         ];
  47.     }
  48.     private function installOrUpdate(InstallContext $context): void
  49.     {
  50.     }
  51.     public function build(ContainerBuilder $container): void
  52.     {
  53.         parent::build($container);
  54.         $container->addCompilerPass(new CustomerTimelineEntriesLoaderPass());
  55.         $container->addCompilerPass(new OrderTimelineEntriesLoaderPass());
  56.         $container->registerForAutoconfiguration(OrderTimelineEntryLoaderInterface::class)
  57.             ->addTag('bucs.timeline.order.entry_loader');
  58.         $container->registerForAutoconfiguration(CustomerTimelineEntryLoaderInterface::class)
  59.             ->addTag('bucs.timeline.customer.entry_loader');
  60.     }
  61.     public function uninstall(UninstallContext $uninstallContext): void
  62.     {
  63.         if ($uninstallContext->keepUserData()) {
  64.             parent::uninstall($uninstallContext);
  65.             return;
  66.         }
  67.         /** @var Connection $connection */
  68.         $connection $this->container->get(Connection::class);
  69.         $connection->beginTransaction();
  70.         try {
  71.             $connection->executeStatement('DROP TABLE bucs_timeline_comment;');
  72.             $connection->executeStatement('DROP TABLE bucs_timeline_custom;');
  73.             $connection->executeStatement('DELETE FROM mail_template_type where technical_name in("comment.order.mail.template.type", "comment.customer.mail.template.type")');
  74.             $connection->commit();
  75.         } catch (\Exception $e) {
  76.             $connection->rollBack();
  77.         }
  78.     }
  79. }