ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -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\Model\LogEntry;
|
||||
|
||||
use Amasty\AdminActionsLog\Model\Admin\SessionUserDataProvider;
|
||||
use Magento\Framework\Stdlib\DateTime\DateTime;
|
||||
|
||||
class AdminLogEntryFactory
|
||||
{
|
||||
/**
|
||||
* @var DateTime
|
||||
*/
|
||||
private $dateTime;
|
||||
|
||||
/**
|
||||
* @var LogEntryFactory
|
||||
*/
|
||||
private $logEntryFactory;
|
||||
|
||||
/**
|
||||
* @var SessionUserDataProvider
|
||||
*/
|
||||
private $userDataProvider;
|
||||
|
||||
public function __construct(
|
||||
DateTime $dateTime,
|
||||
LogEntryFactory $logEntryFactory,
|
||||
SessionUserDataProvider $userDataProvider
|
||||
) {
|
||||
$this->dateTime = $dateTime;
|
||||
$this->logEntryFactory = $logEntryFactory;
|
||||
$this->userDataProvider = $userDataProvider;
|
||||
}
|
||||
|
||||
public function create(array $data = [])
|
||||
{
|
||||
$data = array_merge(
|
||||
[
|
||||
LogEntry::DATE => $this->dateTime->gmtDate(),
|
||||
LogEntry::USERNAME => $this->userDataProvider->getUserName(),
|
||||
LogEntry::PARAMETER_NAME => 'id',
|
||||
LogEntry::STORE_ID => 0,
|
||||
LogEntry::IP => $this->userDataProvider->getIpAddress(),
|
||||
],
|
||||
$data
|
||||
);
|
||||
$logEntry = $this->logEntryFactory->create(['data' => $data]);
|
||||
$logEntry->setHasDataChanges(true);
|
||||
|
||||
return $logEntry;
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Model\LogEntry\Frontend;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\LogEntryRepositoryInterface;
|
||||
use Amasty\AdminActionsLog\Model\DiffFinder\DiffFinderAdapterInterface;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogDetail;
|
||||
|
||||
class LogDetailsFormatter
|
||||
{
|
||||
public const TAG_INS = 'ins';
|
||||
public const TAB_DEL = 'del';
|
||||
|
||||
/**
|
||||
* @var LogEntryRepositoryInterface
|
||||
*/
|
||||
private $logEntryRepository;
|
||||
|
||||
/**
|
||||
* @var DiffFinderAdapterInterface
|
||||
*/
|
||||
private $diffFinder;
|
||||
|
||||
public function __construct(
|
||||
LogEntryRepositoryInterface $logEntryRepository,
|
||||
DiffFinderAdapterInterface $diffFinder
|
||||
) {
|
||||
$this->logEntryRepository = $logEntryRepository;
|
||||
$this->diffFinder = $diffFinder;
|
||||
}
|
||||
|
||||
public function format(int $logEntryId): array
|
||||
{
|
||||
$logEntry = $this->logEntryRepository->getById($logEntryId);
|
||||
|
||||
return array_map(function ($logDetail) {
|
||||
$diffString = $this->diffFinder->render(
|
||||
(string)$logDetail->getOldValue(),
|
||||
(string)$logDetail->getNewValue()
|
||||
);
|
||||
|
||||
return [
|
||||
LogDetail::NAME => $logDetail->getName(),
|
||||
LogDetail::OLD_VALUE => $this->removeDiffTags($diffString, self::TAG_INS),
|
||||
LogDetail::NEW_VALUE => $this->removeDiffTags($diffString, self::TAB_DEL),
|
||||
];
|
||||
}, $logEntry->getLogDetails());
|
||||
}
|
||||
|
||||
private function removeDiffTags(string $text, string $tagName): string
|
||||
{
|
||||
return (string)preg_replace("/<$tagName>(.*?)<\/$tagName>/s", '', $text);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?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\Model\LogEntry;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Data\LogDetailInterface;
|
||||
use Magento\Framework\Model\AbstractModel;
|
||||
|
||||
class LogDetail extends AbstractModel implements LogDetailInterface
|
||||
{
|
||||
/**#@+
|
||||
* Constants defined for keys of data array
|
||||
*/
|
||||
public const ID = 'id';
|
||||
public const LOG_ID = 'log_id';
|
||||
public const NAME = 'name';
|
||||
public const OLD_VALUE = 'old_value';
|
||||
public const NEW_VALUE = 'new_value';
|
||||
public const MODEL = 'model';
|
||||
/**#@-*/
|
||||
|
||||
public function _construct()
|
||||
{
|
||||
parent::_construct();
|
||||
$this->_init(ResourceModel\LogDetail::class);
|
||||
$this->setIdFieldName(self::ID);
|
||||
}
|
||||
|
||||
public function getLogId(): ?int
|
||||
{
|
||||
return $this->hasData(self::LOG_ID) ? (int)$this->_getData(self::LOG_ID) : null;
|
||||
}
|
||||
|
||||
public function setLogId(int $logId): LogDetailInterface
|
||||
{
|
||||
$this->setData(self::LOG_ID, $logId);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->_getData(self::NAME);
|
||||
}
|
||||
|
||||
public function setName(string $name): LogDetailInterface
|
||||
{
|
||||
$this->setData(self::NAME, $name);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOldValue(): ?string
|
||||
{
|
||||
return $this->_getData(self::OLD_VALUE);
|
||||
}
|
||||
|
||||
public function setOldValue(string $oldValue): LogDetailInterface
|
||||
{
|
||||
$this->setData(self::OLD_VALUE, $oldValue);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNewValue(): ?string
|
||||
{
|
||||
return $this->_getData(self::NEW_VALUE);
|
||||
}
|
||||
|
||||
public function setNewValue(string $newValue): LogDetailInterface
|
||||
{
|
||||
$this->setData(self::NEW_VALUE, $newValue);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getModel(): ?string
|
||||
{
|
||||
return $this->_getData(self::MODEL);
|
||||
}
|
||||
|
||||
public function setModel(string $model): LogDetailInterface
|
||||
{
|
||||
$this->setData(self::MODEL, $model);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
+201
@@ -0,0 +1,201 @@
|
||||
<?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\Model\LogEntry;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Data\LogEntryInterface;
|
||||
use Magento\Framework\Model\AbstractModel;
|
||||
|
||||
class LogEntry extends AbstractModel implements LogEntryInterface
|
||||
{
|
||||
/**#@+
|
||||
* Constants defined for keys of data array
|
||||
*/
|
||||
public const ID = 'id';
|
||||
public const DATE = 'date';
|
||||
public const USERNAME = 'username';
|
||||
public const TYPE = 'type';
|
||||
public const CATEGORY = 'category';
|
||||
public const CATEGORY_NAME = 'category_name';
|
||||
public const PARAMETER_NAME = 'parameter_name';
|
||||
public const ELEMENT_ID = 'element_id';
|
||||
public const VIEW_ELEMENT_ID = 'view_element_id';
|
||||
public const ITEM = 'item';
|
||||
public const IP = 'ip';
|
||||
public const STORE_ID = 'store_id';
|
||||
public const ADDITIONAL_DATA = 'additional_data';
|
||||
public const LOG_DETAILS = 'log_details';
|
||||
/**#@-*/
|
||||
|
||||
public function _construct()
|
||||
{
|
||||
parent::_construct();
|
||||
$this->_init(ResourceModel\LogEntry::class);
|
||||
$this->setIdFieldName(self::ID);
|
||||
}
|
||||
|
||||
public function getDate(): ?string
|
||||
{
|
||||
return $this->_getData(self::DATE);
|
||||
}
|
||||
|
||||
public function setDate(string $date): LogEntryInterface
|
||||
{
|
||||
$this->setData(self::DATE, $date);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUsername(): ?string
|
||||
{
|
||||
return $this->_getData(self::USERNAME);
|
||||
}
|
||||
|
||||
public function setUsername(string $username): LogEntryInterface
|
||||
{
|
||||
$this->setData(self::USERNAME, $username);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getType(): ?string
|
||||
{
|
||||
return $this->_getData(self::TYPE);
|
||||
}
|
||||
|
||||
public function setType(string $type): LogEntryInterface
|
||||
{
|
||||
$this->setData(self::TYPE, $type);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCategory(): ?string
|
||||
{
|
||||
return $this->_getData(self::CATEGORY);
|
||||
}
|
||||
|
||||
public function setCategory(string $category): LogEntryInterface
|
||||
{
|
||||
$this->setData(self::CATEGORY, $category);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCategoryName(): ?string
|
||||
{
|
||||
return $this->_getData(self::CATEGORY_NAME);
|
||||
}
|
||||
|
||||
public function setCategoryName(string $categoryName): LogEntryInterface
|
||||
{
|
||||
$this->setData(self::CATEGORY_NAME, $categoryName);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getParameterName(): ?string
|
||||
{
|
||||
return $this->_getData(self::PARAMETER_NAME);
|
||||
}
|
||||
|
||||
public function setParameterName(string $parameterName): LogEntryInterface
|
||||
{
|
||||
$this->setData(self::PARAMETER_NAME, $parameterName);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getElementId(): int
|
||||
{
|
||||
return (int)$this->_getData(self::ELEMENT_ID);
|
||||
}
|
||||
|
||||
public function setElementId(int $elementId): LogEntryInterface
|
||||
{
|
||||
$this->setData(self::ELEMENT_ID, $elementId);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getViewElementId(): ?int
|
||||
{
|
||||
return $this->hasData(self::VIEW_ELEMENT_ID)
|
||||
? (int)$this->_getData(self::VIEW_ELEMENT_ID)
|
||||
: null;
|
||||
}
|
||||
|
||||
public function setViewElementId(?int $viewElementId): LogEntryInterface
|
||||
{
|
||||
$this->setData(self::VIEW_ELEMENT_ID, $viewElementId);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getItem(): ?string
|
||||
{
|
||||
return $this->_getData(self::ITEM);
|
||||
}
|
||||
|
||||
public function setItem(string $item): LogEntryInterface
|
||||
{
|
||||
$this->setData(self::ITEM, $item);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIp(): ?string
|
||||
{
|
||||
return $this->_getData(self::IP);
|
||||
}
|
||||
|
||||
public function setIp(string $ipAddress): LogEntryInterface
|
||||
{
|
||||
$this->setData(self::IP, $ipAddress);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStoreId(): ?int
|
||||
{
|
||||
return $this->hasData(self::STORE_ID) ? (int)$this->_getData(self::STORE_ID) : null;
|
||||
}
|
||||
|
||||
public function setStoreId(int $storeId): LogEntryInterface
|
||||
{
|
||||
$this->setData(self::STORE_ID, $storeId);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAdditionalData()
|
||||
{
|
||||
return $this->_getData(self::ADDITIONAL_DATA);
|
||||
}
|
||||
|
||||
public function setAdditionalData($additionalData): LogEntryInterface
|
||||
{
|
||||
$this->setData(self::ADDITIONAL_DATA, $additionalData);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLogDetails(): array
|
||||
{
|
||||
return (array)$this->_getData(self::LOG_DETAILS);
|
||||
}
|
||||
|
||||
public function setLogDetails(array $logDetails): LogEntryInterface
|
||||
{
|
||||
$this->setData(self::LOG_DETAILS, $logDetails);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -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\Model\LogEntry;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Data\LogEntrySearchResultsInterface;
|
||||
use Magento\Framework\Api\SearchResults;
|
||||
|
||||
/**
|
||||
* Service Data Object with Log Entry search results.
|
||||
*/
|
||||
class LogEntrySearchResults extends SearchResults implements LogEntrySearchResultsInterface
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,261 @@
|
||||
<?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\Model\LogEntry;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Data\LogEntryInterface;
|
||||
use Amasty\AdminActionsLog\Api\Data\LogEntryInterfaceFactory;
|
||||
use Amasty\AdminActionsLog\Api\Data\LogEntrySearchResultsInterface;
|
||||
use Amasty\AdminActionsLog\Api\Data\LogEntrySearchResultsInterfaceFactory;
|
||||
use Amasty\AdminActionsLog\Api\LogEntryRepositoryInterface;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogDetail as LogDetailModel;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\ResourceModel\LogDetail as LogDetailResource;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\ResourceModel\LogDetailCollectionFactory;
|
||||
use Amasty\Base\Model\Serializer;
|
||||
use Magento\Framework\Api\Search\FilterGroup;
|
||||
use Magento\Framework\Api\SearchCriteriaInterface;
|
||||
use Magento\Framework\Api\SortOrder;
|
||||
use Magento\Framework\Exception\CouldNotDeleteException;
|
||||
use Magento\Framework\Exception\CouldNotSaveException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Stdlib\DateTime\DateTime;
|
||||
|
||||
class Repository implements LogEntryRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @var LogEntrySearchResultsInterfaceFactory
|
||||
*/
|
||||
private $searchResultsFactory;
|
||||
|
||||
/**
|
||||
* @var LogEntryInterfaceFactory
|
||||
*/
|
||||
private $logEntryFactory;
|
||||
|
||||
/**
|
||||
* @var ResourceModel\LogEntry
|
||||
*/
|
||||
private $logEntryResource;
|
||||
|
||||
/**
|
||||
* @var ResourceModel\CollectionFactory
|
||||
*/
|
||||
private $logEntryCollectionFactory;
|
||||
|
||||
/**
|
||||
* @var LogDetailResource
|
||||
*/
|
||||
private $logDetailResource;
|
||||
|
||||
/**
|
||||
* @var LogDetailCollectionFactory
|
||||
*/
|
||||
private $logDetailCollectionFactory;
|
||||
|
||||
/**
|
||||
* @var DateTime
|
||||
*/
|
||||
private $dateTime;
|
||||
|
||||
/**
|
||||
* @var Serializer
|
||||
*/
|
||||
private $serializer;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $logEntries = [];
|
||||
|
||||
public function __construct(
|
||||
LogEntrySearchResultsInterfaceFactory $searchResultsFactory,
|
||||
LogEntryInterfaceFactory $logEntryFactory,
|
||||
ResourceModel\LogEntry $logEntryResource,
|
||||
ResourceModel\CollectionFactory $logEntryCollectionFactory,
|
||||
LogDetailResource $logDetailResource,
|
||||
LogDetailCollectionFactory $logDetailCollectionFactory,
|
||||
DateTime $dateTime,
|
||||
Serializer $serializer
|
||||
) {
|
||||
$this->searchResultsFactory = $searchResultsFactory;
|
||||
$this->logEntryFactory = $logEntryFactory;
|
||||
$this->logEntryResource = $logEntryResource;
|
||||
$this->logEntryCollectionFactory = $logEntryCollectionFactory;
|
||||
$this->logDetailResource = $logDetailResource;
|
||||
$this->logDetailCollectionFactory = $logDetailCollectionFactory;
|
||||
$this->dateTime = $dateTime;
|
||||
$this->serializer = $serializer;
|
||||
}
|
||||
|
||||
public function getById(int $id): LogEntryInterface
|
||||
{
|
||||
if (!isset($this->logEntries[$id])) {
|
||||
/** @var LogEntryInterface $logEntry */
|
||||
$logEntry = $this->logEntryFactory->create();
|
||||
$this->logEntryResource->load($logEntry, $id);
|
||||
if (!$logEntry->getId()) {
|
||||
throw new NoSuchEntityException(__('Log Entry with specified ID "%1" not found.', $id));
|
||||
}
|
||||
$logEntry->setLogDetails($this->getLogDetails((int)$logEntry->getId()));
|
||||
$logEntry->setAdditionalData($this->serializer->unserialize($logEntry->getAdditionalData()));
|
||||
|
||||
$this->logEntries[$id] = $logEntry;
|
||||
}
|
||||
|
||||
return $this->logEntries[$id];
|
||||
}
|
||||
|
||||
public function save(LogEntryInterface $logEntry): LogEntryInterface
|
||||
{
|
||||
try {
|
||||
if ($logEntry->getId()) {
|
||||
$logEntry = $this->getById((int)$logEntry->getId())->addData($logEntry->getData());
|
||||
}
|
||||
|
||||
if ($logEntry->getAdditionalData()) {
|
||||
$logEntry->setAdditionalData($this->serializer->serialize($logEntry->getAdditionalData()));
|
||||
}
|
||||
|
||||
$this->logEntryResource->save($logEntry);
|
||||
|
||||
/** @var LogDetailModel $logDetail */
|
||||
foreach ($logEntry->getLogDetails() as $logDetail) {
|
||||
$logDetail->setLogId((int)$logEntry->getId());
|
||||
$this->logDetailResource->save($logDetail);
|
||||
}
|
||||
|
||||
unset($this->logEntries[$logEntry->getId()]);
|
||||
} catch (\Exception $e) {
|
||||
throw new CouldNotSaveException(__('Unable to save the Log Entry. Error: %1', $e->getMessage()));
|
||||
}
|
||||
|
||||
return $logEntry;
|
||||
}
|
||||
|
||||
public function delete(LogEntryInterface $logEntry): bool
|
||||
{
|
||||
try {
|
||||
$this->logEntryResource->delete($logEntry);
|
||||
unset($this->logEntries[$logEntry->getId()]);
|
||||
} catch (\Exception $e) {
|
||||
throw new CouldNotDeleteException(__('Unable to delete the Log Entry. Error: %1', $e->getMessage()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function deleteById(int $id): bool
|
||||
{
|
||||
return $this->delete($this->getById($id));
|
||||
}
|
||||
|
||||
public function getList(SearchCriteriaInterface $searchCriteria): LogEntrySearchResultsInterface
|
||||
{
|
||||
$searchResults = $this->searchResultsFactory->create();
|
||||
$searchResults->setSearchCriteria($searchCriteria);
|
||||
|
||||
/** @var ResourceModel\Collection $logEntryCollection */
|
||||
$logEntryCollection = $this->logEntryCollectionFactory->create();
|
||||
// Add filters from root filter group to the collection
|
||||
foreach ($searchCriteria->getFilterGroups() as $group) {
|
||||
$this->addFilterGroupToCollection($group, $logEntryCollection);
|
||||
}
|
||||
$searchResults->setTotalCount($logEntryCollection->getSize());
|
||||
$sortOrders = $searchCriteria->getSortOrders();
|
||||
if ($sortOrders) {
|
||||
$this->addOrderToCollection($sortOrders, $logEntryCollection);
|
||||
}
|
||||
$logEntryCollection->setCurPage($searchCriteria->getCurrentPage());
|
||||
$logEntryCollection->setPageSize($searchCriteria->getPageSize());
|
||||
$logEntries = [];
|
||||
/** @var LogEntryInterface $logEntry */
|
||||
foreach ($logEntryCollection->getItems() as $logEntry) {
|
||||
$logEntries[] = $this->getById((int)$logEntry->getId());
|
||||
}
|
||||
$searchResults->setItems($logEntries);
|
||||
|
||||
return $searchResults;
|
||||
}
|
||||
|
||||
public function clean(?int $period = null): void
|
||||
{
|
||||
$connection = $this->logEntryResource->getConnection();
|
||||
$tableName = $this->logEntryResource->getMainTable();
|
||||
|
||||
if ($period === null) {
|
||||
$connection->delete($tableName);
|
||||
} else {
|
||||
$time = '-' . $period . ' days';
|
||||
$connection->delete(
|
||||
$tableName,
|
||||
[LogEntry::DATE . ' < ?' => $this->dateTime->gmtDate('Y-m-d H:i:s', $time)]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function cleanByStoreIds(?array $storeIds = []): void
|
||||
{
|
||||
$connection = $this->logEntryResource->getConnection();
|
||||
$tableName = $this->logEntryResource->getMainTable();
|
||||
|
||||
$connection->delete(
|
||||
$tableName,
|
||||
[LogEntry::STORE_ID . ' IN (?)' => $storeIds]
|
||||
);
|
||||
}
|
||||
|
||||
private function getLogDetails(int $logEntryId): array
|
||||
{
|
||||
/** @var ResourceModel\LogDetailCollection $collection */
|
||||
$collection = $this->logDetailCollectionFactory->create();
|
||||
$collection->addFieldToFilter(LogDetailModel::LOG_ID, $logEntryId);
|
||||
|
||||
return $collection->getItems();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function that adds a FilterGroup to the collection.
|
||||
*
|
||||
* @param FilterGroup $filterGroup
|
||||
* @param ResourceModel\Collection $logEntryCollection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function addFilterGroupToCollection(
|
||||
FilterGroup $filterGroup,
|
||||
ResourceModel\Collection $logEntryCollection
|
||||
): void {
|
||||
foreach ($filterGroup->getFilters() as $filter) {
|
||||
$condition = $filter->getConditionType() ? $filter->getConditionType() : 'eq';
|
||||
$logEntryCollection->addFieldToFilter($filter->getField(), [$condition => $filter->getValue()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function that adds a SortOrder to the collection.
|
||||
*
|
||||
* @param SortOrder[] $sortOrders
|
||||
* @param ResourceModel\Collection $logEntryCollection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function addOrderToCollection(
|
||||
array $sortOrders,
|
||||
ResourceModel\Collection $logEntryCollection
|
||||
): void {
|
||||
foreach ($sortOrders as $sortOrder) {
|
||||
$field = $sortOrder->getField();
|
||||
$logEntryCollection->addOrder(
|
||||
$field,
|
||||
($sortOrder->getDirection() == SortOrder::SORT_DESC) ? 'DESC' : 'ASC'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Model\LogEntry\ResourceModel;
|
||||
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry as LogEntryModel;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\ResourceModel\LogEntry as LogEntryResource;
|
||||
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
|
||||
|
||||
class Collection extends AbstractCollection
|
||||
{
|
||||
public function _construct()
|
||||
{
|
||||
$this->_init(LogEntryModel::class, LogEntryResource::class);
|
||||
$this->_setIdFieldName($this->getResource()->getIdFieldName());
|
||||
}
|
||||
}
|
||||
+44
@@ -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\Model\LogEntry\ResourceModel\Grid;
|
||||
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\ResourceModel\LogEntry as LogEntryResource;
|
||||
use Magento\Framework\View\Element\UiComponent\DataProvider\Document;
|
||||
use Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult;
|
||||
|
||||
class Collection extends SearchResult
|
||||
{
|
||||
public const ADMIN_TABLE_ALIAS = 'amasty_admin_user';
|
||||
public const FULL_NAME_EXPR = "CONCAT(amasty_admin_user.firstname, ' ' ,amasty_admin_user.lastname)";
|
||||
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(Document::class, LogEntryResource::class);
|
||||
$this->setMainTable(LogEntryResource::TABLE_NAME);
|
||||
$this->addFilterToMap('full_name', new \Zend_Db_Expr(self::FULL_NAME_EXPR));
|
||||
$this->addFilterToMap('username', 'main_table.username');
|
||||
}
|
||||
|
||||
protected function _initSelect()
|
||||
{
|
||||
parent::_initSelect();
|
||||
$this->getSelect()->joinLeft(
|
||||
[self::ADMIN_TABLE_ALIAS => $this->getTable('admin_user')],
|
||||
'main_table.username = ' . self::ADMIN_TABLE_ALIAS . '.username',
|
||||
[
|
||||
'full_name' => new \Zend_Db_Expr(self::FULL_NAME_EXPR),
|
||||
'email' => self::ADMIN_TABLE_ALIAS . '.email',
|
||||
]
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -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\Model\LogEntry\ResourceModel;
|
||||
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogDetail as LogDetailModel;
|
||||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
|
||||
|
||||
class LogDetail extends AbstractDb
|
||||
{
|
||||
public const TABLE_NAME = 'amasty_audit_log_details';
|
||||
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(self::TABLE_NAME, LogDetailModel::ID);
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Model\LogEntry\ResourceModel;
|
||||
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogDetail as LogDetailModel;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\ResourceModel\LogDetail as LogDetailResource;
|
||||
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
|
||||
|
||||
class LogDetailCollection extends AbstractCollection
|
||||
{
|
||||
public function _construct()
|
||||
{
|
||||
$this->_init(LogDetailModel::class, LogDetailResource::class);
|
||||
$this->_setIdFieldName($this->getResource()->getIdFieldName());
|
||||
}
|
||||
}
|
||||
@@ -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\Model\LogEntry\ResourceModel;
|
||||
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry as LogEntryModel;
|
||||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
|
||||
|
||||
class LogEntry extends AbstractDb
|
||||
{
|
||||
public const TABLE_NAME = 'amasty_audit_log_entry';
|
||||
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(self::TABLE_NAME, LogEntryModel::ID);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user