ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -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\Setup\Operation;
|
||||
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
|
||||
class TableDataMigrator
|
||||
{
|
||||
public function migrateData(
|
||||
ModuleDataSetupInterface $setup,
|
||||
string $tableFrom,
|
||||
string $tableTo,
|
||||
array $mapFields = []
|
||||
): void {
|
||||
if ($setup->tableExists($tableFrom) && $setup->tableExists($tableTo)) {
|
||||
$connection = $setup->getConnection();
|
||||
$tableFrom = $setup->getTable($tableFrom);
|
||||
$tableTo = $setup->getTable($tableTo);
|
||||
$fields = [];
|
||||
foreach ($connection->describeTable($tableFrom) as $columnName => $columnConfig) {
|
||||
$columnName = strtolower($columnName);
|
||||
$alias = $mapFields[$columnName] ?? $columnName;
|
||||
$fields[$alias] = $columnName;
|
||||
}
|
||||
|
||||
$sourceFields = array_keys($fields);
|
||||
$targetFields = array_map('strtolower', array_keys($connection->describeTable($tableTo)));
|
||||
if (array_diff($sourceFields, $targetFields)) {
|
||||
throw new \RuntimeException('Invalid data source to migrate.');
|
||||
}
|
||||
|
||||
$select = $connection->select()->from($tableFrom, $fields);
|
||||
$connection->query(
|
||||
$connection->insertFromSelect($select, $tableTo, $sourceFields)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+64
@@ -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\Setup\Patch\Data;
|
||||
|
||||
use Amasty\AdminActionsLog\Model\ActiveSession\ResourceModel\ActiveSession as ActiveSessionResource;
|
||||
use Amasty\AdminActionsLog\Setup\Operation\TableDataMigrator;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Framework\Setup\Patch\DataPatchInterface;
|
||||
|
||||
class MigrateActiveSessionsData implements DataPatchInterface
|
||||
{
|
||||
public const OLD_TABLE_NAME = 'amasty_audit_active';
|
||||
|
||||
/**
|
||||
* @var ModuleDataSetupInterface
|
||||
*/
|
||||
private $moduleDataSetup;
|
||||
|
||||
/**
|
||||
* @var TableDataMigrator
|
||||
*/
|
||||
private $tableDataMigrator;
|
||||
|
||||
public function __construct(
|
||||
ModuleDataSetupInterface $moduleDataSetup,
|
||||
TableDataMigrator $tableDataMigrator
|
||||
) {
|
||||
$this->moduleDataSetup = $moduleDataSetup;
|
||||
$this->tableDataMigrator = $tableDataMigrator;
|
||||
}
|
||||
|
||||
public function apply()
|
||||
{
|
||||
$this->moduleDataSetup->startSetup();
|
||||
$this->tableDataMigrator->migrateData(
|
||||
$this->moduleDataSetup,
|
||||
self::OLD_TABLE_NAME,
|
||||
ActiveSessionResource::TABLE_NAME,
|
||||
[
|
||||
'date_time' => 'session_start',
|
||||
'name' => 'full_name'
|
||||
]
|
||||
);
|
||||
$this->moduleDataSetup->endSetup();
|
||||
}
|
||||
|
||||
public static function getDependencies()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAliases()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
<?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\Setup\Patch\Data;
|
||||
|
||||
use Amasty\AdminActionsLog\Model\ConfigProvider;
|
||||
use Magento\Framework\App\Area;
|
||||
use Magento\Framework\App\Config\ConfigResource\ConfigInterface;
|
||||
use Magento\Framework\App\State;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Setup\Patch\DataPatchInterface;
|
||||
|
||||
class MigrateConfigData implements DataPatchInterface
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $changedConfigFields = [
|
||||
'log/log_enable_visit_history' => ConfigProvider::LOG_ENABLE_VISIT_HISTORY,
|
||||
'log/log_all_admins' => ConfigProvider::LOG_ALL_ADMINS,
|
||||
'log/log_admin_users' => ConfigProvider::LOG_ADMIN_USERS,
|
||||
'log/log_delete_logs_after_days' => ConfigProvider::ACTIONS_LOG_PERIOD,
|
||||
'log/log_delete_login_attempts_after_days' => ConfigProvider::LOGIN_ATTEMPTS_LOG_PERIOD,
|
||||
'log/log_delete_pages_history_after_days' => ConfigProvider::VISIT_HISTORY_LOG_PERIOD,
|
||||
'geolocation/geolocation_enable' => ConfigProvider::GEOLOCATION_ENABLE,
|
||||
'restore/restore_popup_message' => ConfigProvider::RESTORE_POPUP_MESSAGE,
|
||||
'successful_log_mailing/enabled' => ConfigProvider::SUCCESSFUL_LOG_MAILING_ENABLED,
|
||||
'successful_log_mailing/template' => ConfigProvider::SUCCESSFUL_LOG_MAILING_TEMPLATE,
|
||||
'successful_log_mailing/send_to_mail' => ConfigProvider::SUCCESSFUL_LOG_MAILING_SEND_TO,
|
||||
'unsuccessful_log_mailing/enabled' => ConfigProvider::UNSUCCESSFUL_LOG_MAILING_ENABLED,
|
||||
'unsuccessful_log_mailing/template' => ConfigProvider::UNSUCCESSFUL_LOG_MAILING_TEMPLATE,
|
||||
'unsuccessful_log_mailing/send_to_mail' => ConfigProvider::UNSUCCESSFUL_LOG_MAILING_SEND_TO,
|
||||
'suspicious_log_mailing/enabled' => ConfigProvider::SUSPICIOUS_LOG_MAILING_ENABLED,
|
||||
'suspicious_log_mailing/template' => ConfigProvider::SUSPICIOUS_LOG_MAILING_TEMPLATE,
|
||||
'suspicious_log_mailing/send_to_mail' => ConfigProvider::SUSPICIOUS_LOG_MAILING_SEND_TO
|
||||
];
|
||||
|
||||
/**
|
||||
* @var State
|
||||
*/
|
||||
private $appState;
|
||||
|
||||
/**
|
||||
* @var ConfigInterface
|
||||
*/
|
||||
private $resourceConfig;
|
||||
|
||||
public function __construct(
|
||||
State $appState,
|
||||
ConfigInterface $resourceConfig
|
||||
) {
|
||||
$this->appState = $appState;
|
||||
$this->resourceConfig = $resourceConfig;
|
||||
}
|
||||
|
||||
public function apply()
|
||||
{
|
||||
$this->appState->emulateAreaCode(Area::AREA_ADMINHTML, [$this, 'updateConfig']);
|
||||
}
|
||||
|
||||
public static function getDependencies()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAliases()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Update config patches
|
||||
*/
|
||||
public function updateConfig(): void
|
||||
{
|
||||
foreach ($this->changedConfigFields as $oldPath => $newPath) {
|
||||
$oldPathData = $this->getConfigValues($oldPath);
|
||||
|
||||
if (!$oldPathData) {
|
||||
continue;
|
||||
}
|
||||
foreach ($oldPathData as $record) {
|
||||
$this->changeConfigData($oldPath, $record);
|
||||
|
||||
$this->resourceConfig->saveConfig(
|
||||
'amaudit/' . $newPath,
|
||||
$record['value'],
|
||||
$record['scope'],
|
||||
$record['scope_id']
|
||||
);
|
||||
$this->resourceConfig->deleteConfig(
|
||||
$record['path'],
|
||||
$record['scope'],
|
||||
$record['scope_id']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*
|
||||
* @return array
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
private function getConfigValues(string $path): array
|
||||
{
|
||||
$connection = $this->resourceConfig->getConnection();
|
||||
$select = $connection->select()->from(
|
||||
$this->resourceConfig->getMainTable()
|
||||
)->where(
|
||||
'path = ?',
|
||||
'amaudit/' . $path
|
||||
);
|
||||
|
||||
return $connection->fetchAll($select);
|
||||
}
|
||||
|
||||
private function changeConfigData($oldPath, &$record): void
|
||||
{
|
||||
switch ($oldPath) {
|
||||
case 'successful_log_mailing/template':
|
||||
case 'unsuccessful_log_mailing/template':
|
||||
case 'suspicious_log_mailing/template':
|
||||
if ($record['value'] == 'amaudit_successful_log_mailing_template') {
|
||||
$record['value'] = 'amaudit_email_notifications_successful_log_mailing_template';
|
||||
}
|
||||
if ($record['value'] == 'amaudit_unsuccessful_log_mailing_template') {
|
||||
$record['value'] = 'amaudit_email_notifications_unsuccessful_log_mailing_template';
|
||||
}
|
||||
if ($record['value'] == 'amaudit_suspicious_log_mailing_template') {
|
||||
$record['value'] = 'amaudit_email_notifications_suspicious_log_mailing_template';
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
<?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\Setup\Patch\Data;
|
||||
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\ResourceModel\LogEntry as LogEntryResource;
|
||||
use Amasty\AdminActionsLog\Model\OptionSource\LogEntryTypes;
|
||||
use Magento\Framework\Module\ResourceInterface;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Framework\Setup\Patch\DataPatchInterface;
|
||||
|
||||
class MigrateLogData implements DataPatchInterface
|
||||
{
|
||||
/**
|
||||
* @var ModuleDataSetupInterface
|
||||
*/
|
||||
private $moduleDataSetup;
|
||||
|
||||
/**
|
||||
* @var ResourceInterface
|
||||
*/
|
||||
private $moduleResource;
|
||||
|
||||
/**
|
||||
* @var LogEntryTypes
|
||||
*/
|
||||
private $logEntryTypes;
|
||||
|
||||
public function __construct(
|
||||
ModuleDataSetupInterface $moduleDataSetup,
|
||||
ResourceInterface $moduleResource,
|
||||
LogEntryTypes $logEntryTypes
|
||||
) {
|
||||
$this->moduleDataSetup = $moduleDataSetup;
|
||||
$this->moduleResource = $moduleResource;
|
||||
$this->logEntryTypes = $logEntryTypes;
|
||||
}
|
||||
|
||||
public function apply()
|
||||
{
|
||||
$setupDataVersion = (string)$this->moduleResource->getDataVersion('Amasty_AdminActionsLog');
|
||||
if ($setupDataVersion && version_compare($setupDataVersion, '2.0.0', '<')) {
|
||||
$this->migrateLogTypes();
|
||||
$this->migrateCategories();
|
||||
$this->migrateExportTypes();
|
||||
}
|
||||
}
|
||||
|
||||
public static function getDependencies()
|
||||
{
|
||||
return [
|
||||
MigrateLogEntryData::class
|
||||
];
|
||||
}
|
||||
|
||||
public function getAliases()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
private function migrateExportTypes(): void
|
||||
{
|
||||
$tableName = $this->moduleDataSetup->getTable(LogEntryResource::TABLE_NAME);
|
||||
$oldExportTypes = ['exportCsv', 'exportXml'];
|
||||
|
||||
foreach ($oldExportTypes as $oldExportType) {
|
||||
$this->moduleDataSetup->getConnection()->update(
|
||||
$tableName,
|
||||
[LogEntry::TYPE => 'export'],
|
||||
[LogEntry::TYPE . ' = ?' => $oldExportType]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function migrateCategories(): void
|
||||
{
|
||||
$tableName = $this->moduleDataSetup->getTable(LogEntryResource::TABLE_NAME);
|
||||
$categoriesMapping = [
|
||||
'catalog/product' => [
|
||||
LogEntry::CATEGORY => 'catalog/product/edit',
|
||||
LogEntry::CATEGORY_NAME => __('Catalog Product'),
|
||||
LogEntry::PARAMETER_NAME => 'id'
|
||||
],
|
||||
'customer' => [
|
||||
LogEntry::CATEGORY => 'customer/index/edit',
|
||||
LogEntry::CATEGORY_NAME => __('Customer'),
|
||||
LogEntry::PARAMETER_NAME => 'id'
|
||||
],
|
||||
'customer/index' => [
|
||||
LogEntry::CATEGORY => 'customer/index/edit',
|
||||
LogEntry::CATEGORY_NAME => __('Customer'),
|
||||
LogEntry::PARAMETER_NAME => 'id'
|
||||
],
|
||||
'customer/group' => [
|
||||
LogEntry::CATEGORY => 'customer/group/edit',
|
||||
LogEntry::CATEGORY_NAME => __('Customer Group'),
|
||||
LogEntry::PARAMETER_NAME => 'id'
|
||||
],
|
||||
'catalog/product_attribute' => [
|
||||
LogEntry::CATEGORY => 'catalog/product_attribute/edit',
|
||||
LogEntry::CATEGORY_NAME => __('Product Attribute'),
|
||||
LogEntry::PARAMETER_NAME => 'attribute_id'
|
||||
],
|
||||
'sales/order_create' => [
|
||||
LogEntry::CATEGORY => 'sales/order/view',
|
||||
LogEntry::CATEGORY_NAME => __('Order'),
|
||||
LogEntry::PARAMETER_NAME => 'order_id'
|
||||
],
|
||||
'sales/order' => [
|
||||
LogEntry::CATEGORY => 'sales/order/view',
|
||||
LogEntry::CATEGORY_NAME => __('Order'),
|
||||
LogEntry::PARAMETER_NAME => 'order_id'
|
||||
],
|
||||
'admin/order_shipment' => [
|
||||
LogEntry::CATEGORY => 'sales/shipment/view',
|
||||
LogEntry::CATEGORY_NAME => __('Shipment'),
|
||||
LogEntry::PARAMETER_NAME => 'shipment_id'
|
||||
],
|
||||
'admin/order_creditmemo' => [
|
||||
LogEntry::CATEGORY => 'sales/creditmemo/view',
|
||||
LogEntry::CATEGORY_NAME => __('Credit Memo'),
|
||||
LogEntry::PARAMETER_NAME => 'creditmemo_id'
|
||||
],
|
||||
'admin/order_invoice' => [
|
||||
LogEntry::CATEGORY => 'sales/invoice/view',
|
||||
LogEntry::CATEGORY_NAME => __('Invoice'),
|
||||
LogEntry::PARAMETER_NAME => 'invoice_id'
|
||||
],
|
||||
'catalog_rule/promo_catalog' => [
|
||||
LogEntry::CATEGORY => 'catalog_rule/promo_catalog/edit',
|
||||
LogEntry::CATEGORY_NAME => __('Catalog Price Rule'),
|
||||
LogEntry::PARAMETER_NAME => 'id'
|
||||
]
|
||||
];
|
||||
|
||||
foreach ($categoriesMapping as $origCategory => $dataToUpdate) {
|
||||
$this->moduleDataSetup->getConnection()->update(
|
||||
$tableName,
|
||||
$dataToUpdate,
|
||||
[LogEntry::CATEGORY . ' = ?' => $origCategory]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function migrateLogTypes(): void
|
||||
{
|
||||
$tableName = $this->moduleDataSetup->getTable(LogEntryResource::TABLE_NAME);
|
||||
|
||||
foreach ($this->logEntryTypes->toArray() as $typeKey => $typeLabel) {
|
||||
$this->moduleDataSetup->getConnection()->update(
|
||||
$tableName,
|
||||
[LogEntry::TYPE => $typeKey],
|
||||
[LogEntry::TYPE . ' = ?' => (string)$typeLabel]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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\Setup\Patch\Data;
|
||||
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\ResourceModel\LogEntry as LogEntryResource;
|
||||
use Amasty\AdminActionsLog\Setup\Operation\TableDataMigrator;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Framework\Setup\Patch\DataPatchInterface;
|
||||
|
||||
class MigrateLogEntryData implements DataPatchInterface
|
||||
{
|
||||
public const OLD_TABLE_NAME = 'amasty_audit_log';
|
||||
|
||||
/**
|
||||
* @var ModuleDataSetupInterface
|
||||
*/
|
||||
private $moduleDataSetup;
|
||||
|
||||
/**
|
||||
* @var TableDataMigrator
|
||||
*/
|
||||
private $tableDataMigrator;
|
||||
|
||||
public function __construct(
|
||||
ModuleDataSetupInterface $moduleDataSetup,
|
||||
TableDataMigrator $tableDataMigrator
|
||||
) {
|
||||
$this->moduleDataSetup = $moduleDataSetup;
|
||||
$this->tableDataMigrator = $tableDataMigrator;
|
||||
}
|
||||
|
||||
public function apply()
|
||||
{
|
||||
$this->moduleDataSetup->startSetup();
|
||||
$this->tableDataMigrator->migrateData(
|
||||
$this->moduleDataSetup,
|
||||
self::OLD_TABLE_NAME,
|
||||
LogEntryResource::TABLE_NAME,
|
||||
[
|
||||
'date_time' => 'date',
|
||||
'parametr_name' => 'parameter_name'
|
||||
]
|
||||
);
|
||||
$this->moduleDataSetup->endSetup();
|
||||
}
|
||||
|
||||
public static function getDependencies()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAliases()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?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\Setup\Patch\Data;
|
||||
|
||||
use Amasty\AdminActionsLog\Model\VisitHistoryEntry\ResourceModel\VisitHistoryEntry as VisitHistoryEntryResource;
|
||||
use Amasty\AdminActionsLog\Setup\Operation\TableDataMigrator;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Framework\Setup\Patch\DataPatchInterface;
|
||||
|
||||
class MigrateVisitEntryData implements DataPatchInterface
|
||||
{
|
||||
public const OLD_TABLE_NAME = 'amasty_audit_visit';
|
||||
|
||||
/**
|
||||
* @var ModuleDataSetupInterface
|
||||
*/
|
||||
private $moduleDataSetup;
|
||||
|
||||
/**
|
||||
* @var TableDataMigrator
|
||||
*/
|
||||
private $tableDataMigrator;
|
||||
|
||||
public function __construct(
|
||||
ModuleDataSetupInterface $moduleDataSetup,
|
||||
TableDataMigrator $tableDataMigrator
|
||||
) {
|
||||
$this->moduleDataSetup = $moduleDataSetup;
|
||||
$this->tableDataMigrator = $tableDataMigrator;
|
||||
}
|
||||
|
||||
public function apply()
|
||||
{
|
||||
$this->moduleDataSetup->startSetup();
|
||||
$this->tableDataMigrator->migrateData(
|
||||
$this->moduleDataSetup,
|
||||
self::OLD_TABLE_NAME,
|
||||
VisitHistoryEntryResource::TABLE_NAME,
|
||||
[
|
||||
'name' => 'full_name'
|
||||
]
|
||||
);
|
||||
$this->moduleDataSetup->endSetup();
|
||||
}
|
||||
|
||||
public static function getDependencies()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAliases()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
+53
@@ -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\Setup\Patch\Data;
|
||||
|
||||
use Amasty\AdminActionsLog\Logging\Entity\SaveHandler\Sales\Shipment;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\LogEntry as LogEntryModel;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\ResourceModel\LogEntry as LogEntryResource;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Framework\Setup\Patch\DataPatchInterface;
|
||||
|
||||
class UpdateCategoryForShipmentRecords implements DataPatchInterface
|
||||
{
|
||||
/**
|
||||
* @var ModuleDataSetupInterface
|
||||
*/
|
||||
private $moduleDataSetup;
|
||||
|
||||
public function __construct(
|
||||
ModuleDataSetupInterface $moduleDataSetup
|
||||
) {
|
||||
$this->moduleDataSetup = $moduleDataSetup;
|
||||
}
|
||||
|
||||
public static function getDependencies(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAliases(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function apply(): self
|
||||
{
|
||||
$tableName = $this->moduleDataSetup->getTable(LogEntryResource::TABLE_NAME);
|
||||
$this->moduleDataSetup->getConnection()->update(
|
||||
$tableName,
|
||||
[LogEntryModel::CATEGORY => Shipment::CATEGORY],
|
||||
[LogEntryModel::CATEGORY . ' = ?' => 'sales/order_shipment/view']
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
<?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\Setup;
|
||||
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\ResourceModel\LogDetail as LogDetailResource;
|
||||
use Amasty\AdminActionsLog\Model\VisitHistoryEntry\ResourceModel\VisitHistoryDetail as VisitHistoryDetailResource;
|
||||
use Amasty\AdminActionsLog\Setup\Patch\Data\MigrateActiveSessionsData;
|
||||
use Amasty\AdminActionsLog\Setup\Patch\Data\MigrateLogEntryData;
|
||||
use Amasty\AdminActionsLog\Setup\Patch\Data\MigrateVisitEntryData;
|
||||
use Magento\Framework\FlagManager;
|
||||
use Magento\Framework\Setup\InstallDataInterface;
|
||||
use Magento\Framework\Setup\ModuleContextInterface;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Framework\Setup\Patch\PatchHistory;
|
||||
|
||||
class RecurringData implements InstallDataInterface
|
||||
{
|
||||
private const FLAG_CODE = 'amasty_audit_upg_to_210';
|
||||
|
||||
/**
|
||||
* @var PatchHistory
|
||||
*/
|
||||
private $patchHistory;
|
||||
|
||||
/**
|
||||
* @var FlagManager
|
||||
*/
|
||||
private $flagManager;
|
||||
|
||||
public function __construct(
|
||||
PatchHistory $patchHistory,
|
||||
FlagManager $flagManager
|
||||
) {
|
||||
$this->patchHistory = $patchHistory;
|
||||
$this->flagManager = $flagManager;
|
||||
}
|
||||
|
||||
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
|
||||
{
|
||||
$setup->startSetup();
|
||||
if (!$this->flagManager->getFlagData(self::FLAG_CODE)) {
|
||||
if ($this->removeTables($setup)) {
|
||||
$this->flagManager->saveFlag(self::FLAG_CODE, true);
|
||||
}
|
||||
}
|
||||
|
||||
$setup->endSetup();
|
||||
}
|
||||
|
||||
private function removeTables(ModuleDataSetupInterface $setup): bool
|
||||
{
|
||||
$tablesToDrop = [
|
||||
MigrateActiveSessionsData::OLD_TABLE_NAME => [
|
||||
'patchName' => MigrateActiveSessionsData::class,
|
||||
'refTable' => ''
|
||||
],
|
||||
MigrateLogEntryData::OLD_TABLE_NAME => [
|
||||
'patchName' => MigrateLogEntryData::class,
|
||||
'refTable' => LogDetailResource::TABLE_NAME
|
||||
],
|
||||
MigrateVisitEntryData::OLD_TABLE_NAME => [
|
||||
'patchName' => MigrateVisitEntryData::class,
|
||||
'refTable' => VisitHistoryDetailResource::TABLE_NAME
|
||||
]
|
||||
];
|
||||
$connection = $setup->getConnection();
|
||||
foreach ($tablesToDrop as $table => &$info) {
|
||||
if ($this->patchHistory->isApplied($info['patchName'])) {
|
||||
$tableName = $setup->getTable($table);
|
||||
if ($setup->tableExists($table)) {
|
||||
$connection->dropTable($tableName);
|
||||
$this->dropForeignKeys($setup, $info['refTable'], $tableName);
|
||||
}
|
||||
|
||||
unset($tablesToDrop[$table]);
|
||||
}
|
||||
}
|
||||
|
||||
return empty($tablesToDrop);
|
||||
}
|
||||
|
||||
private function dropForeignKeys(ModuleDataSetupInterface $setup, string $tableName, string $refTable)
|
||||
{
|
||||
if ($tableName && $setup->tableExists($tableName)) {
|
||||
$connection = $setup->getConnection();
|
||||
foreach ($connection->getForeignKeys($setup->getTable($tableName)) as $keyInfo) {
|
||||
if ($keyInfo['REF_TABLE_NAME'] === $refTable) {
|
||||
$connection->dropForeignKey($keyInfo['TABLE_NAME'], $keyInfo['FK_NAME']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
<?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\Setup;
|
||||
|
||||
use Amasty\AdminActionsLog\Model\ActiveSession\ResourceModel\ActiveSession;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\ResourceModel\LogDetail;
|
||||
use Amasty\AdminActionsLog\Model\LogEntry\ResourceModel\LogEntry;
|
||||
use Amasty\AdminActionsLog\Model\LoginAttempt\ResourceModel\LoginAttempt;
|
||||
use Amasty\AdminActionsLog\Model\VisitHistoryEntry\ResourceModel\VisitHistoryDetail;
|
||||
use Amasty\AdminActionsLog\Model\VisitHistoryEntry\ResourceModel\VisitHistoryEntry;
|
||||
use Magento\Framework\Setup\ModuleContextInterface;
|
||||
use Magento\Framework\Setup\SchemaSetupInterface;
|
||||
use Magento\Framework\Setup\UninstallInterface;
|
||||
|
||||
class Uninstall implements UninstallInterface
|
||||
{
|
||||
public function uninstall(SchemaSetupInterface $setup, ModuleContextInterface $context)
|
||||
{
|
||||
$setup->startSetup();
|
||||
$this->uninstallTables($setup)
|
||||
->uninstallConfigData($setup)
|
||||
->uninstallFlagData($setup)
|
||||
->removeEmailTemplates($setup);
|
||||
$setup->endSetup();
|
||||
}
|
||||
|
||||
private function uninstallTables(SchemaSetupInterface $setup): self
|
||||
{
|
||||
$tablesToDrop = [
|
||||
LoginAttempt::TABLE_NAME,
|
||||
VisitHistoryDetail::TABLE_NAME,
|
||||
VisitHistoryEntry::TABLE_NAME,
|
||||
ActiveSession::TABLE_NAME,
|
||||
LogDetail::TABLE_NAME,
|
||||
LogEntry::TABLE_NAME
|
||||
];
|
||||
foreach ($tablesToDrop as $table) {
|
||||
$setup->getConnection()->dropTable(
|
||||
$setup->getTable($table)
|
||||
);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function uninstallConfigData(SchemaSetupInterface $setup): self
|
||||
{
|
||||
$setup->getConnection()->delete(
|
||||
$setup->getTable('core_config_data'),
|
||||
"`path` LIKE 'amaudit%'"
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function uninstallFlagData(SchemaSetupInterface $setup): self
|
||||
{
|
||||
$setup->getConnection()->delete(
|
||||
$setup->getTable('flag'),
|
||||
'`flag_code` LIKE \'amasty_audit_%\''
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function removeEmailTemplates(SchemaSetupInterface $setup): self
|
||||
{
|
||||
$setup->getConnection()->delete(
|
||||
$setup->getTable('email_template'),
|
||||
'`orig_template_code` LIKE \'amaudit_%\''
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user