ltsecurityinc安防产品在线商城代码
This commit is contained in:
+103
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\LoggingActionInterface;
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\ActionType;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
|
||||
class ActionFactory
|
||||
{
|
||||
/**
|
||||
* Handler fetch strategies.
|
||||
*/
|
||||
public const FETCH_ONE = 1;
|
||||
public const FETCH_ANY = 2;
|
||||
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var ActionType\CompositeFactory
|
||||
*/
|
||||
private $compositeFactory;
|
||||
|
||||
/**
|
||||
* @var ActionType\HandlerResolver
|
||||
*/
|
||||
private $actionHandlerResolver;
|
||||
|
||||
/**
|
||||
* @var ActionType\ValidationCompositeFactory
|
||||
*/
|
||||
private $validationCompositeFactory;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $dummyHandlerClass;
|
||||
|
||||
public function __construct(
|
||||
ObjectManagerInterface $objectManager,
|
||||
ActionType\CompositeFactory $compositeFactory,
|
||||
ActionType\HandlerResolver $actionHandlerResolver,
|
||||
ActionType\ValidationCompositeFactory $validationCompositeFactory,
|
||||
string $dummyHandlerClass = ActionType\Dummy::class
|
||||
) {
|
||||
$this->objectManager = $objectManager;
|
||||
$this->compositeFactory = $compositeFactory;
|
||||
$this->actionHandlerResolver = $actionHandlerResolver;
|
||||
$this->validationCompositeFactory = $validationCompositeFactory;
|
||||
$this->dummyHandlerClass = $dummyHandlerClass;
|
||||
}
|
||||
|
||||
public function create(MetadataInterface $metadata, int $fetchStrategy = self::FETCH_ONE): LoggingActionInterface
|
||||
{
|
||||
$loggingActions = [];
|
||||
$actionName = $metadata->getRequest()->getFullActionName();
|
||||
$handlerClasses = $this->actionHandlerResolver->getHandlers($actionName, $metadata->getEventName());
|
||||
|
||||
switch ($fetchStrategy) {
|
||||
case self::FETCH_ONE:
|
||||
$handlerClasses = [$handlerClasses[0] ?? $this->dummyHandlerClass];
|
||||
break;
|
||||
default:
|
||||
$handlerClasses = !empty($handlerClasses) ? $handlerClasses : [$this->dummyHandlerClass];
|
||||
}
|
||||
|
||||
foreach ($handlerClasses as $handlerClass) {
|
||||
$loggingActions[] = $this->initializeLoggingAction($handlerClass, $metadata);
|
||||
}
|
||||
|
||||
return $this->compositeFactory->create(['actions' => $loggingActions]);
|
||||
}
|
||||
|
||||
private function initializeLoggingAction(string $class, MetadataInterface $metadata): LoggingActionInterface
|
||||
{
|
||||
$action = $this->objectManager->create($class, ['metadata' => $metadata]);
|
||||
$eventName = $metadata->getEventName();
|
||||
$actionName = $metadata->getRequest()->getFullActionName();
|
||||
$validators = $this->actionHandlerResolver->getValidators($actionName, $eventName, $class);
|
||||
|
||||
if ($validators) {
|
||||
return $this->validationCompositeFactory->create([
|
||||
'metadata' => $metadata,
|
||||
'wrappedAction' => $action,
|
||||
'validators' => $validators
|
||||
]);
|
||||
}
|
||||
|
||||
return $action;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\ActionType\AfterSave;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\LogEntryRepositoryInterface;
|
||||
use Amasty\AdminActionsLog\Api\Logging\LoggingActionInterface;
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Api\Logging\ObjectDataStorageInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandlerProvider;
|
||||
use Amasty\AdminActionsLog\Logging\Util\DetailsBuilder;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry;
|
||||
use Amasty\AdminActionsLog\Model\OptionSource\LogEntryTypes;
|
||||
use Amasty\AdminActionsLog\Restoring\Entity\RestoreHandler\AbstractHandler;
|
||||
|
||||
class Entity implements LoggingActionInterface
|
||||
{
|
||||
/**
|
||||
* @var MetadataInterface
|
||||
*/
|
||||
private $metadata;
|
||||
|
||||
/**
|
||||
* @var DetailsBuilder
|
||||
*/
|
||||
private $detailsBuilder;
|
||||
|
||||
/**
|
||||
* @var SaveHandlerProvider
|
||||
*/
|
||||
private $entityTypeProvider;
|
||||
|
||||
/**
|
||||
* @var ObjectDataStorageInterface
|
||||
*/
|
||||
private $dataStorage;
|
||||
|
||||
/**
|
||||
* @var LogEntryRepositoryInterface
|
||||
*/
|
||||
private $logEntryRepository;
|
||||
|
||||
/**
|
||||
* @var LogEntry\AdminLogEntryFactory
|
||||
*/
|
||||
private $logEntryFactory;
|
||||
|
||||
public function __construct(
|
||||
MetadataInterface $metadata,
|
||||
DetailsBuilder $detailsBuilder,
|
||||
SaveHandlerProvider $entityTypeProvider,
|
||||
ObjectDataStorageInterface $dataStorage,
|
||||
LogEntryRepositoryInterface $logEntryRepository,
|
||||
LogEntry\AdminLogEntryFactory $logEntryFactory
|
||||
) {
|
||||
$this->metadata = $metadata;
|
||||
$this->detailsBuilder = $detailsBuilder;
|
||||
$this->entityTypeProvider = $entityTypeProvider;
|
||||
$this->dataStorage = $dataStorage;
|
||||
$this->logEntryRepository = $logEntryRepository;
|
||||
$this->logEntryFactory = $logEntryFactory;
|
||||
}
|
||||
|
||||
public function execute(): void
|
||||
{
|
||||
if ($loggingObject = $this->metadata->getObject()) {
|
||||
// storageEntityKey could be set while executing entities by schedule.
|
||||
$storageKey = $this->metadata->getStorageEntityKey() ?? spl_object_id($loggingObject) . '.before';
|
||||
$entityLogType = $this->entityTypeProvider->get(get_class($loggingObject));
|
||||
$beforeData = $this->dataStorage->get($storageKey) ?? [];
|
||||
$afterData = $entityLogType->processAfterSave($loggingObject);
|
||||
$detailsList = $this->detailsBuilder->build(get_class($loggingObject), $beforeData, $afterData);
|
||||
|
||||
if (!empty($detailsList)) {
|
||||
$logEntry = $this->logEntryFactory->create($this->prepareLogEntryData($loggingObject));
|
||||
$logEntry->setLogDetails($detailsList);
|
||||
$this->logEntryRepository->save($logEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function prepareLogEntryData($object): array
|
||||
{
|
||||
$entityLogType = $this->entityTypeProvider->get(get_class($object));
|
||||
$defaultCategory = sprintf(
|
||||
'%s/%s',
|
||||
$this->metadata->getRequest()->getModuleName(),
|
||||
$this->metadata->getRequest()->getControllerName()
|
||||
);
|
||||
|
||||
switch (true) {
|
||||
case (bool)$object->isObjectNew():
|
||||
$actionType = LogEntryTypes::TYPE_NEW;
|
||||
break;
|
||||
default:
|
||||
$actionType = LogEntryTypes::TYPE_EDIT;
|
||||
}
|
||||
|
||||
$logEntryData = array_merge(
|
||||
[
|
||||
LogEntry\LogEntry::TYPE => $actionType,
|
||||
LogEntry\LogEntry::CATEGORY => $defaultCategory,
|
||||
LogEntry\LogEntry::CATEGORY_NAME => $defaultCategory,
|
||||
],
|
||||
$entityLogType->getLogMetadata($this->metadata)
|
||||
);
|
||||
|
||||
$storageKey = spl_object_id($object) . '.' . AbstractHandler::STORAGE_CODE_PREFIX;
|
||||
if ($this->dataStorage->isExists($storageKey)) {
|
||||
$logEntryData[LogEntry\LogEntry::TYPE] = LogEntryTypes::TYPE_RESTORE;
|
||||
}
|
||||
|
||||
return $logEntryData;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\ActionType\BeforeSave;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\LoggingActionInterface;
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Api\Logging\ObjectDataStorageInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandlerProvider;
|
||||
|
||||
class Entity implements LoggingActionInterface
|
||||
{
|
||||
/**
|
||||
* @var MetadataInterface
|
||||
*/
|
||||
private $metadata;
|
||||
|
||||
/**
|
||||
* @var SaveHandlerProvider
|
||||
*/
|
||||
private $entityTypeProvider;
|
||||
|
||||
/**
|
||||
* @var ObjectDataStorageInterface
|
||||
*/
|
||||
private $dataStorage;
|
||||
|
||||
public function __construct(
|
||||
MetadataInterface $metadata,
|
||||
SaveHandlerProvider $entityTypeProvider,
|
||||
ObjectDataStorageInterface $dataStorage
|
||||
) {
|
||||
$this->metadata = $metadata;
|
||||
$this->entityTypeProvider = $entityTypeProvider;
|
||||
$this->dataStorage = $dataStorage;
|
||||
}
|
||||
|
||||
public function execute(): void
|
||||
{
|
||||
if ($loggingObject = $this->metadata->getObject()) {
|
||||
$storageKey = $this->metadata->getStorageEntityKey() ?? spl_object_id($loggingObject) . '.before';
|
||||
if ($this->dataStorage->isExists($storageKey)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$entityLogType = $this->entityTypeProvider->get(get_class($loggingObject));
|
||||
if ($beforeData = $entityLogType->processBeforeSave($loggingObject)) {
|
||||
$this->dataStorage->set($storageKey, $beforeData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\ActionType;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\LoggingActionInterface;
|
||||
use Magento\Framework\Profiler;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Composite implements LoggingActionInterface
|
||||
{
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* @var LoggingActionInterface[]
|
||||
*/
|
||||
private $actions;
|
||||
|
||||
public function __construct(
|
||||
LoggerInterface $logger,
|
||||
array $actions = []
|
||||
) {
|
||||
foreach ($actions as $action) {
|
||||
if (!$action instanceof LoggingActionInterface) {
|
||||
throw new \LogicException(
|
||||
sprintf('Action handler must implement %s', LoggingActionInterface::class)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->logger = $logger;
|
||||
$this->actions = $actions;
|
||||
}
|
||||
|
||||
public function execute(): void
|
||||
{
|
||||
foreach ($this->actions as $action) {
|
||||
try {
|
||||
$actionTimerName = sprintf('__ACTION_LOG_RUN_%s__', get_class($action));
|
||||
Profiler::start($actionTimerName);
|
||||
$action->execute();
|
||||
Profiler::stop($actionTimerName);
|
||||
} catch (\Throwable $e) {
|
||||
$this->logger->error(
|
||||
__('An error occurred during Logging Action execution. Error is %1', $e->getMessage())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\ActionType\Delete;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\LoggingActionInterface;
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Api\Logging\ObjectDataStorageInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandlerProvider;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry;
|
||||
use Amasty\AdminActionsLog\Model\OptionSource\LogEntryTypes;
|
||||
|
||||
class Entity implements LoggingActionInterface
|
||||
{
|
||||
public const DELETE_LOG_ENTRY_POSTFIX = '.delete_log_entry';
|
||||
|
||||
/**
|
||||
* @var MetadataInterface
|
||||
*/
|
||||
private $metadata;
|
||||
|
||||
/**
|
||||
* @var SaveHandlerProvider
|
||||
*/
|
||||
private $entityTypeProvider;
|
||||
|
||||
/**
|
||||
* @var ObjectDataStorageInterface
|
||||
*/
|
||||
private $dataStorage;
|
||||
|
||||
/**
|
||||
* @var LogEntry\AdminLogEntryFactory
|
||||
*/
|
||||
private $logEntryFactory;
|
||||
|
||||
public function __construct(
|
||||
MetadataInterface $metadata,
|
||||
SaveHandlerProvider $entityTypeProvider,
|
||||
ObjectDataStorageInterface $dataStorage,
|
||||
LogEntry\AdminLogEntryFactory $logEntryFactory
|
||||
) {
|
||||
$this->metadata = $metadata;
|
||||
$this->entityTypeProvider = $entityTypeProvider;
|
||||
$this->dataStorage = $dataStorage;
|
||||
$this->logEntryFactory = $logEntryFactory;
|
||||
}
|
||||
|
||||
public function execute(): void
|
||||
{
|
||||
if ($deletedObject = $this->metadata->getObject()) {
|
||||
$entityLogType = $this->entityTypeProvider->get(get_class($deletedObject));
|
||||
$category = sprintf(
|
||||
'%s/%s',
|
||||
$this->metadata->getRequest()->getModuleName(),
|
||||
$this->metadata->getRequest()->getControllerName()
|
||||
);
|
||||
|
||||
$lodEntryData = array_merge(
|
||||
[LogEntry\LogEntry::CATEGORY_NAME => $category],
|
||||
$entityLogType->getLogMetadata($this->metadata),
|
||||
[
|
||||
LogEntry\LogEntry::CATEGORY => $category,
|
||||
LogEntry\LogEntry::TYPE => LogEntryTypes::TYPE_DELETE,
|
||||
LogEntry\LogEntry::STORE_ID => 0
|
||||
]
|
||||
);
|
||||
$logEntry = $this->logEntryFactory->create($lodEntryData);
|
||||
$storageKey = spl_object_id($deletedObject) . self::DELETE_LOG_ENTRY_POSTFIX;
|
||||
$this->dataStorage->set($storageKey, ['log' => $logEntry]);
|
||||
}
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\ActionType\Dispatch;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\ActiveSessionManagerInterface;
|
||||
use Amasty\AdminActionsLog\Api\Logging\LoggingActionInterface;
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Api\LoginAttemptManagerInterface;
|
||||
use Amasty\AdminActionsLog\Api\VisitHistoryManagerInterface;
|
||||
use Amasty\AdminActionsLog\Model\OptionSource\LoginAttemptStatus;
|
||||
|
||||
class AdminSession implements LoggingActionInterface
|
||||
{
|
||||
public const LOGOUT_ACTION = 'logout';
|
||||
|
||||
/**
|
||||
* @var MetadataInterface
|
||||
*/
|
||||
private $metadata;
|
||||
|
||||
/**
|
||||
* @var ActiveSessionManagerInterface
|
||||
*/
|
||||
private $activeSessionManager;
|
||||
|
||||
/**
|
||||
* @var VisitHistoryManagerInterface
|
||||
*/
|
||||
private $visitHistoryManager;
|
||||
|
||||
/**
|
||||
* @var LoginAttemptManagerInterface
|
||||
*/
|
||||
private $loginAttemptManager;
|
||||
|
||||
public function __construct(
|
||||
MetadataInterface $metadata,
|
||||
ActiveSessionManagerInterface $activeSessionManager,
|
||||
VisitHistoryManagerInterface $visitHistoryManager,
|
||||
LoginAttemptManagerInterface $loginAttemptManager
|
||||
) {
|
||||
$this->metadata = $metadata;
|
||||
$this->activeSessionManager = $activeSessionManager;
|
||||
$this->visitHistoryManager = $visitHistoryManager;
|
||||
$this->loginAttemptManager = $loginAttemptManager;
|
||||
}
|
||||
|
||||
public function execute(): void
|
||||
{
|
||||
if ($this->metadata->getRequest()->getActionName() === self::LOGOUT_ACTION) {
|
||||
$this->activeSessionManager->terminate();
|
||||
$this->visitHistoryManager->endVisit();
|
||||
$this->loginAttemptManager->saveAttempt(null, LoginAttemptStatus::LOGOUT);
|
||||
} elseif (!$this->metadata->getRequest()->isAjax()) {
|
||||
$this->activeSessionManager->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\ActionType\Dispatch;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\LogEntryRepositoryInterface;
|
||||
use Amasty\AdminActionsLog\Api\Logging\LoggingActionInterface;
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry;
|
||||
use Amasty\AdminActionsLog\Model\OptionSource\LogEntryTypes;
|
||||
|
||||
class Cache implements LoggingActionInterface
|
||||
{
|
||||
/**
|
||||
* @var MetadataInterface
|
||||
*/
|
||||
private $metadata;
|
||||
|
||||
/**
|
||||
* @var LogEntryRepositoryInterface
|
||||
*/
|
||||
private $logEntryRepository;
|
||||
|
||||
/**
|
||||
* @var LogEntry\AdminLogEntryFactory
|
||||
*/
|
||||
private $logEntryFactory;
|
||||
|
||||
public function __construct(
|
||||
MetadataInterface $metadata,
|
||||
LogEntryRepositoryInterface $logEntryRepository,
|
||||
LogEntry\AdminLogEntryFactory $logEntryFactory
|
||||
) {
|
||||
$this->metadata = $metadata;
|
||||
$this->logEntryRepository = $logEntryRepository;
|
||||
$this->logEntryFactory = $logEntryFactory;
|
||||
}
|
||||
|
||||
public function execute(): void
|
||||
{
|
||||
$logEntry = $this->logEntryFactory->create([
|
||||
LogEntry\LogEntry::TYPE => LogEntryTypes::TYPE_CACHE,
|
||||
LogEntry\LogEntry::CATEGORY => __('Cache'),
|
||||
LogEntry\LogEntry::CATEGORY_NAME => __('Cache'),
|
||||
LogEntry\LogEntry::ITEM => $this->actionName2Label($this->metadata->getRequest()->getActionName()),
|
||||
]);
|
||||
$this->logEntryRepository->save($logEntry);
|
||||
}
|
||||
|
||||
private function actionName2Label(string $actionName): string
|
||||
{
|
||||
$actionLabels = [
|
||||
'cleanImages' => __('Flushed image cache'),
|
||||
'cleanMedia' => __('Flushed JavaScript/CSS cache'),
|
||||
'cleanStaticFiles' => __('Flushed static files cache'),
|
||||
'flushAll' => __('Flushed cache storage'),
|
||||
'flushSystem' => __('Flushed Magento cache storage'),
|
||||
'massDisable' => __('Cache disabled'),
|
||||
'massEnable' => __('Cache enabled'),
|
||||
'massRefresh' => __('Cache refreshed')
|
||||
];
|
||||
|
||||
return isset($actionLabels[$actionName]) ? $actionLabels[$actionName]->render() : $actionName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\ActionType\Dispatch;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\LogEntryRepositoryInterface;
|
||||
use Amasty\AdminActionsLog\Api\Logging\LoggingActionInterface;
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry;
|
||||
use Amasty\AdminActionsLog\Model\OptionSource\LogEntryTypes;
|
||||
|
||||
class Export implements LoggingActionInterface
|
||||
{
|
||||
/**
|
||||
* @var MetadataInterface
|
||||
*/
|
||||
private $metadata;
|
||||
|
||||
/**
|
||||
* @var LogEntryRepositoryInterface
|
||||
*/
|
||||
private $logEntryRepository;
|
||||
|
||||
/**
|
||||
* @var LogEntry\AdminLogEntryFactory
|
||||
*/
|
||||
private $logEntryFactory;
|
||||
|
||||
public function __construct(
|
||||
MetadataInterface $metadata,
|
||||
LogEntryRepositoryInterface $logEntryRepository,
|
||||
LogEntry\AdminLogEntryFactory $logEntryFactory
|
||||
) {
|
||||
$this->metadata = $metadata;
|
||||
$this->logEntryRepository = $logEntryRepository;
|
||||
$this->logEntryFactory = $logEntryFactory;
|
||||
}
|
||||
|
||||
public function execute(): void
|
||||
{
|
||||
$category = sprintf(
|
||||
'%s %s',
|
||||
$this->metadata->getRequest()->getModuleName(),
|
||||
$this->metadata->getRequest()->getControllerName()
|
||||
);
|
||||
$logEntry = $this->logEntryFactory->create([
|
||||
LogEntry\LogEntry::TYPE => LogEntryTypes::TYPE_EXPORT,
|
||||
LogEntry\LogEntry::CATEGORY => $category,
|
||||
LogEntry\LogEntry::CATEGORY_NAME => $category,
|
||||
LogEntry\LogEntry::ITEM => __('Data was exported.'),
|
||||
]);
|
||||
$this->logEntryRepository->save($logEntry);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\ActionType;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\LoggingActionInterface;
|
||||
|
||||
class Dummy implements LoggingActionInterface
|
||||
{
|
||||
//phpcs:ignore Magento2.CodeAnalysis.EmptyBlock.DetectedFunction
|
||||
public function execute(): void
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\ActionType;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\LoggingActionInterface;
|
||||
|
||||
class HandlerResolver
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $handlers;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $matched = [];
|
||||
|
||||
public function __construct(array $handlers = [])
|
||||
{
|
||||
foreach ($handlers as $handlerName => $handlerData) {
|
||||
$handlerClass = $handlerData['handlerClass'] ?? null;
|
||||
$config = $handlerData['config'] ?? null;
|
||||
|
||||
if (!is_subclass_of($handlerClass, LoggingActionInterface::class)) {
|
||||
throw new \LogicException(
|
||||
sprintf('ActionType handler "%s" must implement %s', $handlerName, LoggingActionInterface::class)
|
||||
);
|
||||
}
|
||||
|
||||
if (!$config instanceof TypeConfig) {
|
||||
throw new \LogicException(
|
||||
sprintf('ActionType handler config "%s" must be instance of %s', $handlerName, TypeConfig::class)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
usort($handlers, function ($first, $second) {
|
||||
return $first['config']->getPriority() <=> $second['config']->getPriority();
|
||||
});
|
||||
|
||||
$this->handlers = $handlers;
|
||||
}
|
||||
|
||||
public function getHandlers(string $actionName, string $event): array
|
||||
{
|
||||
$this->matchHandlers($actionName, $event);
|
||||
|
||||
return array_map(function ($handlerData) {
|
||||
return $handlerData['class'];
|
||||
}, $this->matched[$actionName][$event]['handlers'] ?? []);
|
||||
}
|
||||
|
||||
public function getValidators(string $actionName, string $event, string $handlerClass): array
|
||||
{
|
||||
$this->matchHandlers($actionName, $event);
|
||||
|
||||
foreach ($this->matched[$actionName][$event]['handlers'] ?? [] as $handlerData) {
|
||||
if ($handlerData['class'] === $handlerClass) {
|
||||
return $handlerData['validators'];
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
private function matchHandlers(string $actionName, string $event): void
|
||||
{
|
||||
if (isset($this->matched[$actionName][$event]['handlers'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->handlers as $handlerData) {
|
||||
/** @var TypeConfig $config */
|
||||
$config = $handlerData['config'];
|
||||
|
||||
if ($config->getEvent() === $event) {
|
||||
foreach ($config->getActions() as $handlerActionRegExp) {
|
||||
if (preg_match("/$handlerActionRegExp/i", $actionName)) {
|
||||
$this->matched[$actionName][$event]['handlers'][] = [
|
||||
'class' => $handlerData['handlerClass'],
|
||||
'validators' => $config->getValidators()
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\ActionType\Login;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\ActiveSessionManagerInterface;
|
||||
use Amasty\AdminActionsLog\Api\Logging\LoggingActionInterface;
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Api\LoginAttemptManagerInterface;
|
||||
use Amasty\AdminActionsLog\Api\VisitHistoryManagerInterface;
|
||||
use Amasty\AdminActionsLog\Model\OptionSource\LoginAttemptStatus;
|
||||
|
||||
class SucceedLogin implements LoggingActionInterface
|
||||
{
|
||||
/**
|
||||
* @var MetadataInterface
|
||||
*/
|
||||
private $metadata;
|
||||
|
||||
/**
|
||||
* @var ActiveSessionManagerInterface
|
||||
*/
|
||||
private $activeSessionManager;
|
||||
|
||||
/**
|
||||
* @var VisitHistoryManagerInterface
|
||||
*/
|
||||
private $visitHistoryManager;
|
||||
|
||||
/**
|
||||
* @var LoginAttemptManagerInterface
|
||||
*/
|
||||
private $loginAttemptManager;
|
||||
|
||||
public function __construct(
|
||||
MetadataInterface $metadata,
|
||||
ActiveSessionManagerInterface $activeSessionManager,
|
||||
VisitHistoryManagerInterface $visitHistoryManager,
|
||||
LoginAttemptManagerInterface $loginAttemptManager
|
||||
) {
|
||||
$this->metadata = $metadata;
|
||||
$this->activeSessionManager = $activeSessionManager;
|
||||
$this->visitHistoryManager = $visitHistoryManager;
|
||||
$this->loginAttemptManager = $loginAttemptManager;
|
||||
}
|
||||
|
||||
public function execute(): void
|
||||
{
|
||||
$this->activeSessionManager->initNew();
|
||||
$this->visitHistoryManager->startVisit();
|
||||
$this->loginAttemptManager->saveAttempt(null, LoginAttemptStatus::SUCCESS);
|
||||
}
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\ActionType\RenderBefore;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Data\VisitHistoryDetailInterfaceFactory;
|
||||
use Amasty\AdminActionsLog\Api\Data\VisitHistoryEntryInterface;
|
||||
use Amasty\AdminActionsLog\Api\Logging\LoggingActionInterface;
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Api\Logging\ObjectDataStorageInterface;
|
||||
use Amasty\AdminActionsLog\Model\Admin\SessionUserDataProvider;
|
||||
use Amasty\AdminActionsLog\Api\VisitHistoryEntryRepositoryInterface;
|
||||
use Amasty\AdminActionsLog\Model\VisitHistoryEntry\VisitHistoryDetail;
|
||||
use Amasty\AdminActionsLog\Model\VisitHistoryEntry\VisitHistoryManager;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Stdlib\DateTime\DateTime;
|
||||
|
||||
class Layout implements LoggingActionInterface
|
||||
{
|
||||
/**
|
||||
* @var DateTime
|
||||
*/
|
||||
private $dateTime;
|
||||
|
||||
/**
|
||||
* @var MetadataInterface
|
||||
*/
|
||||
private $metadata;
|
||||
|
||||
/**
|
||||
* @var SessionUserDataProvider
|
||||
*/
|
||||
private $userDataProvider;
|
||||
|
||||
/**
|
||||
* @var ObjectDataStorageInterface
|
||||
*/
|
||||
private $dataStorage;
|
||||
|
||||
/**
|
||||
* @var VisitHistoryDetailInterfaceFactory
|
||||
*/
|
||||
private $detailFactory;
|
||||
|
||||
/**
|
||||
* @var VisitHistoryEntryRepositoryInterface
|
||||
*/
|
||||
private $historyEntryRepository;
|
||||
|
||||
/**
|
||||
* @var VisitHistoryManager
|
||||
*/
|
||||
private $visitHistoryManager;
|
||||
|
||||
public function __construct(
|
||||
DateTime $dateTime,
|
||||
MetadataInterface $metadata,
|
||||
SessionUserDataProvider $userDataProvider,
|
||||
ObjectDataStorageInterface $dataStorage,
|
||||
VisitHistoryDetailInterfaceFactory $detailFactory,
|
||||
VisitHistoryEntryRepositoryInterface $historyEntryRepository,
|
||||
VisitHistoryManager $visitHistoryManager
|
||||
) {
|
||||
$this->dateTime = $dateTime;
|
||||
$this->metadata = $metadata;
|
||||
$this->userDataProvider = $userDataProvider;
|
||||
$this->dataStorage = $dataStorage;
|
||||
$this->detailFactory = $detailFactory;
|
||||
$this->historyEntryRepository = $historyEntryRepository;
|
||||
$this->visitHistoryManager = $visitHistoryManager;
|
||||
}
|
||||
|
||||
public function execute(): void
|
||||
{
|
||||
/** @var \Magento\Framework\View\Element\Template\Context $context */
|
||||
if (!$context = $this->metadata->getObject()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$sessionId = $this->userDataProvider->getSessionId();
|
||||
$historyEntry = $this->getHistoryEntry($sessionId);
|
||||
$details = $historyEntry->getVisitHistoryDetails();
|
||||
$lastDetail = end($details) ?: $this->detailFactory->create();
|
||||
|
||||
if ($lastDetail->getPageUrl() !== $context->getUrlBuilder()->getCurrentUrl()) {
|
||||
$storageKey = $this->userDataProvider->getUserName() . 'StayDuration';
|
||||
$currentTimeStamp = $this->dateTime->gmtTimestamp();
|
||||
$lastDetailStayDuration = $this->dataStorage->isExists($storageKey)
|
||||
? $currentTimeStamp - ($this->dataStorage->get($storageKey)['timestamp'] ?? 0)
|
||||
: 0;
|
||||
$lastDetail->setStayDuration((int)$lastDetailStayDuration);
|
||||
$this->dataStorage->set($storageKey, ['timestamp' => $currentTimeStamp]);
|
||||
$details[] = $this->detailFactory->create(['data' => [
|
||||
VisitHistoryDetail::PAGE_NAME => $context->getPageConfig()->getTitle()->get(),
|
||||
VisitHistoryDetail::PAGE_URL => $context->getUrlBuilder()->getCurrentUrl()
|
||||
]]);
|
||||
$historyEntry->setVisitHistoryDetails($details);
|
||||
$this->historyEntryRepository->save($historyEntry);
|
||||
}
|
||||
}
|
||||
|
||||
private function getHistoryEntry(string $sessionId): VisitHistoryEntryInterface
|
||||
{
|
||||
try {
|
||||
$historyEntry = $this->historyEntryRepository->getBySessionId($sessionId);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
$this->visitHistoryManager->startVisit();
|
||||
$historyEntry = $this->historyEntryRepository->getBySessionId($sessionId);
|
||||
}
|
||||
|
||||
return $historyEntry;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\ActionType;
|
||||
|
||||
use Amasty\AdminActionsLog\Logging\ActionType\Validation\ActionValidatorInterface;
|
||||
|
||||
class TypeConfig
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $actionsRegExp;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $validators;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $priority;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $event;
|
||||
|
||||
public function __construct(
|
||||
array $actionsRegExp = [],
|
||||
array $validators = [],
|
||||
string $event = '',
|
||||
int $priority = 0
|
||||
) {
|
||||
foreach ($validators as $validatorName => $validator) {
|
||||
if (!$validator instanceof ActionValidatorInterface) {
|
||||
throw new \LogicException(
|
||||
sprintf(
|
||||
'ActionType validator "%s" must implement %s',
|
||||
$validatorName,
|
||||
ActionValidatorInterface::class
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->actionsRegExp = array_map(function ($action) {
|
||||
return (string)$action;
|
||||
}, $actionsRegExp);
|
||||
$this->validators = $validators;
|
||||
$this->event = $event;
|
||||
$this->priority = $priority;
|
||||
}
|
||||
|
||||
public function getActions(): array
|
||||
{
|
||||
return $this->actionsRegExp;
|
||||
}
|
||||
|
||||
public function getPriority(): int
|
||||
{
|
||||
return $this->priority;
|
||||
}
|
||||
|
||||
public function getEvent(): string
|
||||
{
|
||||
return $this->event;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ActionValidatorInterface[]
|
||||
*/
|
||||
public function getValidators(): array
|
||||
{
|
||||
return $this->validators;
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\ActionType\Validation;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Magento\Framework\DataObject;
|
||||
|
||||
class ActionValidator implements ActionValidatorInterface
|
||||
{
|
||||
/**
|
||||
* @var DataObject
|
||||
*/
|
||||
private $actionsList;
|
||||
|
||||
public function __construct(DataObject $actionsList)
|
||||
{
|
||||
$this->actionsList = $actionsList;
|
||||
}
|
||||
|
||||
public function isValid(MetadataInterface $metadata): bool
|
||||
{
|
||||
return !in_array($metadata->getRequest()->getFullActionName(), $this->actionsList->getList());
|
||||
}
|
||||
}
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\ActionType\Validation;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
|
||||
interface ActionValidatorInterface
|
||||
{
|
||||
/**
|
||||
* Validate Action Metadata.
|
||||
*
|
||||
* @param MetadataInterface $metadata
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid(MetadataInterface $metadata): bool;
|
||||
}
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\ActionType\Validation;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Model\Admin\IsLoggingAllowed;
|
||||
|
||||
class LoggingAllowedValidator implements ActionValidatorInterface
|
||||
{
|
||||
/**
|
||||
* @var IsLoggingAllowed
|
||||
*/
|
||||
private $isLoggingAllowed;
|
||||
|
||||
public function __construct(IsLoggingAllowed $isLoggingAllowed)
|
||||
{
|
||||
$this->isLoggingAllowed = $isLoggingAllowed;
|
||||
}
|
||||
|
||||
public function isValid(MetadataInterface $metadata): bool
|
||||
{
|
||||
return $this->isLoggingAllowed->execute();
|
||||
}
|
||||
}
|
||||
Executable
+46
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\ActionType\Validation;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Model\ConfigProvider;
|
||||
use Magento\Framework\App\HttpRequestInterface;
|
||||
|
||||
class LoggingVisitHistoryValidator implements ActionValidatorInterface
|
||||
{
|
||||
/**
|
||||
* @var ConfigProvider
|
||||
*/
|
||||
private $configProvider;
|
||||
|
||||
/**
|
||||
* @var bool|null
|
||||
*/
|
||||
private $validationResult = null;
|
||||
|
||||
public function __construct(ConfigProvider $configProvider)
|
||||
{
|
||||
$this->configProvider = $configProvider;
|
||||
}
|
||||
|
||||
public function isValid(MetadataInterface $metadata): bool
|
||||
{
|
||||
if ($this->validationResult === null) {
|
||||
$request = $metadata->getRequest();
|
||||
|
||||
$this->validationResult = $this->configProvider->isEnabledLogVisitHistory()
|
||||
&& $request instanceof HttpRequestInterface
|
||||
&& !$request->isAjax();
|
||||
}
|
||||
|
||||
return $this->validationResult;
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\ActionType\Validation;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Util\Ignore\ClassList;
|
||||
|
||||
class ObjectClassValidator implements ActionValidatorInterface
|
||||
{
|
||||
/**
|
||||
* @var ClassList
|
||||
*/
|
||||
private $classList;
|
||||
|
||||
public function __construct(ClassList $classList)
|
||||
{
|
||||
$this->classList = $classList;
|
||||
}
|
||||
|
||||
public function isValid(MetadataInterface $metadata): bool
|
||||
{
|
||||
if ($object = $metadata->getObject()) {
|
||||
return !$this->classList->isIgnored(get_class($object));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\ActionType\Validation;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Model\Di\Wrapper as TfaSession;
|
||||
use Magento\Framework\Module\Manager;
|
||||
use Magento\TwoFactorAuth\Api\TfaSessionInterface;
|
||||
|
||||
class TwoFactorGranted implements ActionValidatorInterface
|
||||
{
|
||||
/**
|
||||
* @var Manager
|
||||
*/
|
||||
private $moduleManager;
|
||||
|
||||
/**
|
||||
* @var TfaSessionInterface
|
||||
*/
|
||||
private $tfaSession;
|
||||
|
||||
public function __construct(
|
||||
Manager $moduleManager,
|
||||
TfaSession $tfaSession
|
||||
) {
|
||||
$this->moduleManager = $moduleManager;
|
||||
$this->tfaSession = $tfaSession;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stateless session validator because TFA access can be changed during request processing.
|
||||
* @see \Magento\TwoFactorAuth\Model\TfaSession::grantAccess
|
||||
*
|
||||
* @param MetadataInterface $metadata
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid(MetadataInterface $metadata): bool
|
||||
{
|
||||
return $this->moduleManager->isEnabled('Magento_TwoFactorAuth')
|
||||
? (bool)$this->tfaSession->isGranted()
|
||||
: true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\ActionType;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\LoggingActionInterface;
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\ActionType\Validation\ActionValidatorInterface;
|
||||
|
||||
class ValidationComposite implements LoggingActionInterface
|
||||
{
|
||||
/**
|
||||
* @var MetadataInterface
|
||||
*/
|
||||
private $metadata;
|
||||
|
||||
/**
|
||||
* @var LoggingActionInterface
|
||||
*/
|
||||
private $wrappedAction;
|
||||
|
||||
/**
|
||||
* @var ActionValidatorInterface[]
|
||||
*/
|
||||
private $validators;
|
||||
|
||||
public function __construct(
|
||||
MetadataInterface $metadata,
|
||||
LoggingActionInterface $wrappedAction,
|
||||
array $validators = []
|
||||
) {
|
||||
$this->metadata = $metadata;
|
||||
$this->wrappedAction = $wrappedAction;
|
||||
$this->validators = $validators;
|
||||
}
|
||||
|
||||
public function execute(): void
|
||||
{
|
||||
foreach ($this->validators as $validator) {
|
||||
if (!$validator->isValid($this->metadata)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$this->wrappedAction->execute();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\DataStorage;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\ObjectDataStorageInterface;
|
||||
use Magento\Backend\Model\Session;
|
||||
|
||||
class BackendSession implements ObjectDataStorageInterface
|
||||
{
|
||||
/**
|
||||
* @var Session
|
||||
*/
|
||||
private $session;
|
||||
|
||||
public function __construct(Session $session)
|
||||
{
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
public function get(string $key): ?array
|
||||
{
|
||||
$getterName = 'get' . ucfirst($key);
|
||||
//phpcs:ignore
|
||||
$storedData = call_user_func([$this->session, $getterName]);
|
||||
|
||||
return is_array($storedData) ? $storedData : [$storedData];
|
||||
}
|
||||
|
||||
public function set(string $key, array $data): void
|
||||
{
|
||||
$setterName = 'set' . ucfirst($key);
|
||||
//phpcs:ignore
|
||||
call_user_func_array([$this->session, $setterName], [$data]);
|
||||
}
|
||||
|
||||
public function unset(string $key): void
|
||||
{
|
||||
$unsetterName = 'uns' . ucfirst($key);
|
||||
//phpcs:ignore
|
||||
call_user_func([$this->session, $unsetterName]);
|
||||
}
|
||||
|
||||
public function isExists(string $key): bool
|
||||
{
|
||||
$checkerName = 'has' . ucfirst($key);
|
||||
//phpcs:ignore
|
||||
return call_user_func([$this->session, $checkerName]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\DataStorage;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\ObjectDataStorageInterface;
|
||||
use Magento\Framework\FlagManager;
|
||||
|
||||
class FlagTable implements ObjectDataStorageInterface
|
||||
{
|
||||
public const FLAG_CODE_PREFIX = 'amasty_audit_';
|
||||
|
||||
/**
|
||||
* @var FlagManager
|
||||
*/
|
||||
private $flagManager;
|
||||
|
||||
public function __construct(FlagManager $flagManager)
|
||||
{
|
||||
$this->flagManager = $flagManager;
|
||||
}
|
||||
|
||||
public function get(string $key): ?array
|
||||
{
|
||||
$storedData = $this->flagManager->getFlagData(self::FLAG_CODE_PREFIX . $key);
|
||||
|
||||
return is_array($storedData) || $storedData === null ? $storedData : [$storedData];
|
||||
}
|
||||
|
||||
public function set(string $key, array $data): void
|
||||
{
|
||||
$this->flagManager->saveFlag(self::FLAG_CODE_PREFIX . $key, $data);
|
||||
}
|
||||
|
||||
public function unset(string $key): void
|
||||
{
|
||||
$this->flagManager->deleteFlag(self::FLAG_CODE_PREFIX . $key);
|
||||
}
|
||||
|
||||
public function isExists(string $key): bool
|
||||
{
|
||||
return $this->flagManager->getFlagData(self::FLAG_CODE_PREFIX . $key) !== null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\DataStorage;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\ObjectDataStorageInterface;
|
||||
|
||||
class InMemory implements ObjectDataStorageInterface
|
||||
{
|
||||
/**
|
||||
* Data storage for entities data.
|
||||
* We are using spl_object_id to correctly identify objects.
|
||||
*
|
||||
* Data structure example:
|
||||
* [objectHashId.postfix] => [...]
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $entityDataStorage = [];
|
||||
|
||||
public function get(string $key): ?array
|
||||
{
|
||||
return $this->entityDataStorage[$key] ?? null;
|
||||
}
|
||||
|
||||
public function set(string $key, array $data): void
|
||||
{
|
||||
$this->entityDataStorage[$key] = $data;
|
||||
}
|
||||
|
||||
public function unset(string $key): void
|
||||
{
|
||||
unset($this->entityDataStorage[$key]);
|
||||
}
|
||||
|
||||
public function isExists(string $key): bool
|
||||
{
|
||||
return isset($this->entityDataStorage[$key]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Admin;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Logging\Util\Ignore\ArrayFilter;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
use Magento\User\Model\UserFactory;
|
||||
|
||||
class User extends Common
|
||||
{
|
||||
/**
|
||||
* @var UserFactory
|
||||
*/
|
||||
private $userFactory;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $dataKeysIgnoreList = [
|
||||
'reload_acl_flag',
|
||||
'modified'
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
ArrayFilter\ScalarValueFilter $scalarValueFilter,
|
||||
ArrayFilter\KeyFilter $keyFilter,
|
||||
UserFactory $userFactory
|
||||
) {
|
||||
parent::__construct($scalarValueFilter, $keyFilter);
|
||||
$this->userFactory = $userFactory;
|
||||
}
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\User\Model\User $adminUser */
|
||||
$adminUser = $metadata->getObject();
|
||||
|
||||
if (!$adminUser->getUserName()) {
|
||||
$adminUser->load($adminUser->getId());
|
||||
}
|
||||
|
||||
return [
|
||||
LogEntry::ITEM => $adminUser->getUserName(),
|
||||
LogEntry::CATEGORY => 'admin/user/edit',
|
||||
LogEntry::CATEGORY_NAME => __('Admin User'),
|
||||
LogEntry::ELEMENT_ID => (int)$adminUser->getId(),
|
||||
LogEntry::PARAMETER_NAME => 'user_id'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\User\Model\User $object
|
||||
* @return array
|
||||
*/
|
||||
public function processBeforeSave($object): array
|
||||
{
|
||||
if ($role = $object->getRole()) {
|
||||
$object->setOrigData('role_id', $role->getId());
|
||||
}
|
||||
|
||||
return parent::processBeforeSave($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\User\Model\User $object
|
||||
* @return array
|
||||
*/
|
||||
public function processAfterSave($object): array
|
||||
{
|
||||
$user = $this->userFactory->create()->load($object->getId());
|
||||
|
||||
if ($role = $user->getRole()) {
|
||||
$user->setRoleId($role->getId());
|
||||
}
|
||||
|
||||
return parent::processAfterSave($user);
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Admin;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
use Amasty\AdminActionsLog\Model\OptionSource\LogEntryTypes;
|
||||
|
||||
class UserExpiration extends Common
|
||||
{
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\Security\Model\UserExpiration $expiration */
|
||||
$expiration = $metadata->getObject();
|
||||
$type = $expiration->getOrigData() === [] ? LogEntryTypes::TYPE_NEW : LogEntryTypes::TYPE_EDIT;
|
||||
|
||||
return [
|
||||
LogEntry::TYPE => $type,
|
||||
LogEntry::ITEM => __('Expiration for Admin #%1', $expiration->getUserId()),
|
||||
LogEntry::CATEGORY => 'admin/user/edit',
|
||||
LogEntry::CATEGORY_NAME => __('Admin Expiration'),
|
||||
LogEntry::ELEMENT_ID => (int)$expiration->getUserId(),
|
||||
LogEntry::PARAMETER_NAME => 'user_id'
|
||||
];
|
||||
}
|
||||
|
||||
public function processAfterSave($object): array
|
||||
{
|
||||
$object->load($object->getId());
|
||||
|
||||
return parent::processAfterSave($object);
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Admin;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
|
||||
class UserRole extends Common
|
||||
{
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\Authorization\Model\Role $role */
|
||||
$role = $metadata->getObject();
|
||||
|
||||
return [
|
||||
LogEntry::ITEM => $role->getRoleName(),
|
||||
LogEntry::CATEGORY => 'admin/user_role/editrole',
|
||||
LogEntry::CATEGORY_NAME => __('Admin User Role'),
|
||||
LogEntry::ELEMENT_ID => (int)$role->getId(),
|
||||
LogEntry::PARAMETER_NAME => 'rid'
|
||||
];
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Adminhtml\Stock;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Logging\Util\Ignore\ArrayFilter;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\CatalogInventory\Api\StockItemRepositoryInterface;
|
||||
use Magento\CatalogInventory\Model\Adminhtml\Stock\Item as StockItem;
|
||||
|
||||
class Item extends Common
|
||||
{
|
||||
public const CATEGORY = 'catalog/product/edit/stock/item';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $stockItems = [];
|
||||
|
||||
/**
|
||||
* @var ProductRepositoryInterface
|
||||
*/
|
||||
private $productRepository;
|
||||
|
||||
/**
|
||||
* @var StockItemRepositoryInterface
|
||||
*/
|
||||
private $stockItemRepository;
|
||||
|
||||
public function __construct(
|
||||
ArrayFilter\ScalarValueFilter $scalarValueFilter,
|
||||
ArrayFilter\KeyFilter $keyFilter,
|
||||
ProductRepositoryInterface $productRepository,
|
||||
StockItemRepositoryInterface $stockItemRepository
|
||||
) {
|
||||
parent::__construct($scalarValueFilter, $keyFilter);
|
||||
$this->productRepository = $productRepository;
|
||||
$this->stockItemRepository = $stockItemRepository;
|
||||
}
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var StockItem $stockItem */
|
||||
$stockItem = $metadata->getObject();
|
||||
$product = $this->productRepository->getById((int)$stockItem->getProductId());
|
||||
|
||||
return [
|
||||
LogEntry::ITEM => $product->getName(),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('Stock Item'),
|
||||
LogEntry::ELEMENT_ID => $stockItem->getId(),
|
||||
LogEntry::VIEW_ELEMENT_ID => $product->getId(),
|
||||
];
|
||||
}
|
||||
|
||||
public function processBeforeSave($object): array
|
||||
{
|
||||
$stockItem = $this->getStockItem((int)$object->getId());
|
||||
|
||||
return $this->filterObjectData($stockItem->getData());
|
||||
}
|
||||
|
||||
private function getStockItem(int $stockItemId): StockItem
|
||||
{
|
||||
if (!isset($this->stockItems[$stockItemId])) {
|
||||
$this->stockItems[$stockItemId] = $this->stockItemRepository->get($stockItemId);
|
||||
}
|
||||
|
||||
return $this->stockItems[$stockItemId];
|
||||
}
|
||||
}
|
||||
Executable
+68
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Amasty\RequestQuote\Model;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Logging\Util\Ignore\ArrayFilter;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
|
||||
class Quote extends Common
|
||||
{
|
||||
public const CATEGORY = 'amasty_quote/quote/view';
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $keysToCheck;
|
||||
|
||||
public function __construct(
|
||||
ArrayFilter\ScalarValueFilter $scalarValueFilter,
|
||||
ArrayFilter\KeyFilter $keyFilter,
|
||||
array $keysToCheck = []
|
||||
) {
|
||||
parent::__construct($scalarValueFilter, $keyFilter);
|
||||
$this->keysToCheck = $keysToCheck;
|
||||
}
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Amasty\RequestQuote\Model\Quote $quote */
|
||||
$quote = $metadata->getObject();
|
||||
|
||||
return [
|
||||
LogEntry::ITEM => __('Request Quote #%1', $quote->getIncrementId()),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('Request Quote'),
|
||||
LogEntry::ELEMENT_ID => $quote->getId(),
|
||||
LogEntry::PARAMETER_NAME => 'quote_id'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Amasty\RequestQuote\Model\Quote $object
|
||||
* @return array
|
||||
*/
|
||||
public function processBeforeSave($object): array
|
||||
{
|
||||
$quote = clone $object;
|
||||
$quote->load($object->getId());
|
||||
|
||||
return $this->filterObjectData((array)$quote->getData());
|
||||
}
|
||||
|
||||
protected function filterObjectData(array $data): array
|
||||
{
|
||||
$data = parent::filterObjectData($data);
|
||||
|
||||
return array_intersect_key($data, array_flip($this->keysToCheck));
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Catalog;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
|
||||
class Category extends Common
|
||||
{
|
||||
public const CATEGORY = 'catalog/category/edit';
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $dataKeysIgnoreList = [
|
||||
'form_key',
|
||||
'entity_id',
|
||||
'updated_at',
|
||||
'url_key_create_redirect',
|
||||
'save_rewrites_history',
|
||||
'custom_design_from_is_formated'
|
||||
];
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\Catalog\Model\Category $category */
|
||||
$category = $metadata->getObject();
|
||||
|
||||
if (!$category->getName()) {
|
||||
$category->load($category->getId()); // Force reload category in cases of mass delete, etc.
|
||||
}
|
||||
|
||||
return [
|
||||
LogEntry::ITEM => $category->getName(),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('Catalog Category'),
|
||||
LogEntry::ELEMENT_ID => (int)$category->getId(),
|
||||
LogEntry::STORE_ID => (int)$category->getStoreId()
|
||||
];
|
||||
}
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Catalog;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Logging\Util\Ignore\ArrayFilter;
|
||||
use Amasty\AdminActionsLog\Model\Catalog\Model\Product\Gallery\LogImages;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
|
||||
class Product extends Common
|
||||
{
|
||||
public const CATEGORY = 'catalog/product/edit';
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $dataKeysIgnoreList = [
|
||||
'current_product_id',
|
||||
'affect_product_custom_options',
|
||||
'current_store_id',
|
||||
'product_has_weight',
|
||||
'is_new',
|
||||
'_edit_mode',
|
||||
'amrolepermissions_owner',
|
||||
'use_config_gift_message_available',
|
||||
'use_config_gift_wrapping_available',
|
||||
'url_key_create_redirect',
|
||||
'use_config_is_returnable',
|
||||
'can_save_custom_options',
|
||||
'save_rewrites_history',
|
||||
'is_custom_option_changed',
|
||||
'special_from_date_is_formated',
|
||||
'custom_design_from_is_formated',
|
||||
'news_from_date_is_formated',
|
||||
'news_to_date_is_formated',
|
||||
'force_reindex_eav_required',
|
||||
'updated_at',
|
||||
'has_options',
|
||||
'required_options',
|
||||
'quantity_and_stock_status'
|
||||
];
|
||||
|
||||
/**
|
||||
* @var LogImages
|
||||
*/
|
||||
private $logImages;
|
||||
|
||||
public function __construct(
|
||||
ArrayFilter\ScalarValueFilter $scalarValueFilter,
|
||||
ArrayFilter\KeyFilter $keyFilter,
|
||||
?LogImages $logImages = null
|
||||
) {
|
||||
parent::__construct($scalarValueFilter, $keyFilter);
|
||||
$this->logImages = $logImages ?? ObjectManager::getInstance()->get(LogImages::class);
|
||||
}
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\Catalog\Model\Product $product */
|
||||
$product = $metadata->getObject();
|
||||
|
||||
if (!$product->getName()) {
|
||||
$product->load($product->getId()); // Force reload product in cases of mass delete, etc.
|
||||
}
|
||||
|
||||
return [
|
||||
LogEntry::ITEM => $product->getName(),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('Catalog Product'),
|
||||
LogEntry::ELEMENT_ID => (int)$product->getId(),
|
||||
LogEntry::STORE_ID => (int)$product->getStoreId()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\Model\AbstractModel $object
|
||||
* @return array
|
||||
*/
|
||||
public function processBeforeSave($object): array
|
||||
{
|
||||
$this->logImages->processGalleryBeforeSave($object);
|
||||
|
||||
return parent::processBeforeSave($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\Model\AbstractModel $object
|
||||
* @return array
|
||||
*/
|
||||
public function processAfterSave($object): array
|
||||
{
|
||||
$this->logImages->processGalleryAfterSave($object);
|
||||
|
||||
return parent::processAfterSave($object);
|
||||
}
|
||||
}
|
||||
Executable
+52
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Catalog;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
|
||||
class ProductGalleryEntry extends Common
|
||||
{
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
$image = $metadata->getObject();
|
||||
|
||||
return [
|
||||
LogEntry::ITEM => $image->getFile(),
|
||||
LogEntry::CATEGORY => __('Product Gallery Image'),
|
||||
LogEntry::CATEGORY_NAME => __('Product Gallery Image'),
|
||||
LogEntry::ELEMENT_ID => (int)$image->getId()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\Model\AbstractModel $object
|
||||
* @return array
|
||||
*/
|
||||
public function processBeforeSave($object): array
|
||||
{
|
||||
if ($object->getId()) {
|
||||
return $this->filterObjectData($object->getData());
|
||||
} else {
|
||||
return $this->filterObjectData((array)$object->getOrigData());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\Model\AbstractModel $object
|
||||
* @return array
|
||||
*/
|
||||
public function processAfterSave($object): array
|
||||
{
|
||||
return $this->filterObjectData($object->getData());
|
||||
}
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Catalog;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Logging\Util\Ignore\ArrayFilter;
|
||||
use Amasty\AdminActionsLog\Logging\Util\ProductIdentifierResolver;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
use Amasty\AdminActionsLog\Model\OptionSource\LogEntryTypes;
|
||||
use Magento\Catalog\Api\ProductCustomOptionRepositoryInterface;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
|
||||
class ProductOption extends Common
|
||||
{
|
||||
public const CATEGORY = 'catalog/product/edit';
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $dataKeysIgnoreList = [
|
||||
'is_use_default',
|
||||
'initialize',
|
||||
'record_id',
|
||||
'product_sku',
|
||||
'store_id'
|
||||
];
|
||||
|
||||
/**
|
||||
* @var ProductRepositoryInterface
|
||||
*/
|
||||
private $productRepository;
|
||||
|
||||
/**
|
||||
* @var ProductCustomOptionRepositoryInterface
|
||||
*/
|
||||
private $productCustomOptionRepository;
|
||||
|
||||
/**
|
||||
* @var ProductIdentifierResolver
|
||||
*/
|
||||
private $productIdentifierResolver;
|
||||
|
||||
public function __construct(
|
||||
ArrayFilter\ScalarValueFilter $scalarValueFilter,
|
||||
ArrayFilter\KeyFilter $keyFilter,
|
||||
ProductRepositoryInterface $productRepository,
|
||||
ProductCustomOptionRepositoryInterface $productCustomOptionRepository,
|
||||
ProductIdentifierResolver $productIdentifierResolver
|
||||
) {
|
||||
parent::__construct($scalarValueFilter, $keyFilter);
|
||||
|
||||
$this->productRepository = $productRepository;
|
||||
$this->productCustomOptionRepository = $productCustomOptionRepository;
|
||||
$this->productIdentifierResolver = $productIdentifierResolver;
|
||||
}
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\Catalog\Model\Product\Option $option */
|
||||
$option = $metadata->getObject();
|
||||
$type = $option->isObjectNew() ? LogEntryTypes::TYPE_NEW : LogEntryTypes::TYPE_EDIT;
|
||||
// Workaround because there is no product SKU in the object when deleted
|
||||
$productId = $this->productIdentifierResolver->execute((int)$option->getProductId());
|
||||
|
||||
return [
|
||||
LogEntry::TYPE => $type,
|
||||
LogEntry::ITEM => __('Option "%1"', $option->getTitle()),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('Product Customizable Option'),
|
||||
LogEntry::ELEMENT_ID => $productId,
|
||||
LogEntry::STORE_ID => (int)$option->getStoreId(),
|
||||
LogEntry::ADDITIONAL_DATA => [
|
||||
'productId' => $productId,
|
||||
'optionId' => $option->getId() ? (int)$option->getId() : null
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function processBeforeSave($object): array
|
||||
{
|
||||
if ($object->getId()) {
|
||||
$productId = $this->productIdentifierResolver->execute((int)$object->getProductId());
|
||||
$product = $this->productRepository->getById($productId, false, (int)$object->getStoreId());
|
||||
$option = $this->productCustomOptionRepository->getProductOptions($product)
|
||||
[$object->getId()] ?? null;
|
||||
|
||||
return $option ? $this->filterObjectData($option->getData()) : [];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
public function processAfterSave($object): array
|
||||
{
|
||||
$data = parent::processAfterSave($object);
|
||||
if ($object->hasValues()) {
|
||||
unset($data['price_type']);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Executable
+121
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Catalog;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Api\Logging\ObjectDataStorageInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Logging\Util\Ignore\ArrayFilter;
|
||||
use Amasty\AdminActionsLog\Logging\Util\ProductIdentifierResolver;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
use Amasty\AdminActionsLog\Model\OptionSource\LogEntryTypes;
|
||||
use Amasty\AdminActionsLog\Restoring\Entity\RestoreHandler\AbstractHandler;
|
||||
use Magento\Catalog\Api\ProductCustomOptionRepositoryInterface;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
|
||||
class ProductOptionValue extends Common
|
||||
{
|
||||
public const CATEGORY = 'catalog/product/edit';
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $dataKeysIgnoreList = [
|
||||
'is_use_default',
|
||||
'initialize',
|
||||
'record_id',
|
||||
'store_id'
|
||||
];
|
||||
|
||||
/**
|
||||
* @var ProductRepositoryInterface
|
||||
*/
|
||||
private $productRepository;
|
||||
|
||||
/**
|
||||
* @var ProductCustomOptionRepositoryInterface
|
||||
*/
|
||||
private $productCustomOptionRepository;
|
||||
|
||||
/**
|
||||
* @var ProductIdentifierResolver
|
||||
*/
|
||||
private $productIdentifierResolver;
|
||||
|
||||
/**
|
||||
* @var ObjectDataStorageInterface
|
||||
*/
|
||||
private $dataStorage;
|
||||
|
||||
public function __construct(
|
||||
ArrayFilter\ScalarValueFilter $scalarValueFilter,
|
||||
ArrayFilter\KeyFilter $keyFilter,
|
||||
ProductRepositoryInterface $productRepository,
|
||||
ProductCustomOptionRepositoryInterface $productCustomOptionRepository,
|
||||
ProductIdentifierResolver $productIdentifierResolver,
|
||||
ObjectDataStorageInterface $dataStorage
|
||||
) {
|
||||
parent::__construct($scalarValueFilter, $keyFilter);
|
||||
|
||||
$this->productRepository = $productRepository;
|
||||
$this->productCustomOptionRepository = $productCustomOptionRepository;
|
||||
$this->productIdentifierResolver = $productIdentifierResolver;
|
||||
$this->dataStorage = $dataStorage;
|
||||
}
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\Catalog\Model\Product\Option\Value $value */
|
||||
$value = $metadata->getObject();
|
||||
// Workaround because there is no product SKU in the object when deleted
|
||||
$productId = $this->productIdentifierResolver->execute((int)$value->getOption()->getProductId());
|
||||
$type = $value->isObjectNew() ? LogEntryTypes::TYPE_NEW : LogEntryTypes::TYPE_EDIT;
|
||||
$storageKey = spl_object_id($value->getOption()) . '.' . AbstractHandler::STORAGE_CODE_PREFIX;
|
||||
if ($this->dataStorage->isExists($storageKey)) {
|
||||
$type = LogEntryTypes::TYPE_RESTORE;
|
||||
}
|
||||
|
||||
return [
|
||||
LogEntry::TYPE => $type,
|
||||
LogEntry::ITEM => __(
|
||||
'Value "%1" of Option "%2"',
|
||||
$value->getTitle(),
|
||||
$value->getOption()->getTitle()
|
||||
),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('Product Customizable Option'),
|
||||
LogEntry::ELEMENT_ID => $productId,
|
||||
LogEntry::STORE_ID => (int)$value->getStoreId(),
|
||||
LogEntry::ADDITIONAL_DATA => [
|
||||
'productId' => $productId,
|
||||
'optionId' => $value->getOption()->getId(),
|
||||
'valueId' => $value->getId() ? (int)$value->getId() : null
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function processBeforeSave($object): array
|
||||
{
|
||||
if ($object->getId() && $object->getOption()->getId()) {
|
||||
$productId = $this->productIdentifierResolver->execute(
|
||||
(int)$object->getOption()->getProductId()
|
||||
);
|
||||
$product = $this->productRepository->getById($productId, false, (int)$object->getStoreId());
|
||||
$option = $this->productCustomOptionRepository->getProductOptions($product)
|
||||
[$object->getOption()->getId()] ?? null;
|
||||
$value = $option ? $option->getValues()[$object->getId()] ?? null : null;
|
||||
|
||||
return $value ? $this->filterObjectData($value->getData()) : [];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Executable
+69
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\CheckoutAgreement;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Logging\Util\Ignore\ArrayFilter;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
use Magento\CheckoutAgreements\Api\CheckoutAgreementsRepositoryInterface;
|
||||
use Magento\CheckoutAgreements\Model\Agreement as CheckoutAgreement;
|
||||
|
||||
class Agreement extends Common
|
||||
{
|
||||
public const CATEGORY = 'checkout/agreement/edit';
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $dataKeysIgnoreList = [
|
||||
'form_key'
|
||||
];
|
||||
|
||||
/**
|
||||
* @var CheckoutAgreementsRepositoryInterface
|
||||
*/
|
||||
private $checkoutAgreementsRepository;
|
||||
|
||||
public function __construct(
|
||||
ArrayFilter\ScalarValueFilter $scalarValueFilter,
|
||||
ArrayFilter\KeyFilter $keyFilter,
|
||||
CheckoutAgreementsRepositoryInterface $checkoutAgreementsRepository
|
||||
) {
|
||||
parent::__construct($scalarValueFilter, $keyFilter);
|
||||
|
||||
$this->checkoutAgreementsRepository = $checkoutAgreementsRepository;
|
||||
}
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var CheckoutAgreement $agreement */
|
||||
$agreement = $metadata->getObject();
|
||||
|
||||
return [
|
||||
LogEntry::ITEM => $agreement->getName(),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('Terms and Conditions'),
|
||||
LogEntry::ELEMENT_ID => (int)$agreement->getId(),
|
||||
];
|
||||
}
|
||||
|
||||
public function processBeforeSave($object): array
|
||||
{
|
||||
if ($object->getId()) {
|
||||
$agreement = $this->checkoutAgreementsRepository->get((int)$object->getId());
|
||||
|
||||
return $this->filterObjectData($agreement->getData());
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Cms;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
use Magento\Store\Model\Store;
|
||||
|
||||
class Block extends Common
|
||||
{
|
||||
public const CATEGORY = 'cms/block/edit';
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $dataKeysIgnoreList = [
|
||||
'_first_store_id',
|
||||
'form_key',
|
||||
];
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\Cms\Model\Block $block */
|
||||
$block = $metadata->getObject();
|
||||
|
||||
return [
|
||||
LogEntry::ITEM => $block->getTitle(),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('CMS Block'),
|
||||
LogEntry::ELEMENT_ID => (int)$block->getId(),
|
||||
LogEntry::STORE_ID => Store::DEFAULT_STORE_ID,
|
||||
LogEntry::PARAMETER_NAME => 'block_id'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Cms;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
use Magento\Store\Model\Store;
|
||||
|
||||
class Page extends Common
|
||||
{
|
||||
public const CATEGORY = 'admin/cms_page/edit/';
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\Cms\Model\Page $page */
|
||||
$page = $metadata->getObject();
|
||||
|
||||
return [
|
||||
LogEntry::ITEM => $page->getTitle(),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('CMS Page'),
|
||||
LogEntry::ELEMENT_ID => (int)$page->getId(),
|
||||
LogEntry::STORE_ID => Store::DEFAULT_STORE_ID,
|
||||
LogEntry::PARAMETER_NAME => 'page_id'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Cms;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
use Magento\Store\Model\Store;
|
||||
|
||||
class Widget extends Common
|
||||
{
|
||||
public const CATEGORY = 'admin/widget_instance/edit/';
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\Widget\Model\Widget\Instance $widget */
|
||||
$widget = $metadata->getObject();
|
||||
|
||||
return [
|
||||
LogEntry::ITEM => $widget->getTitle(),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('CMS Widget'),
|
||||
LogEntry::ELEMENT_ID => (int)$widget->getId(),
|
||||
LogEntry::STORE_ID => Store::DEFAULT_STORE_ID,
|
||||
LogEntry::PARAMETER_NAME => 'instance_id'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\EntitySaveHandlerInterface;
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Util\Ignore\ArrayFilter;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
|
||||
class Common implements EntitySaveHandlerInterface
|
||||
{
|
||||
/**
|
||||
* @var ArrayFilter\ScalarValueFilter
|
||||
*/
|
||||
private $scalarValueFilter;
|
||||
|
||||
/**
|
||||
* @var ArrayFilter\KeyFilter
|
||||
*/
|
||||
private $keyFilter;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $dataKeysIgnoreList = [];
|
||||
|
||||
public function __construct(
|
||||
ArrayFilter\ScalarValueFilter $scalarValueFilter,
|
||||
ArrayFilter\KeyFilter $keyFilter
|
||||
) {
|
||||
$this->scalarValueFilter = $scalarValueFilter;
|
||||
$this->keyFilter = $keyFilter;
|
||||
}
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\Framework\Model\AbstractModel $object */
|
||||
$object = $metadata->getObject();
|
||||
|
||||
return [
|
||||
LogEntry::ELEMENT_ID => (int)$object->getId(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\Model\AbstractModel $object
|
||||
* @return array
|
||||
*/
|
||||
public function processBeforeSave($object): array
|
||||
{
|
||||
if (!$object instanceof \Magento\Framework\Model\AbstractModel) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->filterObjectData((array)$object->getOrigData());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\Model\AbstractModel $object
|
||||
* @return array
|
||||
*/
|
||||
public function processAfterSave($object): array
|
||||
{
|
||||
if (!$object instanceof \Magento\Framework\Model\AbstractModel) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->filterObjectData((array)$object->getData());
|
||||
}
|
||||
|
||||
protected function filterObjectData(array $data): array
|
||||
{
|
||||
$data = $this->scalarValueFilter->filter($data);
|
||||
$data = $this->keyFilter->filter($data, $this->dataKeysIgnoreList ?? []);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\EntitySaveHandlerInterface;
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
use Amasty\AdminActionsLog\Model\OptionSource\LogEntryTypes;
|
||||
use Amasty\Base\Model\Serializer;
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Framework\App\Config\Value;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
|
||||
class Config implements EntitySaveHandlerInterface
|
||||
{
|
||||
/**
|
||||
* @var ScopeConfigInterface
|
||||
*/
|
||||
private $scopeConfig;
|
||||
|
||||
/**
|
||||
* @var Serializer
|
||||
*/
|
||||
private $serializer;
|
||||
|
||||
public function __construct(
|
||||
ScopeConfigInterface $scopeConfig,
|
||||
Serializer $serializer
|
||||
) {
|
||||
$this->scopeConfig = $scopeConfig;
|
||||
$this->serializer = $serializer;
|
||||
}
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var Value $object */
|
||||
$object = $metadata->getObject();
|
||||
|
||||
return [
|
||||
LogEntry::TYPE => LogEntryTypes::TYPE_EDIT,
|
||||
LogEntry::CATEGORY_NAME => __('System Config'),
|
||||
LogEntry::ELEMENT_ID => (int)$object->getId(),
|
||||
LogEntry::STORE_ID => (int)$object->getScopeId(),
|
||||
// save 'scope' in additional data to understand, what we save in 'store_id': website id or store view id.
|
||||
LogEntry::ADDITIONAL_DATA => [
|
||||
'scope' => $object->getScope()
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Value $object
|
||||
* @return array
|
||||
*/
|
||||
public function processBeforeSave($object): array
|
||||
{
|
||||
$oldValue = $this->scopeConfig->getValue(
|
||||
$object->getPath(),
|
||||
$object->getScope(),
|
||||
(int)$object->getScopeId()
|
||||
);
|
||||
|
||||
if (is_array($oldValue)) {
|
||||
$oldValue = $this->serializer->serialize($oldValue);
|
||||
}
|
||||
|
||||
return [
|
||||
$object->getPath() => $oldValue
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Value $object
|
||||
* @return array
|
||||
*/
|
||||
public function processAfterSave($object): array
|
||||
{
|
||||
return [
|
||||
$object->getPath() => $object->getValue()
|
||||
];
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Customer;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Logging\Util\Ignore\ArrayFilter;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
use Amasty\AdminActionsLog\Model\OptionSource\LogEntryTypes;
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Eav\Model\ResourceModel\Attribute\Collection;
|
||||
use Magento\Store\Model\Store;
|
||||
|
||||
class Customer extends Common
|
||||
{
|
||||
public const CATEGORY = 'customer/index/edit';
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $dataKeysIgnoreList = [
|
||||
'assistance_allowed',
|
||||
'entity_id',
|
||||
'rp_token',
|
||||
'rp_token_created_at',
|
||||
'ignore_validation_flag',
|
||||
'password_hash',
|
||||
'failures_num',
|
||||
'dob_is_formated',
|
||||
'updated_at'
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
?CustomerRepositoryInterface $customerRepository, // @deprecated
|
||||
ArrayFilter\ScalarValueFilter $scalarValueFilter,
|
||||
ArrayFilter\KeyFilter $keyFilter
|
||||
) {
|
||||
parent::__construct($scalarValueFilter, $keyFilter);
|
||||
}
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\Customer\Model\Backend\Customer $customer */
|
||||
$customer = $metadata->getObject();
|
||||
$type = $customer->hasData(Collection::EAV_CODE_PASSWORD_HASH)
|
||||
? LogEntryTypes::TYPE_EDIT
|
||||
: LogEntryTypes::TYPE_NEW;
|
||||
|
||||
return [
|
||||
LogEntry::TYPE => $type,
|
||||
LogEntry::ITEM => $customer->getName(),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('Customer'),
|
||||
LogEntry::ELEMENT_ID => (int)$customer->getId(),
|
||||
LogEntry::STORE_ID => Store::DEFAULT_STORE_ID,
|
||||
];
|
||||
}
|
||||
|
||||
public function processBeforeSave($object): array
|
||||
{
|
||||
return $this->filterObjectData((array)$object->getOrigData());
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Customer;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
use Amasty\AdminActionsLog\Model\OptionSource\LogEntryTypes;
|
||||
|
||||
class CustomerAddress extends Common
|
||||
{
|
||||
public const CATEGORY = 'customer/index/edit';
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $dataKeysIgnoreList = [
|
||||
'id',
|
||||
'customer_id',
|
||||
'store_id',
|
||||
'attribute_set_id'
|
||||
];
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\Customer\Model\Address $address */
|
||||
$address = $metadata->getObject();
|
||||
$type = $address->getOrigData() === null ? LogEntryTypes::TYPE_NEW : LogEntryTypes::TYPE_EDIT;
|
||||
|
||||
return [
|
||||
LogEntry::TYPE => $type,
|
||||
LogEntry::ITEM => $address->getName(),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('Customer Address'),
|
||||
LogEntry::ELEMENT_ID => (int)$address->getCustomerId(),
|
||||
];
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Customer;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
|
||||
class CustomerGroup extends Common
|
||||
{
|
||||
public const CATEGORY = 'customer/group/edit';
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $dataKeysIgnoreList = [
|
||||
'tax_class_name'
|
||||
];
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\Customer\Model\Group $group */
|
||||
$group = $metadata->getObject();
|
||||
|
||||
return [
|
||||
LogEntry::ITEM => $group->getCustomerGroupCode(),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('Customer Group'),
|
||||
LogEntry::ELEMENT_ID => (int)$group->getId(),
|
||||
];
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Customer;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
|
||||
class CustomerSegment extends Common
|
||||
{
|
||||
public const CATEGORY = 'customersegment/index/edit';
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $dataKeysIgnoreList = [
|
||||
'id',
|
||||
'segment_id',
|
||||
'form_key',
|
||||
];
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\CustomerSegment\Model\Segment $segment */
|
||||
$segment = $metadata->getObject();
|
||||
|
||||
return [
|
||||
LogEntry::ITEM => $segment->getName(),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('Customer Segment'),
|
||||
LogEntry::ELEMENT_ID => (int)$segment->getId(),
|
||||
];
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
|
||||
class EavAttribute extends Common
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $dataKeysIgnoreList = [
|
||||
'form_key',
|
||||
];
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute */
|
||||
$attribute = $metadata->getObject();
|
||||
|
||||
return [
|
||||
LogEntry::ITEM => $attribute->getName(),
|
||||
LogEntry::CATEGORY => 'catalog/product_attribute/edit',
|
||||
LogEntry::CATEGORY_NAME => __('Product Attribute'),
|
||||
LogEntry::ELEMENT_ID => (int)$attribute->getId(),
|
||||
LogEntry::STORE_ID => (int)$attribute->getStoreId(),
|
||||
LogEntry::PARAMETER_NAME => 'attribute_id'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
|
||||
class Flag extends Common
|
||||
{
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
$flag = $metadata->getObject();
|
||||
|
||||
return [
|
||||
LogEntry::ITEM => $flag->getFlagCode(),
|
||||
LogEntry::CATEGORY => __('Flag'),
|
||||
LogEntry::CATEGORY_NAME => __('Flag'),
|
||||
LogEntry::ELEMENT_ID => (int)$flag->getId()
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+66
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Inventory\Model;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Catalog\Product;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Logging\Util\Ignore\ArrayFilter;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Inventory\Model\SourceItem as InventorySourceItem;
|
||||
|
||||
class SourceItem extends Common
|
||||
{
|
||||
public const CATEGORY = 'catalog/product/edit/source/item';
|
||||
|
||||
/**
|
||||
* @var ProductRepositoryInterface
|
||||
*/
|
||||
private $productRepository;
|
||||
|
||||
public function __construct(
|
||||
ArrayFilter\ScalarValueFilter $scalarValueFilter,
|
||||
ArrayFilter\KeyFilter $keyFilter,
|
||||
ProductRepositoryInterface $productRepository
|
||||
) {
|
||||
parent::__construct(
|
||||
$scalarValueFilter,
|
||||
$keyFilter
|
||||
);
|
||||
$this->productRepository = $productRepository;
|
||||
}
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var InventorySourceItem $sourceItem */
|
||||
$sourceItem = $metadata->getObject();
|
||||
|
||||
$logMetadata = [
|
||||
LogEntry::ITEM => $sourceItem->getSku(),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('Source Item (%1)', $sourceItem->getSourceCode()),
|
||||
LogEntry::ELEMENT_ID => $sourceItem->getId()
|
||||
];
|
||||
|
||||
try {
|
||||
$product = $this->productRepository->get($sourceItem->getSku());
|
||||
|
||||
$logMetadata[LogEntry::VIEW_ELEMENT_ID] = $product->getId();
|
||||
$logMetadata[LogEntry::ITEM] = $product->getName();
|
||||
} catch (NoSuchEntityException $e) {
|
||||
null;
|
||||
}
|
||||
|
||||
return $logMetadata;
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Marketing\Communications;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
|
||||
class EmailTemplates extends Common
|
||||
{
|
||||
public const CATEGORY = 'admin/email_template/edit';
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $dataKeysIgnoreList = [
|
||||
'template_id',
|
||||
'added_at'
|
||||
];
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\Email\Model\BackendTemplate $emailTemplate */
|
||||
$emailTemplate = $metadata->getObject();
|
||||
|
||||
return [
|
||||
LogEntry::ITEM => $emailTemplate->getTemplateCode(),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('Email Template'),
|
||||
LogEntry::ELEMENT_ID => (int)$emailTemplate->getId(),
|
||||
LogEntry::STORE_ID => (int)$emailTemplate->getStoreId()
|
||||
];
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Marketing\Communications;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
|
||||
class NewsletterTemplates extends Common
|
||||
{
|
||||
public const CATEGORY = 'newsletter/template/edit';
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $dataKeysIgnoreList = [
|
||||
'template_id',
|
||||
'added_at'
|
||||
];
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\Newsletter\Model\Template $newsletterTemplate */
|
||||
$newsletterTemplate = $metadata->getObject();
|
||||
|
||||
return [
|
||||
LogEntry::ITEM => $newsletterTemplate->getTemplateCode(),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('Newsletter Template'),
|
||||
LogEntry::ELEMENT_ID => (int)$newsletterTemplate->getId(),
|
||||
LogEntry::STORE_ID => (int)$newsletterTemplate->getStoreId()
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Marketing\Promotions;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
|
||||
class CartPriceRule extends Common
|
||||
{
|
||||
public const CATEGORY = 'sales_rule/promo_quote/edit';
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $dataKeysIgnoreList = [
|
||||
'_first_store_id',
|
||||
'form_key',
|
||||
];
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\SalesRule\Model\Rule $cartPriceRule */
|
||||
$cartPriceRule = $metadata->getObject();
|
||||
|
||||
return [
|
||||
LogEntry::ITEM => $cartPriceRule->getName(),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('Cart Price Rule'),
|
||||
LogEntry::ELEMENT_ID => (int)$cartPriceRule->getId(),
|
||||
];
|
||||
}
|
||||
|
||||
public function processAfterSave($object): array
|
||||
{
|
||||
$object->load($object->getId());
|
||||
|
||||
return parent::processAfterSave($object);
|
||||
}
|
||||
}
|
||||
app/code/Amasty/AdminActionsLog/Logging/Entity/SaveHandler/Marketing/Promotions/CatalogPriceRule.php
Executable
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Marketing\Promotions;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
|
||||
class CatalogPriceRule extends Common
|
||||
{
|
||||
public const CATEGORY = 'catalog_rule/promo_catalog/edit';
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $dataKeysIgnoreList = [
|
||||
'_first_store_id',
|
||||
'form_key',
|
||||
];
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\CatalogRule\Model\Rule $catalogPriceRule */
|
||||
$catalogPriceRule = $metadata->getObject();
|
||||
|
||||
return [
|
||||
LogEntry::ITEM => $catalogPriceRule->getName(),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('Catalog Price Rule'),
|
||||
LogEntry::ELEMENT_ID => (int)$catalogPriceRule->getId()
|
||||
];
|
||||
}
|
||||
}
|
||||
app/code/Amasty/AdminActionsLog/Logging/Entity/SaveHandler/Marketing/Promotions/GiftCardAccounts.php
Executable
+42
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Marketing\Promotions;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
|
||||
class GiftCardAccounts extends Common
|
||||
{
|
||||
public const CATEGORY = 'admin/giftcardaccount/edit';
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $dataKeysIgnoreList = [
|
||||
'_first_store_id',
|
||||
'form_key',
|
||||
];
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\GiftCardAccount\Model\Giftcardaccount $giftCardAccount */
|
||||
$giftCardAccount = $metadata->getObject();
|
||||
|
||||
return [
|
||||
LogEntry::ITEM => __('Gift Card Account #%1', $giftCardAccount->getId()),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('Gift Card Account'),
|
||||
LogEntry::ELEMENT_ID => (int)$giftCardAccount->getId(),
|
||||
LogEntry::STORE_ID => (int)$giftCardAccount->getStoreId()
|
||||
];
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Marketing\Promotions;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
|
||||
class RelatedProductsRule extends Common
|
||||
{
|
||||
public const CATEGORY = 'admin/targetrule/edit';
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $dataKeysIgnoreList = [
|
||||
'_first_store_id',
|
||||
'form_key',
|
||||
];
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\TargetRule\Model\Rule $relatedProductsRule */
|
||||
$relatedProductsRule = $metadata->getObject();
|
||||
|
||||
return [
|
||||
LogEntry::ITEM => $relatedProductsRule->getName(),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('Related Products Rule'),
|
||||
LogEntry::ELEMENT_ID => (int)$relatedProductsRule->getId(),
|
||||
LogEntry::STORE_ID => (int)$relatedProductsRule->getStoreId()
|
||||
];
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Marketing\Seo;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
use Magento\Store\Model\Store;
|
||||
|
||||
class UrlRewrite extends Common
|
||||
{
|
||||
public const CATEGORY = 'admin/url_rewrite/edit';
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $dataKeysIgnoreList = [
|
||||
'_first_store_id',
|
||||
'form_key',
|
||||
];
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\UrlRewrite\Model\UrlRewrite $urlRewrite */
|
||||
$urlRewrite = $metadata->getObject();
|
||||
|
||||
return [
|
||||
LogEntry::ITEM => $urlRewrite->getRequestPath(),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('URL Rewrite'),
|
||||
LogEntry::ELEMENT_ID => (int)$urlRewrite->getId(),
|
||||
LogEntry::STORE_ID => Store::DEFAULT_STORE_ID
|
||||
];
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Sales;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
use Amasty\AdminActionsLog\Model\OptionSource\LogEntryTypes;
|
||||
|
||||
class Creditmemo extends Common
|
||||
{
|
||||
public const CATEGORY = 'sales/order_creditmemo/view';
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\Sales\Model\Order\Creditmemo $creditMemo */
|
||||
$creditMemo = $metadata->getObject();
|
||||
$type = $creditMemo->getOrigData() === null ? LogEntryTypes::TYPE_NEW : LogEntryTypes::TYPE_EDIT;
|
||||
|
||||
return [
|
||||
LogEntry::TYPE => $type,
|
||||
LogEntry::ITEM => __('Credit Memo for Order #%1', $creditMemo->getOrder()->getRealOrderId()),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('Credit Memo'),
|
||||
LogEntry::ELEMENT_ID => (int)$creditMemo->getId(),
|
||||
LogEntry::PARAMETER_NAME => 'creditmemo_id'
|
||||
];
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Sales;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
use Amasty\AdminActionsLog\Model\OptionSource\LogEntryTypes;
|
||||
|
||||
class Invoice extends Common
|
||||
{
|
||||
public const CATEGORY = 'sales/order_invoice/view';
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\Sales\Model\Order\Invoice $invoice */
|
||||
$invoice = $metadata->getObject();
|
||||
$type = $invoice->getOrigData() === null ? LogEntryTypes::TYPE_NEW : LogEntryTypes::TYPE_EDIT;
|
||||
|
||||
return [
|
||||
LogEntry::TYPE => $type,
|
||||
LogEntry::ITEM => __('Invoice for Order #%1', $invoice->getOrder()->getRealOrderId()),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('Invoice'),
|
||||
LogEntry::ELEMENT_ID => (int)$invoice->getId(),
|
||||
LogEntry::PARAMETER_NAME => 'invoice_id'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Sales;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
use Amasty\AdminActionsLog\Model\OptionSource\LogEntryTypes;
|
||||
|
||||
class Order extends Common
|
||||
{
|
||||
public const CATEGORY = 'sales/order/view';
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\Sales\Model\Order $order */
|
||||
$order = $metadata->getObject();
|
||||
$type = $order->getOrigData() === null ? LogEntryTypes::TYPE_NEW : LogEntryTypes::TYPE_EDIT;
|
||||
|
||||
return [
|
||||
LogEntry::TYPE => $type,
|
||||
LogEntry::ITEM => __('Order #%1', $order->getRealOrderId()),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('Order'),
|
||||
LogEntry::ELEMENT_ID => (int)$order->getId(),
|
||||
LogEntry::PARAMETER_NAME => 'order_id'
|
||||
];
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Sales;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
use Amasty\AdminActionsLog\Model\OptionSource\LogEntryTypes;
|
||||
|
||||
class OrderAddress extends Common
|
||||
{
|
||||
public const CATEGORY = 'sales/order/address';
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $dataKeysIgnoreList = [
|
||||
'form_key',
|
||||
'region_code'
|
||||
];
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\Sales\Model\Order\Address $address */
|
||||
$address = $metadata->getObject();
|
||||
$type = $address->getOrigData() === null ? LogEntryTypes::TYPE_NEW : LogEntryTypes::TYPE_EDIT;
|
||||
|
||||
return [
|
||||
LogEntry::TYPE => $type,
|
||||
LogEntry::ITEM => __(
|
||||
'%1 Address for Order #%2',
|
||||
ucfirst($address->getAddressType()),
|
||||
$address->getOrder()->getRealOrderId()
|
||||
),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('Order Address'),
|
||||
LogEntry::ELEMENT_ID => (int)$address->getId(),
|
||||
LogEntry::PARAMETER_NAME => 'address_id'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Sales;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
|
||||
class Rma extends Common
|
||||
{
|
||||
public const CATEGORY = 'admin/rma/edit';
|
||||
|
||||
/**
|
||||
* @param MetadataInterface $metadata
|
||||
* @return array
|
||||
*/
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\Rma\Model\Rma $rma */
|
||||
$rma = $metadata->getObject();
|
||||
|
||||
return [
|
||||
LogEntry::ITEM => __('Return Request #%1', $rma->getId()),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('RMA'),
|
||||
LogEntry::ELEMENT_ID => (int)$rma->getId()
|
||||
];
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Sales;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Common;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
use Amasty\AdminActionsLog\Model\OptionSource\LogEntryTypes;
|
||||
|
||||
class Shipment extends Common
|
||||
{
|
||||
public const CATEGORY = 'sales/shipment/view';
|
||||
|
||||
public function getLogMetadata(MetadataInterface $metadata): array
|
||||
{
|
||||
/** @var \Magento\Sales\Model\Order\Shipment $shipment */
|
||||
$shipment = $metadata->getObject();
|
||||
$type = $shipment->getOrigData() === null ? LogEntryTypes::TYPE_NEW : LogEntryTypes::TYPE_EDIT;
|
||||
|
||||
return [
|
||||
LogEntry::TYPE => $type,
|
||||
LogEntry::ITEM => __('Shipment for Order #%1', $shipment->getOrder()->getRealOrderId()),
|
||||
LogEntry::CATEGORY => self::CATEGORY,
|
||||
LogEntry::CATEGORY_NAME => __('Shipment'),
|
||||
LogEntry::ELEMENT_ID => (int)$shipment->getId(),
|
||||
LogEntry::PARAMETER_NAME => 'shipment_id'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Entity;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\EntitySaveHandlerInterface;
|
||||
use Amasty\AdminActionsLog\Logging\Util\ClassNameNormalizer;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
|
||||
class SaveHandlerProvider
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var ClassNameNormalizer
|
||||
*/
|
||||
private $classNameNormalizer;
|
||||
|
||||
/**
|
||||
* @var SaveHandler\Common
|
||||
*/
|
||||
private $commonSaveHandler;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $entityTypes;
|
||||
|
||||
public function __construct(
|
||||
ObjectManagerInterface $objectManager,
|
||||
ClassNameNormalizer $classNameNormalizer,
|
||||
SaveHandler\Common $commonSaveHandler,
|
||||
array $entityTypes = []
|
||||
) {
|
||||
foreach ($entityTypes as $entityTypeClass => &$affectedObjectClasses) {
|
||||
if (!is_subclass_of($entityTypeClass, EntitySaveHandlerInterface::class)) {
|
||||
throw new \LogicException(
|
||||
sprintf(
|
||||
'EntitySaveHandler "%s" must implement %s',
|
||||
$entityTypeClass,
|
||||
EntitySaveHandlerInterface::class
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$affectedObjectClasses = array_map(function ($affectedClass) {
|
||||
return trim($affectedClass, '\\');
|
||||
}, $affectedObjectClasses);
|
||||
}
|
||||
|
||||
$this->objectManager = $objectManager;
|
||||
$this->classNameNormalizer = $classNameNormalizer;
|
||||
$this->commonSaveHandler = $commonSaveHandler;
|
||||
$this->entityTypes = $entityTypes;
|
||||
}
|
||||
|
||||
public function get(string $objectClass): EntitySaveHandlerInterface
|
||||
{
|
||||
$objectClass = $this->classNameNormalizer->execute($objectClass);
|
||||
|
||||
foreach ($this->entityTypes as $entityTypeClass => $affectedObjectClasses) {
|
||||
foreach ($affectedObjectClasses as $affectedObjectClass) {
|
||||
if ($objectClass === $affectedObjectClass || \is_subclass_of($objectClass, $affectedObjectClass)) {
|
||||
return $this->objectManager->get($entityTypeClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->commonSaveHandler;
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Logging\MetadataInterface;
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
|
||||
class Metadata implements MetadataInterface
|
||||
{
|
||||
/**
|
||||
* @var RequestInterface
|
||||
*/
|
||||
private $request;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $eventName;
|
||||
|
||||
/**
|
||||
* @var object|null
|
||||
*/
|
||||
private $loggingObject;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $storageEntityKey;
|
||||
|
||||
public function __construct(
|
||||
RequestInterface $request,
|
||||
string $eventName,
|
||||
object $loggingObject = null,
|
||||
string $storageEntityKey = null
|
||||
) {
|
||||
$this->request = $request;
|
||||
$this->eventName = $eventName;
|
||||
$this->loggingObject = $loggingObject;
|
||||
$this->storageEntityKey = $storageEntityKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getRequest(): RequestInterface
|
||||
{
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getObject(): ?object
|
||||
{
|
||||
return $this->loggingObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getEventName(): string
|
||||
{
|
||||
return $this->eventName;
|
||||
}
|
||||
|
||||
public function getStorageEntityKey(): ?string
|
||||
{
|
||||
return $this->storageEntityKey;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Util;
|
||||
|
||||
class ClassNameNormalizer
|
||||
{
|
||||
public function execute(string $className): string
|
||||
{
|
||||
return str_replace(['\\Interceptor', '\\Proxy'], '', $className);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Util;
|
||||
|
||||
use Amasty\AdminActionsLog\Model\LogEntry;
|
||||
|
||||
class DetailsBuilder
|
||||
{
|
||||
/**
|
||||
* @var ClassNameNormalizer
|
||||
*/
|
||||
private $classNameNormalizer;
|
||||
|
||||
/**
|
||||
* @var LogEntry\LogDetailFactory
|
||||
*/
|
||||
private $detailFactory;
|
||||
|
||||
public function __construct(
|
||||
ClassNameNormalizer $classNameNormalizer,
|
||||
LogEntry\LogDetailFactory $detailFactory
|
||||
) {
|
||||
$this->classNameNormalizer = $classNameNormalizer;
|
||||
$this->detailFactory = $detailFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $modelName
|
||||
* @param array $beforeData
|
||||
* @param array $afterData
|
||||
* @return LogEntry\LogDetail[]
|
||||
*/
|
||||
public function build(string $modelName, array $beforeData, array $afterData): array
|
||||
{
|
||||
$detailList = [];
|
||||
$allDataKeys = array_keys(array_merge($beforeData, $afterData));
|
||||
|
||||
foreach ($allDataKeys as $dataKey) {
|
||||
$oldValue = $beforeData[$dataKey] ?? null;
|
||||
$newValue = $afterData[$dataKey] ?? null;
|
||||
|
||||
if ($oldValue != $newValue) {
|
||||
$detailList[] = $this->detailFactory->create(['data' => [
|
||||
LogEntry\LogDetail::MODEL => $this->classNameNormalizer->execute($modelName),
|
||||
LogEntry\LogDetail::NAME => $dataKey,
|
||||
LogEntry\LogDetail::OLD_VALUE => $oldValue,
|
||||
LogEntry\LogDetail::NEW_VALUE => $newValue,
|
||||
]]);
|
||||
}
|
||||
}
|
||||
|
||||
return $detailList;
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Util\Ignore\ArrayFilter;
|
||||
|
||||
class KeyFilter
|
||||
{
|
||||
public function filter(array $data, array $keysToIgnore): array
|
||||
{
|
||||
if (empty($keysToIgnore)) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
return array_filter($data, function ($key) use ($keysToIgnore) {
|
||||
return !in_array($key, $keysToIgnore);
|
||||
}, ARRAY_FILTER_USE_KEY);
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Util\Ignore\ArrayFilter;
|
||||
|
||||
class ScalarValueFilter
|
||||
{
|
||||
public function filter(array $data): array
|
||||
{
|
||||
return array_filter($data, function ($value) {
|
||||
return is_scalar($value) && !is_array($value);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Util\Ignore;
|
||||
|
||||
use Amasty\AdminActionsLog\Logging\Util\ClassNameNormalizer;
|
||||
|
||||
class ClassList
|
||||
{
|
||||
/**
|
||||
* @var ClassNameNormalizer
|
||||
*/
|
||||
private $classNameNormalizer;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $list;
|
||||
|
||||
public function __construct(
|
||||
ClassNameNormalizer $classNameNormalizer,
|
||||
array $list = []
|
||||
) {
|
||||
$this->classNameNormalizer = $classNameNormalizer;
|
||||
$this->list = array_map(function ($class) {
|
||||
return trim($class, '\\');
|
||||
}, $list);
|
||||
}
|
||||
|
||||
public function isIgnored(string $class): bool
|
||||
{
|
||||
return in_array($this->classNameNormalizer->execute($class), $this->list);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Logging\Util;
|
||||
|
||||
use Magento\Catalog\Api\Data\ProductInterface;
|
||||
use Magento\Framework\App\ResourceConnection;
|
||||
use Magento\Framework\EntityManager\MetadataPool;
|
||||
|
||||
class ProductIdentifierResolver
|
||||
{
|
||||
/**
|
||||
* @var MetadataPool
|
||||
*/
|
||||
private $metadataPool;
|
||||
|
||||
/**
|
||||
* @var ResourceConnection
|
||||
*/
|
||||
private $resourceConnection;
|
||||
|
||||
public function __construct(
|
||||
MetadataPool $metadataPool,
|
||||
ResourceConnection $resourceConnection
|
||||
) {
|
||||
$this->metadataPool = $metadataPool;
|
||||
$this->resourceConnection = $resourceConnection;
|
||||
}
|
||||
|
||||
public function execute(int $productId): ?int
|
||||
{
|
||||
$metadata = $this->metadataPool->getMetadata(ProductInterface::class);
|
||||
if ($metadata->getLinkField() == $metadata->getIdentifierField()) {
|
||||
return $productId;
|
||||
}
|
||||
|
||||
$connection = $this->resourceConnection->getConnectionByName($metadata->getEntityConnectionName());
|
||||
$select = $connection->select()
|
||||
->from($metadata->getEntityTable(), [$metadata->getIdentifierField()])
|
||||
->where($metadata->getLinkField() . ' = ?', $productId);
|
||||
$productId = $connection->fetchOne($select);
|
||||
|
||||
return $productId ? (int)$productId : null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user