Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WorkflowBundle] refactor state change logging #835

Merged
merged 4 commits into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG-2.0.x.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Within V2

## 2.0.5:
- Deprecations:
- [WorkflowBundle] refactor state change logging (https://github.com/coreshop/CoreShop/pull/835)
- `CoreShop\Bundle\OrderBundle\Workflow\OrderHistoryLogger` has been deprecated, use `CoreShop\Bundle\WorkflowBundle\History\HistoryLoggerInterface` instead
- `CoreShop\Bundle\OrderBundle\Workflow\OrderStateHistoryLogger` has been deprecated, use `CoreShop\Bundle\WorkflowBundle\History\StateHistoryLoggerInterface` instead
- `CoreShop\Bundle\OrderBundle\Workflow\WorkflowStateManager` has been deprecated, use `CoreShop\Bundle\WorkflowBundle\StateManager\WorkflowStateInfoManagerInterface` instead

## 2.0.4
- Features:
- [Reports] Reports Grid Sorting (https://github.com/coreshop/CoreShop/pull/828)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace CoreShop\Bundle\CoreBundle\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Pimcore\Migrations\Migration\AbstractPimcoreMigration;

class Version20190225140315 extends AbstractPimcoreMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
$this->addSql('UPDATE notes SET type="history_state_change" WHERE type="order_state_change"');

}

/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use Carbon\Carbon;
use CoreShop\Bundle\WorkflowBundle\Manager\StateMachineManager;
use CoreShop\Bundle\WorkflowBundle\StateManager\WorkflowStateInfoManagerInterface;
use CoreShop\Component\Order\Model\OrderInterface;
use CoreShop\Component\Order\Model\SaleInterface;
use CoreShop\Component\Order\OrderStates;
Expand Down Expand Up @@ -399,11 +400,11 @@ private function getOrderShipmentRepository()
}

/**
* @return WorkflowStateManagerInterface
* @return WorkflowStateInfoManagerInterface
*/
private function getWorkflowStateManager()
{
return $this->get('coreshop.workflow.state_manager');
return $this->get('coreshop.workflow.state_info_manager');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@
namespace CoreShop\Bundle\OrderBundle\Pimcore\GridColumnConfig\Operator\Factory;

use CoreShop\Bundle\OrderBundle\Pimcore\GridColumnConfig\Operator\OrderState;
use CoreShop\Component\Order\Workflow\WorkflowStateManagerInterface;
use CoreShop\Bundle\WorkflowBundle\StateManager\WorkflowStateInfoManagerInterface;
use Pimcore\DataObject\GridColumnConfig\Operator\Factory\OperatorFactoryInterface;
use Pimcore\DataObject\GridColumnConfig\Operator\OperatorInterface;

class OrderStateFactory implements OperatorFactoryInterface
{
/**
* @var WorkflowStateManagerInterface
* @var WorkflowStateInfoManagerInterface
*/
private $workflowManager;

/**
* @param WorkflowStateManagerInterface $workflowManager
* @param WorkflowStateInfoManagerInterface $workflowManager
*/
public function __construct(WorkflowStateManagerInterface $workflowManager)
public function __construct(WorkflowStateInfoManagerInterface $workflowManager)
{
$this->workflowManager = $workflowManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace CoreShop\Bundle\OrderBundle\Pimcore\GridColumnConfig\Operator;

use CoreShop\Component\Order\Workflow\WorkflowStateManagerInterface;
use CoreShop\Bundle\WorkflowBundle\StateManager\WorkflowStateInfoManagerInterface;
use Pimcore\DataObject\GridColumnConfig\Operator\AbstractOperator;

class OrderState extends AbstractOperator
Expand All @@ -23,16 +23,16 @@ class OrderState extends AbstractOperator
private $highlightLabel = false;

/**
* @var WorkflowStateManagerInterface
* @var WorkflowStateInfoManagerInterface
*/
private $workflowManager;

/**
* @param WorkflowStateManagerInterface $workflowManager
* @param WorkflowStateInfoManagerInterface $workflowManager
* @param \stdClass $config
* @param null $context
*/
public function __construct(WorkflowStateManagerInterface $workflowManager, \stdClass $config, $context = null)
public function __construct(WorkflowStateInfoManagerInterface $workflowManager, \stdClass $config, $context = null)
{
parent::__construct($config, $context);
$this->workflowManager = $workflowManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
coreshop.data_object.grid_column_config.operator.factory.order_state:
class: CoreShop\Bundle\OrderBundle\Pimcore\GridColumnConfig\Operator\Factory\OrderStateFactory
arguments:
- '@coreshop.workflow.state_manager'
- '@coreshop.workflow.state_info_manager'
tags:
- { name: pimcore.data_object.grid_column_config.operator_factory, id: coreshop_order_state }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ services:

coreshop.templating.helper.order_state:
class: CoreShop\Bundle\OrderBundle\Templating\Helper\OrderStateHelper
arguments: ['@coreshop.workflow.state_manager']
arguments: ['@coreshop.workflow.state_info_manager']
tags:
- { name: templating.helper, alias: coreshop_order_state }

coreshop.twig.extension.order_state:
class: CoreShop\Bundle\OrderBundle\Twig\OrderStateExtension
arguments: ['@coreshop.templating.helper.order_state']
tags:
- { name: twig.extension }
- { name: twig.extension }
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ parameters:
_defaults:
public: true

coreshop.workflow.manager.order.history_log_state_identifier: !php/const CoreShop\Component\Order\Notes::ORDER_HISTORY_STATE_LOG
coreshop.workflow.include_invoice_state_to_complete_order: false

services:
Expand Down Expand Up @@ -100,24 +99,15 @@ services:
coreshop.workflow.state_manager:
class: CoreShop\Bundle\OrderBundle\Workflow\WorkflowStateManager
arguments:
- '@event_dispatcher'
- '@coreshop.state_machine_manager'
- '@pimcore.translator'
- '%coreshop.workflow.manager.order.history_log_state_identifier%'
- '%coreshop.state_machine.colors%'
- '@coreshop.workflow.state_info_manager'

coreshop.workflow.order_history_logger:
class: CoreShop\Bundle\OrderBundle\Workflow\OrderHistoryLogger
arguments:
- '@coreshop.repository.order'
- '@coreshop.object_note_service'
- '@pimcore.translator'
- '%coreshop.workflow.manager.order.history_log_state_identifier%'
- '@coreshop.workflow.history_logger'

coreshop.workflow.order_state_history_logger:
class: CoreShop\Bundle\OrderBundle\Workflow\OrderStateHistoryLogger
arguments:
- '@coreshop.state_machine_manager'
- '@coreshop.object_note_service'
- '@pimcore.translator'
- '%coreshop.workflow.manager.order.history_log_state_identifier%'
- '@coreshop.workflow.state_history_logger'
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ coreshop_workflow_transition_coreshop_shipment_cancel: 'Stornieren'
coreshop_workflow_transition_coreshop_invoice_create: 'Erstellen'
coreshop_workflow_transition_coreshop_invoice_complete: 'Abschließen'
coreshop_workflow_transition_coreshop_invoice_cancel: 'Stornieren'
coreshop_workflow_order_history_logger_prefix: 'Log'
coreshop_discount: 'Rabatt (inkl. Mwst.)'
coreshop_discount_tax: 'Rabatt Mwst.'
coreshop_discount_without_tax: 'Rabatt (exkl. Mwst.)'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ coreshop_workflow_transition_coreshop_shipment_cancel: 'Cancel'
coreshop_workflow_transition_coreshop_invoice_create: 'Create'
coreshop_workflow_transition_coreshop_invoice_complete: 'Complete'
coreshop_workflow_transition_coreshop_invoice_cancel: 'Cancel'
coreshop_workflow_order_history_logger_prefix: 'Log'
coreshop_discount: 'Discount (incl. Tax)'
coreshop_discount_tax: 'Discount Tax'
coreshop_discount_without_tax: 'Discount (excl. Tax.)'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@

namespace CoreShop\Bundle\OrderBundle\Templating\Helper;

use CoreShop\Bundle\WorkflowBundle\StateManager\WorkflowStateInfoManagerInterface;
use CoreShop\Component\Order\Model\OrderInterface;
use CoreShop\Component\Order\OrderPaymentStates;
use CoreShop\Component\Order\OrderShipmentStates;
use CoreShop\Component\Order\OrderStates;
use CoreShop\Component\Order\Workflow\WorkflowStateManagerInterface;
use Symfony\Component\Templating\Helper\Helper;

class OrderStateHelper extends Helper implements OrderStateHelperInterface
{
/**
* @var WorkflowStateManagerInterface
* @var WorkflowStateInfoManagerInterface
*/
private $workflowStateManager;

/**
* @param WorkflowStateManagerInterface $workflowStateManager
* @param WorkflowStateInfoManagerInterface $workflowStateManager
*/
public function __construct(WorkflowStateManagerInterface $workflowStateManager)
public function __construct(WorkflowStateInfoManagerInterface $workflowStateManager)
{
$this->workflowStateManager = $workflowStateManager;
}
Expand Down
58 changes: 20 additions & 38 deletions src/CoreShop/Bundle/OrderBundle/Workflow/OrderHistoryLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@

namespace CoreShop\Bundle\OrderBundle\Workflow;

use CoreShop\Bundle\WorkflowBundle\History\HistoryLoggerInterface;
use CoreShop\Component\Order\Model\OrderInterface;
use CoreShop\Component\Order\Repository\OrderRepositoryInterface;
use CoreShop\Component\Pimcore\DataObject\NoteServiceInterface;
use Symfony\Component\Translation\TranslatorInterface;

/**
* @deprecated Class CoreShop\Bundle\OrderBundle\Workflow\OrderHistoryLogger is deprecated and will be removed with 2.1, use CoreShop\Bundle\WorkflowBundle\History\HistoryLoggerInterface instead
*/
final class OrderHistoryLogger
{
/**
Expand All @@ -25,36 +27,20 @@ final class OrderHistoryLogger
private $orderRepository;

/**
* @var NoteServiceInterface
*/
private $noteService;

/**
* @var TranslatorInterface
*/
private $translator;

/**
* @var string
* @var HistoryLoggerInterface
*/
private $noteIdentifier;
private $historyLogger;

/**
* @param OrderRepositoryInterface $orderRepository
* @param NoteServiceInterface $noteService
* @param TranslatorInterface $translator
* @param string $noteIdentifier
* @param HistoryLoggerInterface $historyLogger
*/
public function __construct(
OrderRepositoryInterface $orderRepository,
NoteServiceInterface $noteService,
TranslatorInterface $translator,
$noteIdentifier
HistoryLoggerInterface $historyLogger
) {
$this->orderRepository = $orderRepository;
$this->noteService = $noteService;
$this->translator = $translator;
$this->noteIdentifier = $noteIdentifier;
$this->historyLogger = $historyLogger;
}

/**
Expand All @@ -65,25 +51,21 @@ public function __construct(
*/
public function log($orderId = null, $message = null, $description = null, $translate = false)
{
trigger_error(
sprintf('%s::%s is deprecated and will be removed with 2.1, please use %s:%s instead.',
static::class,
__METHOD__,
HistoryLoggerInterface::class,
__METHOD__
),
E_USER_DEPRECATED
);

$order = $this->orderRepository->find($orderId);
if (!$order instanceof OrderInterface) {
return;
}

$note = $this->noteService->createPimcoreNoteInstance($order, $this->noteIdentifier);

$message = strip_tags($message);

if ($translate === true) {
$message = $this->translator->trans($message, [], 'admin');
}

$note->setTitle($this->translator->trans('coreshop_workflow_order_history_logger_prefix', [], 'admin') . ': ' . $message);

if (!is_null($description)) {
$note->setDescription($description);
}

$this->noteService->storeNote($note);
$this->historyLogger->log($order, $message, $description, $translate);
}
}
Loading