<?php
declare(strict_types=1);
/**
* PremSoft
* Copyright © 2020 Premsoft - Sven Mittreiter
*
* @copyright Copyright (c) 2020, premsoft - Sven Mittreiter (http://www.premsoft.de)
* @author Sven Mittreiter <info@premsoft.de>
*/
namespace Wbfk\Offer;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
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 Wbfk\Offer\Lifecycle\DocumentsLifecycle;
use Wbfk\Offer\Lifecycle\MailLifecycle;
class WbfkOffer extends Plugin
{
public const EVENT_OFFER_REQUESTED = 'wbfk.offer.requested';
public function install(InstallContext $installContext): void
{
/** @var EntityRepository $flowRepository */
/*
$flowRepository = $this->container->get('flow.repository');
$flowRepository->create([
[
'id' => $this->ids->create('flow_id'),
'name' => 'Create Offer',
'eventName' => self::EVENT_OFFER_REQUESTED,
'priority' => 1,
'active' => true,
'payload' => null,
'invalid' => true,
'sequences' => [
[
'id' => $this->ids->create('flow_sequence_id'),
'parentId' => null,
'ruleId' => $this->ids->create('rule_id'),
'actionName' => null,
'config' => [],
'position' => 1,
'rule' => [
'id' => $this->ids->get('rule_id'),
'name' => 'Test rule',
'priority' => 1,
'conditions' => [
['type' => (new AlwaysValidRule())->getName()],
],
],
],
[
'id' => $this->ids->create('flow_sequence_id1'),
'parentId' => $this->ids->get('flow_sequence_id'),
'ruleId' => null,
'actionName' => AddOrderTagAction::getName(),
'config' => [
'tagId' => $this->ids->get('tag_id'),
'entity' => OrderDefinition::ENTITY_NAME,
],
'position' => 1,
'trueCase' => true,
],
[
'id' => $this->ids->create('flow_sequence_id2'),
'parentId' => $this->ids->get('flow_sequence_id'),
'ruleId' => null,
'actionName' => AddOrderTagAction::getName(),
'config' => [
'tagId' => $this->ids->get('tag_id2'),
'entity' => OrderDefinition::ENTITY_NAME,
],
'position' => 2,
'trueCase' => true,
],
],
]
], Context::createDefaultContext());
/**/
parent::install($installContext);
}
public function update(UpdateContext $updateContext): void
{
parent::update($updateContext);
}
/**
* @throws Exception
*/
public function uninstall(UninstallContext $uninstallContext): void
{
if ($uninstallContext->keepUserData()) {
parent::uninstall($uninstallContext);
return;
}
/** @var Connection $connection */
$connection = $this->container->get(Connection::class);
$docLifecycle = new DocumentsLifecycle($connection);
$docLifecycle->delete();
$mailLifecycle = new MailLifecycle($connection);
$mailLifecycle->delete();
$connection->executeStatement(
<<<SQL
DROP TABLE IF EXISTS `wbfk_offer_document`;
DROP TABLE IF EXISTS `wbfk_offer_item`;
DROP TABLE IF EXISTS `wbfk_offer_tag`;
DROP TABLE IF EXISTS `wbfk_offer`;
SQL
);
parent::uninstall($uninstallContext);
}
}