ltsecurityinc安防产品在线商城代码

This commit is contained in:
2026-09-14 17:47:10 +08:00
parent 57d8444c15
commit 6a3c9c5bd8
14539 changed files with 1775310 additions and 0 deletions
@@ -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\Api;
interface ActiveSessionManagerInterface
{
public function initNew(): void;
public function update(): void;
public function terminate(string $sessionId = null): void;
public function getInactiveSessions(): array;
public function terminateAll(): void;
}
@@ -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\Api;
use Amasty\AdminActionsLog\Api\Data\ActiveSessionInterface;
interface ActiveSessionRepositoryInterface
{
/**
* @param int $id
*
* @return \Amasty\AdminActionsLog\Api\Data\ActiveSessionInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getById(int $id): ActiveSessionInterface;
/**
* @param string $sessionId
*
* @return \Amasty\AdminActionsLog\Api\Data\ActiveSessionInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getBySessionId(string $sessionId): ActiveSessionInterface;
/**
* @param \Amasty\AdminActionsLog\Api\Data\ActiveSessionInterface $activeSession
*
* @return \Amasty\AdminActionsLog\Api\Data\ActiveSessionInterface
* @throws \Magento\Framework\Exception\CouldNotSaveException
*/
public function save(ActiveSessionInterface $activeSession): ActiveSessionInterface;
/**
* @param \Amasty\AdminActionsLog\Api\Data\ActiveSessionInterface $activeSession
*
* @return bool
* @throws \Magento\Framework\Exception\CouldNotDeleteException
*/
public function delete(ActiveSessionInterface $activeSession): bool;
/**
* @param int $id
*
* @return bool
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Framework\Exception\CouldNotDeleteException
*/
public function deleteById(int $id): bool;
}
@@ -0,0 +1,136 @@
<?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\Api\Data;
interface ActiveSessionInterface
{
/**
* @return int|null
*/
public function getId();
/**
* @param int|null $id
*
* @return \Amasty\AdminActionsLog\Api\Data\ActiveSessionInterface
*/
public function setId($id);
/**
* @return string|null
*/
public function getSessionId(): ?string;
/**
* @param string $sessionId
* @return \Amasty\AdminActionsLog\Api\Data\ActiveSessionInterface
*/
public function setSessionId(string $sessionId): ActiveSessionInterface;
/**
* @return int|null
*/
public function getAdminSessionInfoId(): ?int;
/**
* @param int|null $adminSessionInfoId
* @return ActiveSessionInterface
*/
public function setAdminSessionInfoId(?int $adminSessionInfoId): ActiveSessionInterface;
/**
* @return int|null
*/
public function getUserId(): ?int;
/**
* @param int|null $userId
* @return ActiveSessionInterface
*/
public function setUserId(?int $userId): ActiveSessionInterface;
/**
* @return string|null
*/
public function getUsername(): ?string;
/**
* @param string $username
* @return \Amasty\AdminActionsLog\Api\Data\ActiveSessionInterface
*/
public function setUsername(string $username): ActiveSessionInterface;
/**
* @return string|null
*/
public function getFullName(): ?string;
/**
* @param string $fullName
* @return \Amasty\AdminActionsLog\Api\Data\ActiveSessionInterface
*/
public function setFullName(string $fullName): ActiveSessionInterface;
/**
* @return string|null
*/
public function getIp(): ?string;
/**
* @param string $ip
* @return \Amasty\AdminActionsLog\Api\Data\ActiveSessionInterface
*/
public function setIp(string $ip): ActiveSessionInterface;
/**
* @return string|null
*/
public function getSessionStart(): ?string;
/**
* @param string $startTime
* @return \Amasty\AdminActionsLog\Api\Data\ActiveSessionInterface
*/
public function setSessionStart(string $startTime): ActiveSessionInterface;
/**
* @return string|null
*/
public function getRecentActivity(): ?string;
/**
* @param string $activityTime
* @return \Amasty\AdminActionsLog\Api\Data\ActiveSessionInterface
*/
public function setRecentActivity(string $activityTime): ActiveSessionInterface;
/**
* @return string|null
*/
public function getLocation(): ?string;
/**
* @param string $location
* @return \Amasty\AdminActionsLog\Api\Data\ActiveSessionInterface
*/
public function setLocation(string $location): ActiveSessionInterface;
/**
* @return string|null
*/
public function getCountryId(): ?string;
/**
* @param string $countryId
* @return \Amasty\AdminActionsLog\Api\Data\ActiveSessionInterface
*/
public function setCountryId(string $countryId): ActiveSessionInterface;
}
@@ -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\Api\Data;
interface LogDetailInterface
{
/**
* @return int|null
*/
public function getId();
/**
* @param int|null $id
*
* @return \Amasty\AdminActionsLog\Api\Data\LogDetailInterface
*/
public function setId($id);
/**
* @return int
*/
public function getLogId(): ?int;
/**
* @param int $logId
*
* @return \Amasty\AdminActionsLog\Api\Data\LogDetailInterface
*/
public function setLogId(int $logId): LogDetailInterface;
/**
* @return string|null
*/
public function getName(): ?string;
/**
* @param string $name
*
* @return \Amasty\AdminActionsLog\Api\Data\LogDetailInterface
*/
public function setName(string $name): LogDetailInterface;
/**
* @return string|null
*/
public function getOldValue(): ?string;
/**
* @param string $oldValue
*
* @return \Amasty\AdminActionsLog\Api\Data\LogDetailInterface
*/
public function setOldValue(string $oldValue): LogDetailInterface;
/**
* @return string|null
*/
public function getNewValue(): ?string;
/**
* @param string $newValue
*
* @return \Amasty\AdminActionsLog\Api\Data\LogDetailInterface
*/
public function setNewValue(string $newValue): LogDetailInterface;
/**
* @return string|null
*/
public function getModel(): ?string;
/**
* @param string $model
*
* @return \Amasty\AdminActionsLog\Api\Data\LogDetailInterface
*/
public function setModel(string $model): LogDetailInterface;
}
@@ -0,0 +1,182 @@
<?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\Api\Data;
interface LogEntryInterface
{
/**
* @return int|null
*/
public function getId();
/**
* @param int|null $id
*
* @return \Amasty\AdminActionsLog\Api\Data\LogEntryInterface
*/
public function setId($id);
/**
* @return string|null
*/
public function getDate(): ?string;
/**
* @param string $date
*
* @return \Amasty\AdminActionsLog\Api\Data\LogEntryInterface
*/
public function setDate(string $date): LogEntryInterface;
/**
* @return string|null
*/
public function getUsername(): ?string;
/**
* @param string $username
*
* @return \Amasty\AdminActionsLog\Api\Data\LogEntryInterface
*/
public function setUsername(string $username): LogEntryInterface;
/**
* @return string|null
*/
public function getType(): ?string;
/**
* @param string $type
*
* @return \Amasty\AdminActionsLog\Api\Data\LogEntryInterface
*/
public function setType(string $type): LogEntryInterface;
/**
* @return string|null
*/
public function getCategory(): ?string;
/**
* @param string $category
*
* @return \Amasty\AdminActionsLog\Api\Data\LogEntryInterface
*/
public function setCategory(string $category): LogEntryInterface;
/**
* @return string|null
*/
public function getCategoryName(): ?string;
/**
* @param string $categoryName
*
* @return \Amasty\AdminActionsLog\Api\Data\LogEntryInterface
*/
public function setCategoryName(string $categoryName): LogEntryInterface;
/**
* @return string|null
*/
public function getParameterName(): ?string;
/**
* @param string $parameterName
*
* @return \Amasty\AdminActionsLog\Api\Data\LogEntryInterface
*/
public function setParameterName(string $parameterName): LogEntryInterface;
/**
* @return int
*/
public function getElementId(): int;
/**
* @param int $elementId
*
* @return \Amasty\AdminActionsLog\Api\Data\LogEntryInterface
*/
public function setElementId(int $elementId): LogEntryInterface;
/**
* @return int|null
*/
public function getViewElementId(): ?int;
/**
* @param int|null $viewElementId
*
* @return LogEntryInterface
*/
public function setViewElementId(?int $viewElementId): LogEntryInterface;
/**
* @return string|null
*/
public function getItem(): ?string;
/**
* @param string $item
*
* @return \Amasty\AdminActionsLog\Api\Data\LogEntryInterface
*/
public function setItem(string $item): LogEntryInterface;
/**
* @return string|null
*/
public function getIp(): ?string;
/**
* @param string $ipAddress
*
* @return \Amasty\AdminActionsLog\Api\Data\LogEntryInterface
*/
public function setIp(string $ipAddress): LogEntryInterface;
/**
* @return int|null
*/
public function getStoreId(): ?int;
/**
* @param int $storeId
*
* @return \Amasty\AdminActionsLog\Api\Data\LogEntryInterface
*/
public function setStoreId(int $storeId): LogEntryInterface;
/**
* @return mixed
*/
public function getAdditionalData();
/**
* @param mixed $additionalData
*
* @return \Amasty\AdminActionsLog\Api\Data\LogEntryInterface
*/
public function setAdditionalData($additionalData): LogEntryInterface;
/**
* @return \Amasty\AdminActionsLog\Api\Data\LogDetailInterface[]
*/
public function getLogDetails(): array;
/**
* @param array $logDetails
*
* @return \Amasty\AdminActionsLog\Api\Data\LogEntryInterface
*/
public function setLogDetails(array $logDetails): LogEntryInterface;
}
@@ -0,0 +1,31 @@
<?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\Api\Data;
use Magento\Framework\Api\SearchResultsInterface;
interface LogEntrySearchResultsInterface extends SearchResultsInterface
{
/**
* Get log entries list.
*
* @return \Amasty\AdminActionsLog\Api\Data\LogEntryInterface[]
*/
public function getItems();
/**
* Set log entries list.
*
* @param \Amasty\AdminActionsLog\Api\Data\LogEntryInterface[] $items
* @return $this
*/
public function setItems(array $items);
}
@@ -0,0 +1,114 @@
<?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\Api\Data;
interface LoginAttemptInterface
{
/**
* @return int|null
*/
public function getId();
/**
* @param int|null $id
*
* @return \Amasty\AdminActionsLog\Api\Data\LoginAttemptInterface
*/
public function setId($id);
/**
* @return string|null
*/
public function getDate(): ?string;
/**
* @param string $date
* @return \Amasty\AdminActionsLog\Api\Data\LoginAttemptInterface
*/
public function setDate(string $date): LoginAttemptInterface;
/**
* @return string|null
*/
public function getUsername(): ?string;
/**
* @param string $username
* @return \Amasty\AdminActionsLog\Api\Data\LoginAttemptInterface
*/
public function setUsername(string $username): LoginAttemptInterface;
/**
* @return string|null
*/
public function getFullName(): ?string;
/**
* @param string $fullName
* @return \Amasty\AdminActionsLog\Api\Data\LoginAttemptInterface
*/
public function setFullName(string $fullName): LoginAttemptInterface;
/**
* @return string|null
*/
public function getIp(): ?string;
/**
* @param string $ip
* @return \Amasty\AdminActionsLog\Api\Data\LoginAttemptInterface
*/
public function setIp(string $ip): LoginAttemptInterface;
/**
* @return int|null
*/
public function getStatus(): ?int;
/**
* @param int $status
* @return \Amasty\AdminActionsLog\Api\Data\LoginAttemptInterface
*/
public function setStatus(int $status): LoginAttemptInterface;
/**
* @return string|null
*/
public function getLocation(): ?string;
/**
* @param string $location
* @return \Amasty\AdminActionsLog\Api\Data\LoginAttemptInterface
*/
public function setLocation(string $location): LoginAttemptInterface;
/**
* @return string|null
*/
public function getCountryId(): ?string;
/**
* @param string $countryId
* @return \Amasty\AdminActionsLog\Api\Data\LoginAttemptInterface
*/
public function setCountryId(string $countryId): LoginAttemptInterface;
/**
* @return string|null
*/
public function getUserAgent(): ?string;
/**
* @param string $userAgent
* @return \Amasty\AdminActionsLog\Api\Data\LoginAttemptInterface
*/
public function setUserAgent(string $userAgent): LoginAttemptInterface;
}
@@ -0,0 +1,31 @@
<?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\Api\Data;
use Magento\Framework\Api\SearchResultsInterface;
interface LoginAttemptSearchResultsInterface extends SearchResultsInterface
{
/**
* Get login attempts list.
*
* @return \Amasty\AdminActionsLog\Api\Data\LoginAttemptInterface[]
*/
public function getItems();
/**
* Set login attempts list.
*
* @param \Amasty\AdminActionsLog\Api\Data\LoginAttemptInterface[] $items
* @return $this
*/
public function setItems(array $items);
}
@@ -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\Api\Data;
interface VisitHistoryDetailInterface
{
/**
* @return int|null
*/
public function getId();
/**
* @param int|null $id
*
* @return \Amasty\AdminActionsLog\Api\Data\VisitHistoryDetailInterface
*/
public function setId($id);
/**
* @return int
*/
public function getVisitId(): ?int;
/**
* @param int $visitId
*
* @return \Amasty\AdminActionsLog\Api\Data\VisitHistoryDetailInterface
*/
public function setVisitId(int $visitId): VisitHistoryDetailInterface;
/**
* @return string|null
*/
public function getPageName(): ?string;
/**
* @param string $pageName
*
* @return \Amasty\AdminActionsLog\Api\Data\VisitHistoryDetailInterface
*/
public function setPageName(string $pageName): VisitHistoryDetailInterface;
/**
* @return string|null
*/
public function getPageUrl(): ?string;
/**
* @param string $pageUrl
*
* @return \Amasty\AdminActionsLog\Api\Data\VisitHistoryDetailInterface
*/
public function setPageUrl(string $pageUrl): VisitHistoryDetailInterface;
/**
* @return int|null
*/
public function getStayDuration(): ?int;
/**
* @param int $stayDuration
*
* @return \Amasty\AdminActionsLog\Api\Data\VisitHistoryDetailInterface
*/
public function setStayDuration(int $stayDuration): VisitHistoryDetailInterface;
/**
* @return string|null
*/
public function getSessionId(): ?string;
/**
* @param string $sessionId
*
* @return \Amasty\AdminActionsLog\Api\Data\VisitHistoryDetailInterface
*/
public function setSessionId(string $sessionId): VisitHistoryDetailInterface;
}
@@ -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\Api\Data;
interface VisitHistoryEntryInterface
{
/**
* @return int|null
*/
public function getId();
/**
* @param int|null $id
*
* @return \Amasty\AdminActionsLog\Api\Data\VisitHistoryEntryInterface
*/
public function setId($id);
/**
* @return string|null
*/
public function getUsername(): ?string;
/**
* @param string $username
*
* @return \Amasty\AdminActionsLog\Api\Data\VisitHistoryEntryInterface
*/
public function setUsername(string $username): VisitHistoryEntryInterface;
/**
* @return string|null
*/
public function getFullName(): ?string;
/**
* @param string $fullName
*
* @return \Amasty\AdminActionsLog\Api\Data\VisitHistoryEntryInterface
*/
public function setFullName(string $fullName): VisitHistoryEntryInterface;
/**
* @return string|null
*/
public function getSessionStart(): ?string;
/**
* @param string $sessionStart
*
* @return \Amasty\AdminActionsLog\Api\Data\VisitHistoryEntryInterface
*/
public function setSessionStart(string $sessionStart): VisitHistoryEntryInterface;
/**
* @return string|null
*/
public function getSessionEnd(): ?string;
/**
* @param string $sessionEnd
*
* @return \Amasty\AdminActionsLog\Api\Data\VisitHistoryEntryInterface
*/
public function setSessionEnd(string $sessionEnd): VisitHistoryEntryInterface;
/**
* @return string|null
*/
public function getIp(): ?string;
/**
* @param string $ip
*
* @return \Amasty\AdminActionsLog\Api\Data\VisitHistoryEntryInterface
*/
public function setIp(string $ip): VisitHistoryEntryInterface;
/**
* @return string|null
*/
public function getLocation(): ?string;
/**
* @param string $location
*
* @return \Amasty\AdminActionsLog\Api\Data\VisitHistoryEntryInterface
*/
public function setLocation(string $location): VisitHistoryEntryInterface;
/**
* @return int
*/
public function getSessionId(): ?string;
/**
* @param string $sessionId
*
* @return \Amasty\AdminActionsLog\Api\Data\VisitHistoryEntryInterface
*/
public function setSessionId(string $sessionId): VisitHistoryEntryInterface;
/**
* @return \Amasty\AdminActionsLog\Api\Data\VisitHistoryDetailInterface[]
*/
public function getVisitHistoryDetails(): array;
/**
* @param array $visitHistoryDetails
*
* @return \Amasty\AdminActionsLog\Api\Data\VisitHistoryEntryInterface
*/
public function setVisitHistoryDetails(array $visitHistoryDetails): VisitHistoryEntryInterface;
}
@@ -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\Api\Data;
interface VisitHistoryEntrySearchResultsInterface extends \Magento\Framework\Api\SearchResultsInterface
{
/**
* Get visit history list.
*
* @return \Amasty\AdminActionsLog\Api\Data\VisitHistoryEntryInterface[]
*/
public function getItems();
/**
* Set visit history list.
*
* @param \Amasty\AdminActionsLog\Api\Data\VisitHistoryEntryInterface[] $items
* @return $this
*/
public function setItems(array $items);
}
@@ -0,0 +1,75 @@
<?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\Api;
use Amasty\AdminActionsLog\Api\Data\LogEntryInterface;
use Amasty\AdminActionsLog\Api\Data\LogEntrySearchResultsInterface;
use Magento\Framework\Api\SearchCriteriaInterface;
interface LogEntryRepositoryInterface
{
/**
* @param int $id
*
* @return \Amasty\AdminActionsLog\Api\Data\LogEntryInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getById(int $id): LogEntryInterface;
/**
* @param \Amasty\AdminActionsLog\Api\Data\LogEntryInterface $logEntry
*
* @return \Amasty\AdminActionsLog\Api\Data\LogEntryInterface
* @throws \Magento\Framework\Exception\CouldNotSaveException
*/
public function save(LogEntryInterface $logEntry): LogEntryInterface;
/**
* @param \Amasty\AdminActionsLog\Api\Data\LogEntryInterface $logEntry
*
* @return bool
* @throws \Magento\Framework\Exception\CouldNotDeleteException
*/
public function delete(LogEntryInterface $logEntry): bool;
/**
* @param int $id
*
* @return bool
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Framework\Exception\CouldNotDeleteException
*/
public function deleteById(int $id): bool;
/**
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
*
* @return \Amasty\AdminActionsLog\Api\Data\LogEntrySearchResultsInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getList(SearchCriteriaInterface $searchCriteria): LogEntrySearchResultsInterface;
/**
* @param int|null $period
*
* @return void
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Framework\Exception\CouldNotSaveException
*/
public function clean(?int $period = null): void;
/**
* @param array|null $storeIds
*
* @return void
*/
public function cleanByStoreIds(?array $storeIds = []): void;
}
@@ -0,0 +1,40 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Admin Actions Log for Magento 2
*/
namespace Amasty\AdminActionsLog\Api\Logging;
interface EntitySaveHandlerInterface
{
/**
* Method returns specific LogEntry's data after object saving/deleting.
* @see \Amasty\AdminActionsLog\Logging\ActionType\AfterSave\Entity::prepareLogEntryData
*
* @param MetadataInterface $metadata
* @return array
*/
public function getLogMetadata(MetadataInterface $metadata): array;
/**
* Method for extracting and generating key => value array with data from concrete object
* for LogDetail entity before saving main entity.
* @see \Amasty\AdminActionsLog\Logging\ActionType\BeforeSave\Entity::execute
*
* @param $object
* @return array
*/
public function processBeforeSave($object): array;
/**
* Method for extracting and generating key => value array with data from concrete object
* for LogDetail entity after saving main entity.
* @see \Amasty\AdminActionsLog\Logging\ActionType\AfterSave\Entity::execute
*
* @param $object
* @return array
*/
public function processAfterSave($object): array;
}
@@ -0,0 +1,16 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Admin Actions Log for Magento 2
*/
namespace Amasty\AdminActionsLog\Api\Logging;
interface LoggingActionInterface
{
/**
* Perform logging action i.e. save product changes, save visit history, etc.
*/
public function execute(): void;
}
@@ -0,0 +1,51 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Admin Actions Log for Magento 2
*/
namespace Amasty\AdminActionsLog\Api\Logging;
use Magento\Framework\App\RequestInterface;
interface MetadataInterface
{
/**
* Basic event actions identifiers.
*/
public const EVENT_DISPATCH = 'dispatch';
public const EVENT_SAVE_BEFORE = 'save_before';
public const EVENT_SAVE_AFTER = 'save_after';
public const EVENT_DELETE = 'delete';
public const EVENT_LOGIN = 'login';
public const EVENT_LAYOUT_RENDER_BEFORE = 'layout_render_before';
/**
* Current action's request.
*
* @return RequestInterface
*/
public function getRequest(): RequestInterface;
/**
* Action's event name.
*
* @return string
*/
public function getEventName(): string;
/**
* Action's logging object.
*
* @return object|null
*/
public function getObject(): ?object;
/**
* Object key. It could be set while executing entities by schedule.
*
* @return string|null
*/
public function getStorageEntityKey(): ?string;
}
@@ -0,0 +1,42 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Admin Actions Log for Magento 2
*/
namespace Amasty\AdminActionsLog\Api\Logging;
interface ObjectDataStorageInterface
{
/**
* Method to retrieve stored object data.
*
* @param string $key
* @return array|null
*/
public function get(string $key): ?array;
/**
* Method to store object's data in storage.
*
* @param string $key
* @param array $data
*/
public function set(string $key, array $data): void;
/**
* Method to remove object's data from storage.
*
* @param string $key
*/
public function unset(string $key): void;
/**
* Method to to check is data persists in storage.
*
* @param string $key
* @return bool
*/
public function isExists(string $key): bool;
}
@@ -0,0 +1,18 @@
<?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\Api;
interface LoginAttemptManagerInterface
{
public function saveAttempt(?string $username, int $status): void;
public function clear(int $period = null): void;
}
@@ -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\Api;
use Amasty\AdminActionsLog\Api\Data\LoginAttemptInterface;
use Amasty\AdminActionsLog\Api\Data\LoginAttemptSearchResultsInterface;
use Magento\Framework\Api\SearchCriteriaInterface;
interface LoginAttemptRepositoryInterface
{
/**
* @param int $id
*
* @return \Amasty\AdminActionsLog\Api\Data\LoginAttemptInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getById(int $id): LoginAttemptInterface;
/**
* @param \Amasty\AdminActionsLog\Api\Data\LoginAttemptInterface $loginAttempt
*
* @return \Amasty\AdminActionsLog\Api\Data\LoginAttemptInterface
* @throws \Magento\Framework\Exception\CouldNotSaveException
*/
public function save(LoginAttemptInterface $loginAttempt): LoginAttemptInterface;
/**
* @param \Amasty\AdminActionsLog\Api\Data\LoginAttemptInterface $loginAttempt
*
* @return bool
* @throws \Magento\Framework\Exception\CouldNotDeleteException
*/
public function delete(LoginAttemptInterface $loginAttempt): bool;
/**
* @param int $id
*
* @return bool
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Framework\Exception\CouldNotDeleteException
*/
public function deleteById(int $id): bool;
/**
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
*
* @return \Amasty\AdminActionsLog\Api\Data\LoginAttemptSearchResultsInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getList(SearchCriteriaInterface $searchCriteria): LoginAttemptSearchResultsInterface;
/**
* @param int|null $period
*
* @return void
*/
public function clean(?int $period = null): void;
}
@@ -0,0 +1,22 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Admin Actions Log for Magento 2
*/
namespace Amasty\AdminActionsLog\Api\Restoring;
use Amasty\AdminActionsLog\Api\Data\LogEntryInterface;
interface EntityRestoreHandlerInterface
{
/**
* Perform restoring action by action log details
*
* @param \Amasty\AdminActionsLog\Api\Data\LogEntryInterface $logEntry
* @param \Amasty\AdminActionsLog\Api\Data\LogDetailInterface[] $logDetails
* @return void
*/
public function restore(LogEntryInterface $logEntry, array $logDetails): void;
}
@@ -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\Api;
use Amasty\AdminActionsLog\Api\Data\VisitHistoryEntrySearchResultsInterface;
use Magento\Framework\Api\SearchCriteriaInterface;
interface VisitHistoryEntryFinderInterface
{
/**
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
*
* @return \Amasty\AdminActionsLog\Api\Data\VisitHistoryEntrySearchResultsInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getList(SearchCriteriaInterface $searchCriteria): VisitHistoryEntrySearchResultsInterface;
}
@@ -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\Api;
use Amasty\AdminActionsLog\Api\Data\VisitHistoryEntryInterface;
use Amasty\AdminActionsLog\Api\Data\VisitHistoryEntrySearchResultsInterface;
use Magento\Framework\Api\SearchCriteriaInterface;
interface VisitHistoryEntryRepositoryInterface
{
/**
* @param int $id
* @return \Amasty\AdminActionsLog\Api\Data\VisitHistoryEntryInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getById(int $id): VisitHistoryEntryInterface;
/**
* @param string $sessionId
* @return \Amasty\AdminActionsLog\Api\Data\VisitHistoryEntryInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getBySessionId(string $sessionId): VisitHistoryEntryInterface;
/**
* @param \Amasty\AdminActionsLog\Api\Data\VisitHistoryEntryInterface $logEntry
*
* @return \Amasty\AdminActionsLog\Api\Data\VisitHistoryEntryInterface
* @throws \Magento\Framework\Exception\CouldNotSaveException
*/
public function save(VisitHistoryEntryInterface $logEntry): VisitHistoryEntryInterface;
/**
* @param \Amasty\AdminActionsLog\Api\Data\VisitHistoryEntryInterface $logEntry
*
* @return bool
* @throws \Magento\Framework\Exception\CouldNotDeleteException
*/
public function delete(VisitHistoryEntryInterface $logEntry): bool;
/**
* @param int $id
*
* @return bool
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Framework\Exception\CouldNotDeleteException
*/
public function deleteById(int $id): bool;
/**
* @param int|null $period
*
* @return void
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Framework\Exception\CouldNotSaveException
*/
public function clean(?int $period = null): void;
}
@@ -0,0 +1,33 @@
<?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\Api;
interface VisitHistoryManagerInterface
{
/**
* Initialize Visit History tracking for current admin.
*/
public function startVisit(): void;
/**
* Track Visit History end time, i.e. admin logout or session destroy.
*
* @param string|null $sessionId
*/
public function endVisit(string $sessionId = null): void;
/**
* Clear whole Visit History storage.
*
* @param int|null $period
*/
public function clear(int $period = null): 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\Block\Adminhtml\Buttons\ActionsLog;
use Amasty\AdminActionsLog\Api\LogEntryRepositoryInterface;
use Amasty\AdminActionsLog\Model\ConfigProvider;
use Amasty\AdminActionsLog\Restoring\RestoreValidator;
use Magento\Backend\Block\Widget\Context;
use Magento\Framework\Escaper;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
class RestoreButton implements ButtonProviderInterface
{
/**
* @var ConfigProvider
*/
private $configProvider;
/**
* @var LogEntryRepositoryInterface
*/
private $logEntryRepository;
/**
* @var RestoreValidator
*/
private $restoreValidator;
/**
* @var Escaper
*/
private $escaper;
/**
* @var \Magento\Framework\App\RequestInterface
*/
private $request;
/**
* @var \Magento\Framework\UrlInterface
*/
private $urlBuilder;
public function __construct(
Context $context,
ConfigProvider $configProvider,
LogEntryRepositoryInterface $logEntryRepository,
RestoreValidator $restoreValidator,
Escaper $escaper
) {
$this->configProvider = $configProvider;
$this->logEntryRepository = $logEntryRepository;
$this->restoreValidator = $restoreValidator;
$this->escaper = $escaper;
$this->request = $context->getRequest();
$this->urlBuilder = $context->getUrlBuilder();
}
public function getButtonData()
{
$id = (int)$this->request->getParam('id');
try {
$logEntry = $this->logEntryRepository->getById($id);
} catch (\Exception $e) {
return [];
}
if ($this->restoreValidator->isValid($logEntry)) {
return [
'label' => __('Restore Changes'),
'class' => 'restore_changes',
'on_click' => $this->getClickAction($id),
'sort_order' => 20
];
}
return [];
}
private function getClickAction(int $id): string
{
return sprintf(
'confirmSetLocation("%s", "%s")',
$this->escaper->escapeJs($this->configProvider->getRestoreSettingsText()),
$this->urlBuilder->getUrl('amaudit/actionslog/restore', ['id' => $id])
);
}
}
@@ -0,0 +1,53 @@
<?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\Block\Adminhtml\Buttons;
use Magento\Backend\Block\Widget\Context;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\AuthorizationInterface;
use Magento\Framework\UrlInterface;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
class GenericButton implements ButtonProviderInterface
{
/**
* @var UrlInterface
*/
protected $urlBuilder;
/**
* @var RequestInterface
*/
protected $request;
/**
* @var AuthorizationInterface
*/
protected $authorization;
public function __construct(
Context $context
) {
$this->urlBuilder = $context->getUrlBuilder();
$this->request = $context->getRequest();
$this->authorization = $context->getAuthorization();
}
public function getUrl($route = '', $params = []): string
{
return $this->urlBuilder->getUrl($route, $params);
}
public function getButtonData(): array
{
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\Block\Adminhtml\Buttons\Grid;
use Amasty\AdminActionsLog\Block\Adminhtml\Buttons\GenericButton;
class ClearLogging extends GenericButton
{
public const ADMIN_RESOURCE = 'Amasty_AdminActionsLog::clear_logging';
public function getButtonData(): array
{
if ($this->authorization->isAllowed(self::ADMIN_RESOURCE)) {
$alertMessage = __('Are you sure you want to do this?');
$onClick = sprintf(
'deleteConfirm("%s", "%s")',
$alertMessage,
$this->getClearLogUrl()
);
return [
'label' => __('Clear Log'),
'class' => 'primary',
'on_click' => $onClick,
'sort_order' => 10,
];
}
return [];
}
public function getClearLogUrl(): string
{
return $this->getUrl('*/*/clear');
}
}
@@ -0,0 +1,45 @@
<?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\Block\Adminhtml\Buttons\Grid;
use Amasty\AdminActionsLog\Block\Adminhtml\Buttons\GenericButton;
class TerminateAllSessions extends GenericButton
{
public const ADMIN_RESOURCE = 'Amasty_AdminActionsLog::active_sessions';
public function getButtonData(): array
{
if ($this->authorization->isAllowed(self::ADMIN_RESOURCE)) {
$alertMessage = __('Are you sure you want to terminate all sessions?'
. ' Your current session will also be terminated.');
$onClick = sprintf(
'deleteConfirm("%s", "%s")',
$alertMessage,
$this->getClearLogUrl()
);
return [
'label' => __('Terminate All Sessions'),
'class' => 'primary',
'on_click' => $onClick,
'sort_order' => 10,
];
}
return [];
}
public function getClearLogUrl(): string
{
return $this->getUrl('*/*/clear');
}
}
@@ -0,0 +1,77 @@
<?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\Block\Adminhtml\Edit\Tab;
use Amasty\AdminActionsLog\Controller\Adminhtml\AbstractActionsLog;
use Magento\Backend\Block\Widget\Tab\TabInterface;
use Magento\Framework\View\Element\Text\ListText;
class History extends ListText implements TabInterface
{
/**
* @var \Magento\Framework\AuthorizationInterface
*/
protected $authorization;
public function __construct(
\Magento\Framework\View\Element\Context $context,
\Magento\Framework\AuthorizationInterface $authorization,
array $data = []
) {
parent::__construct($context, $data);
$this->authorization = $authorization;
}
/**
* Return Tab label
*
* @return \Magento\Framework\Phrase
*/
public function getTabLabel()
{
return __('History of Changes');
}
/**
* Return Tab title
*
* @return \Magento\Framework\Phrase
*/
public function getTabTitle()
{
return __('History of Changes');
}
/**
* Can show tab in tabs
*
* @return boolean
*/
public function canShowTab()
{
return $this->authorization->isAllowed(AbstractActionsLog::ADMIN_RESOURCE);
}
/**
* Tab is hidden
*
* @return boolean
*/
public function isHidden()
{
return false;
}
public function isAjaxLoaded()
{
return true;
}
}
@@ -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\Block\Adminhtml\System\Config\Form;
use Magento\Framework\Data\Form\Element\AbstractElement;
class Email extends \Magento\Config\Block\System\Config\Form\Field
{
/**
* @param AbstractElement $element
*
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _getElementHtml(AbstractElement $element)
{
$js = '<script type="text/javascript">
require([
"Magento_Ui/js/lib/view/utils/async",
"Amasty_AdminActionsLog/js/form/tag-it"
], function ($) {
"use strict";
var input = "#' . $element->getHtmlId() . '";
$.async(input, (function() {
$(input).tagit();
}));
});
</script>';
$element->setAfterElementJs($js);
$element->setData('class', "amactionslog-input");
return parent::_getElementHtml($element);
}
}
@@ -0,0 +1,53 @@
<?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\Block\Adminhtml\System\Config\Form;
use Amasty\Geoip\Helper\Data as GeoipHelper;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\Module\Manager as ModuleManager;
class Geolocation extends \Magento\Config\Block\System\Config\Form\Field
{
/**
* @var ModuleManager
*/
private $moduleManager;
/**
* @var GeoIpHelper
*/
private $geoipHelper;
public function __construct(
Context $context,
ModuleManager $moduleManager,
GeoipHelper $geoipHelper,
array $data = []
) {
$this->moduleManager = $moduleManager;
$this->geoipHelper = $geoipHelper;
parent::__construct($context, $data);
}
protected function _getElementHtml(AbstractElement $element)
{
$element->setDisabled(true);
if ($this->moduleManager->isEnabled('Amasty_Geoip')
&& $this->geoipHelper->isDone(false)
) {
$element->setDisabled(false);
}
return parent::_getElementHtml($element);
}
}
@@ -0,0 +1,18 @@
<?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\Controller\Adminhtml;
use Magento\Backend\App\Action;
abstract class AbstractActionsLog extends Action
{
public const ADMIN_RESOURCE = 'Amasty_AdminActionsLog::actions_log';
}
@@ -0,0 +1,18 @@
<?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\Controller\Adminhtml;
use Magento\Backend\App\Action;
abstract class AbstractActiveSessions extends Action
{
public const ADMIN_RESOURCE = 'Amasty_AdminActionsLog::active_sessions';
}
@@ -0,0 +1,18 @@
<?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\Controller\Adminhtml;
use Magento\Backend\App\Action;
abstract class AbstractLoginAttempts extends Action
{
public const ADMIN_RESOURCE = 'Amasty_AdminActionsLog::login_attempts';
}
@@ -0,0 +1,18 @@
<?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\Controller\Adminhtml;
use Magento\Backend\App\Action;
abstract class AbstractVisitHistory extends Action
{
public const ADMIN_RESOURCE = 'Amasty_AdminActionsLog::page_visit_history';
}
@@ -0,0 +1,64 @@
<?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\Controller\Adminhtml\ActionsLog;
use Amasty\AdminActionsLog\Api\LogEntryRepositoryInterface;
use Amasty\AdminActionsLog\Controller\Adminhtml\AbstractActionsLog;
use Magento\Backend\App\Action\Context;
use Magento\Backend\Model\Auth\Session;
class Clear extends AbstractActionsLog
{
/**
* @var LogEntryRepositoryInterface
*/
private $logEntryRepository;
/**
* @var Session
*/
private $backendSession;
public function __construct(
Context $context,
LogEntryRepositoryInterface $logEntryRepository,
Session $backendSession
) {
parent::__construct($context);
$this->logEntryRepository = $logEntryRepository;
$this->backendSession = $backendSession;
}
public function execute()
{
if ($storeIds = $this->getAvailableStoreIds()) {
$this->logEntryRepository->cleanByStoreIds($storeIds);
} else {
$this->logEntryRepository->clean();
}
$this->messageManager->addSuccessMessage(__('Actions Log has been successfully cleared.'));
return $this->resultRedirectFactory->create()->setRefererUrl();
}
private function getAvailableStoreIds(): array
{
$userRole = $this->backendSession->getUser()->getRole();
if ($userRole->getData('gws_is_all')) {
return [];
}
if ($userRole->getData('gws_stores')) {
return $userRole->getData('gws_stores');
}
return [];
}
}
@@ -0,0 +1,28 @@
<?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\Controller\Adminhtml\ActionsLog;
use Amasty\AdminActionsLog\Controller\Adminhtml\AbstractActionsLog;
use Magento\Framework\Controller\ResultFactory;
class Edit extends AbstractActionsLog
{
public function execute()
{
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
$resultPage->setActiveMenu('Amasty_AdminActionsLog::amaudit');
$resultPage->addBreadcrumb(__('Admin Actions Log'), __('Actions Log'));
$resultPage->getConfig()->getTitle()->prepend(__('Actions Log'));
return $resultPage;
}
}
@@ -0,0 +1,28 @@
<?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\Controller\Adminhtml\ActionsLog;
use Amasty\AdminActionsLog\Controller\Adminhtml\AbstractActionsLog;
use Magento\Framework\Controller\ResultFactory;
class Index extends AbstractActionsLog
{
public function execute()
{
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
$resultPage->setActiveMenu('Amasty_AdminActionsLog::amaudit');
$resultPage->addBreadcrumb(__('Admin Actions Log'), __('Actions Log'));
$resultPage->getConfig()->getTitle()->prepend(__('Actions Log'));
return $resultPage;
}
}
@@ -0,0 +1,134 @@
<?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\Controller\Adminhtml\ActionsLog;
use Amasty\AdminActionsLog\Api\Data\LogEntryInterfaceFactory;
use Amasty\AdminActionsLog\Api\LogEntryRepositoryInterface;
use Amasty\AdminActionsLog\Controller\Adminhtml\AbstractActionsLog;
use Amasty\AdminActionsLog\Model\LogEntry\ResourceModel\Grid\CollectionFactory;
use Amasty\AdminActionsLog\Restoring\RestoreProcessor;
use Amasty\AdminActionsLog\Restoring\RestoreValidator;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Indexer\SaveHandler\Batch;
use Magento\Ui\Component\MassAction\Filter;
use Psr\Log\LoggerInterface;
class MassRestore extends AbstractActionsLog
{
/**
* @var RestoreProcessor
*/
private $restoreProcessor;
/**
* @var RestoreValidator
*/
private $restoreValidator;
/**
* @var Filter
*/
private $filter;
/**
* @var Batch
*/
private $batch;
/**
* @var CollectionFactory
*/
private $collectionFactory;
/**
* @var LogEntryInterfaceFactory
*/
private $logEntryFactory;
/**
* @var LogEntryRepositoryInterface
*/
private $entryRepository;
/**
* @var LoggerInterface
*/
private $logger;
public function __construct(
Context $context,
RestoreProcessor $restoreProcessor,
RestoreValidator $restoreValidator,
CollectionFactory $collectionFactory,
LogEntryInterfaceFactory $logEntryFactory,
LogEntryRepositoryInterface $entryRepository,
Filter $filter,
Batch $batch,
LoggerInterface $logger
) {
parent::__construct($context);
$this->restoreProcessor = $restoreProcessor;
$this->restoreValidator = $restoreValidator;
$this->filter = $filter;
$this->batch = $batch;
$this->collectionFactory = $collectionFactory;
$this->logEntryFactory = $logEntryFactory;
$this->entryRepository = $entryRepository;
$this->logger = $logger;
}
public function execute()
{
$this->filter->applySelectionOnTargetProvider();
$collection = $this->filter->getCollection($this->collectionFactory->create());
$successRestore = $skippedRestore = $failedRestore = [];
/** @var \Magento\Framework\Api\Search\DocumentInterface $logEntryDocument */
foreach ($this->batch->getItems($collection, 10) as $batch) {
foreach ($batch as $logEntryDocument) {
$logEntry = $this->entryRepository->getById((int)$logEntryDocument->getId());
if ($this->restoreValidator->isValid($logEntry)) {
try {
$this->restoreProcessor->restoreChanges($logEntry);
$successRestore[] = $logEntry->getId();
} catch (LocalizedException $e) {
$failedRestore[] = $logEntry->getId();
} catch (\Exception $e) {
$failedRestore[] = $logEntry->getId();
$this->logger->critical($e);
}
} else {
$skippedRestore[] = $logEntry->getId();
}
}
}
if (!empty($successRestore)) {
$this->messageManager->addSuccessMessage(
__('A total of %1 record(s) have been restored.', count($successRestore))
);
}
if (!empty($skippedRestore)) {
$this->messageManager->addWarningMessage(
__('The restoring of records (%1) is not allowed.', implode(', ', $skippedRestore))
);
}
if (!empty($failedRestore)) {
$this->messageManager->addErrorMessage(
__('Failed to restore the records (%1).', implode(', ', $failedRestore))
);
}
return $this->resultRedirectFactory->create()->setPath('*/*/index');
}
}
@@ -0,0 +1,64 @@
<?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\Controller\Adminhtml\ActionsLog;
use Amasty\AdminActionsLog\Controller\Adminhtml\AbstractActionsLog;
use Amasty\AdminActionsLog\Model\LogEntry\Frontend\LogDetailsFormatter;
use Amasty\Base\Model\Serializer;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\ResultFactory;
class Preview extends AbstractActionsLog
{
/**
* @var LogDetailsFormatter
*/
private $detailsFormatter;
/**
* @var Serializer
*/
private $jsonSerializer;
public function __construct(
Context $context,
LogDetailsFormatter $detailsFormatter,
Serializer $jsonSerializer
) {
parent::__construct($context);
$this->detailsFormatter = $detailsFormatter;
$this->jsonSerializer = $jsonSerializer;
}
public function execute()
{
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
if ($logEntryId = (int)$this->getRequest()->getParam('element_id')) {
try {
$data = $this->detailsFormatter->format($logEntryId);
$result = [
'isError' => false,
'data' => $data
];
} catch (\RuntimeException $e) {
$result = [
'isError' => true,
'message' => $e->getMessage()
];
} finally {
$resultJson->setData($result);
}
}
return $resultJson;
}
}
@@ -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\Controller\Adminhtml\ActionsLog;
use Amasty\AdminActionsLog\Api\Data\LogEntryInterface;
use Amasty\AdminActionsLog\Api\LogEntryRepositoryInterface;
use Amasty\AdminActionsLog\Controller\Adminhtml\AbstractActionsLog;
use Amasty\AdminActionsLog\Restoring\RestoreProcessor;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Exception\LocalizedException;
use Psr\Log\LoggerInterface;
class Restore extends AbstractActionsLog
{
/**
* @var LogEntryRepositoryInterface
*/
private $logEntryRepository;
/**
* @var RestoreProcessor
*/
private $restoreProcessor;
/**
* @var LoggerInterface
*/
private $logger;
public function __construct(
Context $context,
LogEntryRepositoryInterface $logEntryRepository,
RestoreProcessor $restoreProcessor,
LoggerInterface $logger
) {
parent::__construct($context);
$this->logEntryRepository = $logEntryRepository;
$this->restoreProcessor = $restoreProcessor;
$this->logger = $logger;
}
public function execute()
{
try {
/** @var LogEntryInterface $logEntry */
$logEntry = $this->logEntryRepository->getById((int)$this->getRequest()->getParam('id'));
$this->restoreProcessor->restoreChanges($logEntry);
$this->messageManager->addSuccessMessage(__('Changes have been successfully restored.'));
} catch (LocalizedException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addErrorMessage(__('Something went wrong.'));
$this->logger->critical($e);
}
return $this->resultRedirectFactory->create()->setRefererUrl();
}
}
@@ -0,0 +1,38 @@
<?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\Controller\Adminhtml\ActiveSessions;
use Amasty\AdminActionsLog\Api\ActiveSessionManagerInterface;
use Amasty\AdminActionsLog\Controller\Adminhtml\AbstractActiveSessions;
use Magento\Backend\App\Action\Context;
class Clear extends AbstractActiveSessions
{
/**
* @var ActiveSessionManagerInterface
*/
private $activeSessionManager;
public function __construct(
Context $context,
ActiveSessionManagerInterface $loginAttemptManager
) {
parent::__construct($context);
$this->activeSessionManager = $loginAttemptManager;
}
public function execute()
{
$this->activeSessionManager->terminateAll();
return $this->resultRedirectFactory->create()->setRefererUrl();
}
}
@@ -0,0 +1,28 @@
<?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\Controller\Adminhtml\ActiveSessions;
use Amasty\AdminActionsLog\Controller\Adminhtml\AbstractActiveSessions;
use Magento\Framework\Controller\ResultFactory;
class Index extends AbstractActiveSessions
{
public function execute()
{
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
$resultPage->setActiveMenu('Amasty_AdminActionsLog::active_sessions');
$resultPage->addBreadcrumb(__('Active Sessions'), __('Active Sessions'));
$resultPage->getConfig()->getTitle()->prepend(__('Active Sessions'));
return $resultPage;
}
}
@@ -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\Controller\Adminhtml\ActiveSessions;
use Amasty\AdminActionsLog\Api\ActiveSessionManagerInterface;
use Amasty\AdminActionsLog\Controller\Adminhtml\AbstractActiveSessions;
use Amasty\AdminActionsLog\Model\ActiveSession\ActiveSession;
use Magento\Backend\App\Action\Context;
class Terminate extends AbstractActiveSessions
{
/**
* @var ActiveSessionManagerInterface
*/
private $activeSessionManager;
public function __construct(
Context $context,
ActiveSessionManagerInterface $activeSessionManager
) {
parent::__construct($context);
$this->activeSessionManager = $activeSessionManager;
}
public function execute()
{
if ($sessionId = $this->getRequest()->getParam(ActiveSession::SESSION_ID)) {
$this->activeSessionManager->terminate($sessionId);
$this->messageManager->addSuccessMessage('Session has been successfully terminated.');
}
return $this->resultRedirectFactory->create()->setRefererUrl();
}
}
@@ -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\Controller\Adminhtml\LoginAttempts;
use Amasty\AdminActionsLog\Api\LoginAttemptManagerInterface;
use Amasty\AdminActionsLog\Controller\Adminhtml\AbstractLoginAttempts;
use Magento\Backend\App\Action\Context;
class Clear extends AbstractLoginAttempts
{
public const ADMIN_RESOURCE = 'Amasty_AdminActionsLog::clear_logging';
/**
* @var LoginAttemptManagerInterface
*/
private $loginAttemptManager;
public function __construct(
Context $context,
LoginAttemptManagerInterface $loginAttemptManager
) {
parent::__construct($context);
$this->loginAttemptManager = $loginAttemptManager;
}
public function execute()
{
$this->loginAttemptManager->clear();
$this->messageManager->addSuccessMessage(__('Login Attempts Log has been successfully cleared.'));
return $this->resultRedirectFactory->create()->setRefererUrl();
}
}
@@ -0,0 +1,28 @@
<?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\Controller\Adminhtml\LoginAttempts;
use Amasty\AdminActionsLog\Controller\Adminhtml\AbstractLoginAttempts;
use Magento\Framework\Controller\ResultFactory;
class Index extends AbstractLoginAttempts
{
public function execute()
{
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
$resultPage->setActiveMenu('Amasty_AdminActionsLog::login_attempts');
$resultPage->addBreadcrumb(__('Login Attempts'), __('Login Attempts'));
$resultPage->getConfig()->getTitle()->prepend(__('Login Attempts'));
return $resultPage;
}
}
@@ -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\Controller\Adminhtml\VisitHistory;
use Amasty\AdminActionsLog\Api\VisitHistoryManagerInterface;
use Amasty\AdminActionsLog\Controller\Adminhtml\AbstractVisitHistory;
use Magento\Backend\App\Action\Context;
class Clear extends AbstractVisitHistory
{
public const ADMIN_RESOURCE = 'Amasty_AdminActionsLog::clear_logging';
/**
* @var VisitHistoryManagerInterface
*/
private $visitHistoryManager;
public function __construct(
Context $context,
VisitHistoryManagerInterface $visitHistoryManager
) {
parent::__construct($context);
$this->visitHistoryManager = $visitHistoryManager;
}
public function execute()
{
$this->visitHistoryManager->clear();
$this->messageManager->addSuccessMessage(__('Page History Log has been successfully cleared.'));
return $this->resultRedirectFactory->create()->setRefererUrl();
}
}
@@ -0,0 +1,74 @@
<?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\Controller\Adminhtml\VisitHistory;
use Amasty\AdminActionsLog\Api\VisitHistoryEntryRepositoryInterface;
use Amasty\AdminActionsLog\Controller\Adminhtml\AbstractVisitHistory;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
class GetDetails extends AbstractVisitHistory
{
/**
* @var VisitHistoryEntryRepositoryInterface
*/
private $visitHistoryEntryRepository;
/**
* @var TimezoneInterface
*/
private $localeDate;
public function __construct(
Context $context,
VisitHistoryEntryRepositoryInterface $visitHistoryEntryRepository,
TimezoneInterface $localeDate
) {
parent::__construct($context);
$this->visitHistoryEntryRepository = $visitHistoryEntryRepository;
$this->localeDate = $localeDate;
}
public function execute()
{
$result = [];
if ($id = (int)$this->getRequest()->getParam('id')) {
$visitHistoryEntry = $this->visitHistoryEntryRepository->getById($id);
$details = [];
foreach ($visitHistoryEntry->getVisitHistoryDetails() as $detail) {
$details[] = $detail->getData();
}
$sessionStart = $this->localeDate->formatDateTime(
$visitHistoryEntry->getSessionStart() ?? '',
\IntlDateFormatter::MEDIUM,
\IntlDateFormatter::MEDIUM
);
$sessionEnd = $this->localeDate->formatDateTime(
$visitHistoryEntry->getSessionEnd() ?? '',
\IntlDateFormatter::MEDIUM,
\IntlDateFormatter::MEDIUM
);
$result = $visitHistoryEntry->setVisitHistoryDetails($details)
->setSessionStart($sessionStart)
->setSessionEnd($sessionEnd)
->getData();
}
/** @var \Magento\Framework\Controller\Result\Json $resultPage */
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
$resultJson->setData($result);
return $resultJson;
}
}
@@ -0,0 +1,28 @@
<?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\Controller\Adminhtml\VisitHistory;
use Amasty\AdminActionsLog\Controller\Adminhtml\AbstractVisitHistory;
use Magento\Framework\Controller\ResultFactory;
class Index extends AbstractVisitHistory
{
public function execute()
{
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
$resultPage->setActiveMenu('Amasty_AdminActionsLog::page_visit_history');
$resultPage->addBreadcrumb(__('Visit History'), __('Visit History'));
$resultPage->getConfig()->getTitle()->prepend(__('Visit History'));
return $resultPage;
}
}
+68
View File
@@ -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\Cron;
use Amasty\AdminActionsLog\Api\LogEntryRepositoryInterface;
use Amasty\AdminActionsLog\Api\LoginAttemptRepositoryInterface;
use Amasty\AdminActionsLog\Api\VisitHistoryEntryRepositoryInterface;
use Amasty\AdminActionsLog\Model\ConfigProvider;
class LogCleaner
{
/**
* @var ConfigProvider
*/
private $configProvider;
/**
* @var LogEntryRepositoryInterface
*/
private $logEntryRepository;
/**
* @var LoginAttemptRepositoryInterface
*/
private $loginAttemptRepository;
/**
* @var VisitHistoryEntryRepositoryInterface
*/
private $visitHistoryEntryRepository;
public function __construct(
ConfigProvider $configProvider,
LogEntryRepositoryInterface $logEntryRepository,
LoginAttemptRepositoryInterface $loginAttemptRepository,
VisitHistoryEntryRepositoryInterface $visitHistoryEntryRepository
) {
$this->configProvider = $configProvider;
$this->logEntryRepository = $logEntryRepository;
$this->loginAttemptRepository = $loginAttemptRepository;
$this->visitHistoryEntryRepository = $visitHistoryEntryRepository;
}
public function execute()
{
if ($this->configProvider->isNeedCleanActionsLog()) {
$this->logEntryRepository->clean($this->configProvider->getActionsLogPeriod());
}
if ($this->configProvider->isNeedCleanLoginAttemptsLog()) {
//TODO: replace to LoginAttemptsManager->clear()
$this->loginAttemptRepository->clean($this->configProvider->getLoginAttemptsLogPeriod());
}
if ($this->configProvider->isNeedCleanVisitHistoryLog()) {
//TODO: replace to VisitHistoryManager->clear()
$this->visitHistoryEntryRepository->clean($this->configProvider->getVisitHistoryLogPeriod());
}
}
}
@@ -0,0 +1,45 @@
<?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\Cron;
use Amasty\AdminActionsLog\Api\ActiveSessionManagerInterface;
use Amasty\AdminActionsLog\Api\VisitHistoryManagerInterface;
class UpdateActiveSessions
{
/**
* @var ActiveSessionManagerInterface
*/
private $activeSessionManager;
/**
* @var VisitHistoryManagerInterface
*/
private $visitHistoryManager;
public function __construct(
ActiveSessionManagerInterface $activeSessionManager,
VisitHistoryManagerInterface $visitHistoryManager
) {
$this->activeSessionManager = $activeSessionManager;
$this->visitHistoryManager = $visitHistoryManager;
}
public function execute(): void
{
$inactiveSessions = $this->activeSessionManager->getInactiveSessions();
foreach ($inactiveSessions as $sessionId) {
$this->activeSessionManager->terminate($sessionId);
$this->visitHistoryManager->endVisit($sessionId);
}
}
}
+103
View File
@@ -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]);
}
}
}
@@ -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);
}
}
@@ -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;
}
}
@@ -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());
}
}
@@ -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;
}
@@ -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();
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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'
];
}
}
@@ -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];
}
}
@@ -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));
}
}
@@ -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()
];
}
}
@@ -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);
}
}
@@ -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());
}
}
@@ -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;
}
}
@@ -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 [];
}
}
@@ -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()
];
}
}
@@ -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());
}
}
@@ -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(),
];
}
}
@@ -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(),
];
}
}
@@ -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(),
];
}
}
@@ -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()
];
}
}
@@ -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;
}
}
@@ -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()
];
}
}
@@ -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()
];
}
}
@@ -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);
}
}
@@ -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()
];
}
}
@@ -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()
];
}
}

Some files were not shown because too many files have changed in this diff Show More