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,126 @@
<?php
/**
* @package Plumrocket_CookieConsent
* @copyright Copyright (c) 2024 Plumrocket Inc. (https://plumrocket.com)
* @license https://plumrocket.com/license/ End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\CookieConsent\Setup\Patch\Data;
use Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Plumrocket\CookieConsent\Helper\Config;
/**
* @since 1.11.2
*/
class AddV2ConsentTypesForOldClients implements DataPatchInterface
{
private const GTM_V2_CONSENT_TYPES = [
'item6' => [
'consent_type' => 'ad_user_data',
'status' => 'denied',
'cookie_category' => 'marketing'
],
'item7' => [
'consent_type' => 'ad_personalization',
'status' => 'denied',
'cookie_category' => 'marketing'
]
];
/**
* @var \Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory
*/
private $configDataCollectionFactory;
/**
* @var \Magento\Framework\Serialize\Serializer\Json
*/
private $jsonSerializer;
/**
* @var \Magento\Framework\App\Config\Storage\WriterInterface
*/
private $configWriter;
/**
* @param \Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory $configDataCollectionFactory
* @param \Magento\Framework\App\Config\Storage\WriterInterface $configWriter
* @param \Magento\Framework\Serialize\Serializer\Json $jsonSerializer
*/
public function __construct(
CollectionFactory $configDataCollectionFactory,
WriterInterface $configWriter,
Json $jsonSerializer
) {
$this->configDataCollectionFactory = $configDataCollectionFactory;
$this->jsonSerializer = $jsonSerializer;
$this->configWriter = $configWriter;
}
/**
* @inheritdoc
*/
public function apply()
{
/** @var \Magento\Config\Model\ResourceModel\Config\Data\Collection $configDataCollection */
$configDataCollection = $this->configDataCollectionFactory->create();
$configDataCollection->addFieldToFilter('path', Config::XML_PATH_GTM_CONSENT_TYPES);
/** @var \Magento\Framework\App\Config\Value $configData */
foreach ($configDataCollection as $configDataItem) {
if (! $this->shouldUpdateConfigValue($configDataItem->getValue())) {
continue;
}
$configDataItemValue = $this->jsonSerializer->unserialize($configDataItem->getValue());
foreach (self::GTM_V2_CONSENT_TYPES as $key => $defaultConfig) {
if (! isset($configDataItemValue[$key])) {
$configDataItemValue[$key] = $defaultConfig;
}
}
$this->configWriter->save(
Config::XML_PATH_GTM_CONSENT_TYPES,
$this->jsonSerializer->serialize($configDataItemValue),
$configDataItem->getScope(),
$configDataItem->getScopeId()
);
}
}
private function shouldUpdateConfigValue(string $currentValue): bool
{
$currentValue = $this->jsonSerializer->unserialize($currentValue);
foreach (array_keys(self::GTM_V2_CONSENT_TYPES) as $key) {
if (! isset($currentValue[$key])) {
return true;
}
}
return false;
}
/**
* @inheritdoc
*/
public static function getDependencies()
{
return [];
}
/**
* @inheritdoc
*/
public function getAliases()
{
return [];
}
}
@@ -0,0 +1,149 @@
<?php
/**
* @package Plumrocket_CookieConsent
* @copyright Copyright (c) 2022 Plumrocket Inc. (https://plumrocket.com)
* @license https://plumrocket.com/license/ End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\CookieConsent\Setup\Patch\Data;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Plumrocket\CookieConsent\Api\CategoryRepositoryInterface;
use Plumrocket\CookieConsent\Api\Data\CategoryInterfaceFactory;
use Plumrocket\CookieConsent\Model\Category\Attribute\Source\CategoryKey;
use Plumrocket\CookieConsent\Model\ResourceModel\Category\GetKeys;
/**
* @since 1.3.0
*/
class CreateDefaultCategories implements DataPatchInterface
{
/**
* @var \Plumrocket\CookieConsent\Api\CategoryRepositoryInterface
*/
private $categoryRepository;
/**
* @var \Plumrocket\CookieConsent\Api\Data\CategoryInterfaceFactory
*/
private $categoryFactory;
/**
* @var \Plumrocket\CookieConsent\Model\ResourceModel\Category\GetKeys
*/
private $getCreatedCategoriesKeys;
/**
* @param \Plumrocket\CookieConsent\Api\CategoryRepositoryInterface $categoryRepository
* @param \Plumrocket\CookieConsent\Api\Data\CategoryInterfaceFactory $categoryFactory
* @param \Plumrocket\CookieConsent\Model\ResourceModel\Category\GetKeys $getCreatedCategoriesKeys
*/
public function __construct(
CategoryRepositoryInterface $categoryRepository,
CategoryInterfaceFactory $categoryFactory,
GetKeys $getCreatedCategoriesKeys
) {
$this->categoryRepository = $categoryRepository;
$this->categoryFactory = $categoryFactory;
$this->getCreatedCategoriesKeys = $getCreatedCategoriesKeys;
}
/**
* @inheritdoc
*/
public function apply()
{
$createdCategoriesKeys = $this->getCreatedCategoriesKeys->execute();
foreach ($this->getCategories() as $categoryData) {
if (in_array($categoryData['key'], $createdCategoriesKeys, true)) {
continue;
}
/** @var \Plumrocket\CookieConsent\Api\Data\CategoryInterface $category */
$category = $this->categoryFactory->create();
$category->setName($categoryData['name']);
$category->setIsEssential($categoryData['isEssential']);
$category->setKey($categoryData['key']);
$category->setStatus(true);
$category->setSortOrder($categoryData['sortOrder']);
$category->setDescription($categoryData['description']);
$category->setStoreId(0); // save on default level
$this->categoryRepository->save($category);
}
}
/**
* Get default cookie categories settings
*
* @return array[]
*/
private function getCategories(): array
{
return [
[
'name' => 'Strictly necessary cookies',
'isEssential' => true,
'key' => CategoryKey::KEY_NECESSARY,
'sortOrder' => 0,
'description' => 'These cookies are essential for you to browse our store and use its features, ' .
'such as accessing secure areas of the website. Cookies that allow holding your cart items, ' .
'cookies that keep you logged-in and cookies that save your customized preferences are an ' .
'example of strictly necessary cookies. These cookies are essential to a website\'s ' .
'functionality and cannot be disabled by users.',
],
[
'name' => 'Preferences cookies',
'isEssential' => false,
'key' => CategoryKey::KEY_PREFERENCES,
'sortOrder' => 0,
'description' => 'Preferences cookies are also known as “functionality cookies”. These cookies ' .
'allow a website to remember choices you have made in the past, like what language you prefer, ' .
'your favourite search filters, or what your user name and password are so you can automatically ' .
'log in.',
],
[
'name' => 'Statistics cookies',
'isEssential' => false,
'key' => CategoryKey::KEY_STATISTICS,
'sortOrder' => 0,
'description' => 'Statistics cookies are also known as “performance cookies”. These cookies collect ' .
'information about how you use a website, like which pages you visited and which links you ' .
'clicked on. None of this information can be used to identify you. It is all aggregated and, ' .
'therefore, anonymized. Their sole purpose is to improve website functions. This includes ' .
'cookies from third-party analytics services, such as visitor analytics, heatmaps and social ' .
'media analytics.',
],
[
'name' => 'Marketing cookies',
'isEssential' => false,
'key' => CategoryKey::KEY_MARKETING,
'sortOrder' => 0,
'description' => 'These cookies track your online activity to help advertisers deliver more relevant ' .
'advertising or to limit how many times you see an ad. These cookies can share that information ' .
'with other organizations or advertisers. These are persistent cookies and almost always of ' .
'third-party provenance.',
],
];
}
/**
* @inheritdoc
*/
public static function getDependencies(): array
{
return [\Plumrocket\CookieConsent\Setup\Patch\Data\CreateEntities::class];
}
/**
* @inheritdoc
*/
public function getAliases(): array
{
return [];
}
}
@@ -0,0 +1,139 @@
<?php
/**
* @package Plumrocket_CookieConsent
* @copyright Copyright (c) 2022 Plumrocket Inc. (https://plumrocket.com)
* @license https://plumrocket.com/license/ End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\CookieConsent\Setup\Patch\Data;
use Magento\Eav\Model\Config as EavConfig;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
use Plumrocket\CookieConsent\Setup\Patch\Data\Entities\GetCategoryEntities;
use Plumrocket\CookieConsent\Setup\Patch\Data\Entities\GetCookieEntities;
/**
* @since 1.3.0
*/
class CreateEntities implements DataPatchInterface, PatchRevertableInterface
{
/**
* @var \Magento\Eav\Model\Config
*/
private $eavConfig;
/**
* @var \Magento\Framework\Setup\ModuleDataSetupInterface
*/
private $moduleDataSetup;
/**
* @var \Magento\Eav\Setup\EavSetupFactory
*/
private $eavSetupFactory;
/**
* @var \Plumrocket\CookieConsent\Setup\Patch\Data\Entities\GetCategoryEntities
*/
private $getCategoryEntities;
/**
* @var \Plumrocket\CookieConsent\Setup\Patch\Data\Entities\GetCookieEntities
*/
private $getCookieEntities;
/**
* @param \Magento\Eav\Model\Config $eavConfig
* @param \Magento\Eav\Setup\EavSetupFactory $eavSetupFactory
* @param \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup
* @param \Plumrocket\CookieConsent\Setup\Patch\Data\Entities\GetCategoryEntities $getCategoryEntities
* @param \Plumrocket\CookieConsent\Setup\Patch\Data\Entities\GetCookieEntities $getCookieEntities
*/
public function __construct(
EavConfig $eavConfig,
EavSetupFactory $eavSetupFactory,
ModuleDataSetupInterface $moduleDataSetup,
GetCategoryEntities $getCategoryEntities,
GetCookieEntities $getCookieEntities
) {
$this->eavConfig = $eavConfig;
$this->moduleDataSetup = $moduleDataSetup;
$this->eavSetupFactory = $eavSetupFactory;
$this->getCategoryEntities = $getCategoryEntities;
$this->getCookieEntities = $getCookieEntities;
}
/**
* @inheritdoc
*/
public function apply()
{
$this->moduleDataSetup->getConnection()->startSetup();
/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
$eavSetup->installEntities($this->getCategoryEntities->execute());
$eavSetup->installEntities($this->getCookieEntities->execute());
$this->eavConfig->clear();
$this->moduleDataSetup->getConnection()->endSetup();
}
/**
* @inheritdoc
*/
public function revert()
{
$this->moduleDataSetup->getConnection()->startSetup();
/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
$this->removeEntities($eavSetup, $this->getCategoryEntities->execute());
$this->removeEntities($eavSetup, $this->getCookieEntities->execute());
$this->moduleDataSetup->getConnection()->endSetup();
}
/**
* Remove entities attributes and types
*
* @param \Magento\Eav\Setup\EavSetup $eavSetup
* @param array $entities
* @return void
*/
private function removeEntities(EavSetup $eavSetup, array $entities): void
{
foreach ($entities as $entityType => $entityData) {
// remove attributes
if (is_array($entityData['attributes']) && !empty($entityData['attributes'])) {
foreach ($entityData['attributes'] as $attrCode => $attr) {
$eavSetup->removeAttribute($entityType, $attrCode);
}
}
//remove Eav Entity Type
$eavSetup->removeEntityType($entityType);
}
}
/**
* @inheritdoc
*/
public static function getDependencies(): array
{
return [];
}
/**
* @inheritdoc
*/
public function getAliases(): array
{
return [];
}
}
@@ -0,0 +1,75 @@
<?php
/**
* @package Plumrocket_CookieConsent
* @copyright Copyright (c) 2022 Plumrocket Inc. (https://plumrocket.com)
* @license https://plumrocket.com/license/ End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\CookieConsent\Setup\Patch\Data;
use Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Plumrocket\CookieConsent\Helper\Config;
/**
* @since 1.5.0
*/
class DisableConsentModeForOldClients implements DataPatchInterface
{
/**
* @var \Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory
*/
private $configDataCollectionFactory;
/**
* @var \Magento\Framework\App\Config\Storage\WriterInterface
*/
private $configWriter;
/**
* @param \Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory $configDataCollectionFactory
* @param \Magento\Framework\App\Config\Storage\WriterInterface $configWriter
*/
public function __construct(
CollectionFactory $configDataCollectionFactory,
WriterInterface $configWriter
) {
$this->configDataCollectionFactory = $configDataCollectionFactory;
$this->configWriter = $configWriter;
}
/**
* @inheritdoc
*/
public function apply()
{
/** @var \Magento\Config\Model\ResourceModel\Config\Data\Collection $configDataCollection */
$configDataCollection = $this->configDataCollectionFactory->create();
$configDataCollection->addFieldToFilter('path', Config::XML_PATH_GTM_CONTAINER_ID);
$isGtmAlreadyEnabled = $configDataCollection->getSize();
if ($isGtmAlreadyEnabled) {
$this->configWriter->save(Config::XML_PATH_GTM_CONSENT_MODE_ENABLED, 0);
}
}
/**
* @inheritdoc
*/
public static function getDependencies(): array
{
return [];
}
/**
* @inheritdoc
*/
public function getAliases(): array
{
return [];
}
}
@@ -0,0 +1,151 @@
<?php
/**
* @package Plumrocket_CookieConsent
* @copyright Copyright (c) 2022 Plumrocket Inc. (https://plumrocket.com)
* @license https://plumrocket.com/license/ End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\CookieConsent\Setup\Patch\Data\Entities;
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
use Magento\Eav\Model\Entity\Attribute\Source\Boolean;
use Plumrocket\CookieConsent\Api\Data\CategoryInterface;
use Plumrocket\CookieConsent\Model\Category;
use Plumrocket\CookieConsent\Model\Eav\Attribute;
use Plumrocket\CookieConsent\Model\ResourceModel\Category\Attribute\Collection;
/**
* Get category entities data
*
* @since 1.3.0
*/
class GetCategoryEntities
{
/**
* Get category entity and attributes.
*
* @return array[]
*/
public function execute(): array
{
$categoryEntity = Category::ENTITY;
return [
$categoryEntity => [
'entity_model' => \Plumrocket\CookieConsent\Model\ResourceModel\Category::class,
'attribute_model' => Attribute::class,
'table' => \Plumrocket\CookieConsent\Model\ResourceModel\Category::MAIN_TABLE_NAME,
'additional_attribute_table' => Collection::EAV_ATTRIBUTE_ADDITIONAL_TABLE,
'entity_attribute_collection' => Collection::class,
'attributes' => [
CategoryInterface::STATUS => [
'type' => 'static',
'label' => 'Is Enabled?',
'required' => false,
'default' => 1,
'input' => 'boolean',
'source' => Boolean::class,
'sort_order' => 100,
'global' => ScopedAttributeInterface::SCOPE_GLOBAL,
'group' => 'General Information',
'note' => 'Indicates whether the category is visible on frontend.',
],
CategoryInterface::IS_ESSENTIAL => [
'type' => 'static',
'label' => 'Is Essential?',
'required' => false,
'default' => 0,
'input' => 'boolean',
'source' => Boolean::class,
'sort_order' => 200,
'global' => ScopedAttributeInterface::SCOPE_GLOBAL,
'group' => 'General Information',
'note' => 'If the cookie category is defined as "essential" then users will not be able to ' .
'disable it in the frontend. An example of essential cookies would be session cookies, ' .
'persistent cookies, shopping cart cookies, etc.',
],
CategoryInterface::NAME => [
'type' => 'text',
'label' => 'Name',
'required' => true,
'default' => '',
'input' => 'text',
'sort_order' => 300,
'global' => ScopedAttributeInterface::SCOPE_STORE,
'group' => 'General Information',
],
CategoryInterface::KEY => [
'type' => 'static',
'label' => 'Category Identifier',
'required' => true,
'input' => 'text',
'sort_order' => 400,
'global' => ScopedAttributeInterface::SCOPE_GLOBAL,
'group' => 'General Information',
],
CategoryInterface::DESCRIPTION => [
'type' => 'text',
'label' => 'Description',
'required' => false,
'default' => '',
'input' => 'textarea',
'sort_order' => 500,
'global' => ScopedAttributeInterface::SCOPE_STORE,
'group' => 'General Information',
],
CategoryInterface::SORT_ORDER => [
'type' => 'int',
'label' => 'Sort Order',
'required' => false,
'default' => 0,
'input' => 'text',
'sort_order' => 600,
'global' => ScopedAttributeInterface::SCOPE_STORE,
'group' => 'General Information',
'note' => 'Sort order is a category position in "Cookie Settings Panel".',
],
CategoryInterface::HEAD_SCRIPTS => [
'type' => 'text',
'label' => 'Head Scripts',
'required' => false,
'default' => '',
'input' => 'textarea',
'sort_order' => 700,
'global' => ScopedAttributeInterface::SCOPE_STORE,
'group' => 'General Information',
'note' => 'Scripts and HTML listed here will be included right after the opening <body> tag. ' .
'They will be executed if the corresponding cookie category is enabled by the customer.'
],
CategoryInterface::FOOTER_MISCELLANEOUS_HTML => [
'type' => 'text',
'label' => 'Footer Miscellaneous HTML',
'required' => false,
'default' => '',
'input' => 'textarea',
'sort_order' => 800,
'global' => ScopedAttributeInterface::SCOPE_STORE,
'group' => 'General Information',
'note' => 'Scripts and HTML listed here will be included right before the closing </body> ' .
'tag. They will be executed if the corresponding cookie category is enabled by the ' .
'customer.',
],
CategoryInterface::IS_PRE_CHECKED => [
'type' => 'int',
'label' => 'Is Pre-checked?',
'required' => false,
'default' => 0,
'input' => 'boolean',
'sort_order' => 250,
'global' => ScopedAttributeInterface::SCOPE_STORE,
'group' => 'General Information',
'note' => 'Indicates whether the category switcher is "ON" by default' .
' in the Cookie Settings Panel. Please note, the cookies from this category will be' .
' accepted only after the visitor confirms the choices.',
]
],
],
];
}
}
@@ -0,0 +1,114 @@
<?php
/**
* @package Plumrocket_CookieConsent
* @copyright Copyright (c) 2022 Plumrocket Inc. (https://plumrocket.com)
* @license https://plumrocket.com/license/ End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\CookieConsent\Setup\Patch\Data\Entities;
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
use Plumrocket\CookieConsent\Api\Data\CookieInterface;
use Plumrocket\CookieConsent\Model\Cookie;
use Plumrocket\CookieConsent\Model\Cookie\Attribute\Source\CategoryKey;
use Plumrocket\CookieConsent\Model\Cookie\Attribute\Source\Type as CookieType;
use Plumrocket\CookieConsent\Model\Eav\Attribute;
use Plumrocket\CookieConsent\Model\ResourceModel\Cookie\Attribute\Collection;
/**
* Get cookie entities data
*
* @since 1.3.0
*/
class GetCookieEntities
{
/**
* Get cookie entity and attributes.
*
* @return array[]
*/
public function execute(): array
{
$categoryEntity = Cookie::ENTITY;
return [
$categoryEntity => [
'entity_model' => \Plumrocket\CookieConsent\Model\ResourceModel\Cookie::class,
'attribute_model' => Attribute::class,
'table' => \Plumrocket\CookieConsent\Model\ResourceModel\Cookie::MAIN_TABLE_NAME,
'additional_attribute_table' => Collection::EAV_ATTRIBUTE_ADDITIONAL_TABLE,
'entity_attribute_collection' => Collection::class,
'attributes' => [
CookieInterface::NAME => [
'type' => 'static',
'label' => 'Name',
'required' => true,
'default' => '',
'input' => 'text',
'sort_order' => 100,
'global' => ScopedAttributeInterface::SCOPE_GLOBAL,
'group' => 'General Information',
],
CookieInterface::TYPE => [
'type' => 'static',
'label' => 'Type',
'required' => true,
'input' => 'select',
'source' => CookieType::class,
'sort_order' => 200,
'global' => ScopedAttributeInterface::SCOPE_GLOBAL,
'group' => 'General Information',
'note' => 'A first-party cookie is set by your Magento store. A third-party cookie is set by' .
' a third-party service, via code loaded on your website.',
],
CookieInterface::DOMAIN => [
'type' => 'static',
'label' => 'Domain',
'required' => true,
'default' => '',
'input' => 'text',
'sort_order' => 300,
'global' => ScopedAttributeInterface::SCOPE_GLOBAL,
'group' => 'General Information',
'note' => 'The domain for which the cookie is valid. If this attribute is not specified, ' .
'then the Magento base URL is used as the default value.',
],
CookieInterface::DURATION => [
'type' => 'static',
'label' => 'Duration',
'required' => true,
'default' => 0,
'input' => 'text',
'sort_order' => 400,
'global' => ScopedAttributeInterface::SCOPE_GLOBAL,
'group' => 'General Information',
'note' => 'Set the period when the cookie should expire. If set to 0, or omitted, the cookie ' .
'will expire at the end of the session (when the browser closes).',
],
CookieInterface::DESCRIPTION => [
'type' => 'text',
'label' => 'Description',
'required' => false,
'default' => '',
'input' => 'textarea',
'sort_order' => 500,
'global' => ScopedAttributeInterface::SCOPE_STORE,
'group' => 'General Information',
],
CookieInterface::CATEGORY_KEY => [
'type' => 'static',
'label' => 'Cookie Category',
'required' => true,
'input' => 'select',
'source' => CategoryKey::class,
'sort_order' => 600,
'global' => ScopedAttributeInterface::SCOPE_GLOBAL,
'group' => 'General Information',
],
],
],
];
}
}
@@ -0,0 +1,102 @@
<?php
/**
* @package Plumrocket_CookieConsent
* @copyright Copyright (c) 2022 Plumrocket Inc. (https://plumrocket.com)
* @license https://plumrocket.com/license/ End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\CookieConsent\Setup\Patch\Data;
use Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Plumrocket\CookieConsent\Helper\Config\CookieNotice as CookieNoticeConfig;
use Plumrocket\CookieConsent\Helper\Config\SettingsBar as SettingsBarConfig;
/**
* @since 1.3.0
*/
class MigrateConfigsFromGdpr implements DataPatchInterface
{
/**
* @var \Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory
*/
private $configDataCollectionFactory;
/**
* @param \Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory $configDataCollectionFactory
*/
public function __construct(
CollectionFactory $configDataCollectionFactory
) {
$this->configDataCollectionFactory = $configDataCollectionFactory;
}
/**
* @inheritdoc
*/
public function apply()
{
/** @var \Magento\Config\Model\ResourceModel\Config\Data\Collection $configDataCollection */
$configDataCollection = $this->configDataCollectionFactory->create();
$configDataCollection->addPathFilter('prgdpr/cookie_consent');
$mapping = [
'prgdpr/cookie_consent/geoip_restriction' => 'pr_cookie/main_settings/geo_targeting',
'prgdpr/cookie_consent/geoip_restriction_usa_ccpa' => 'pr_cookie/main_settings/geoip_restriction_usa_ccpa',
'prgdpr/cookie_consent/notice_text' => CookieNoticeConfig::XML_PATH_TEXT,
'prgdpr/cookie_consent/button_label' => [
CookieNoticeConfig::XML_PATH_ACCEPT_BUTTON_GROUP . '/label',
SettingsBarConfig::XML_PATH_ACCEPT_BUTTON_GROUP . '/label',
],
'prgdpr/cookie_consent/decline_button_label' => [
CookieNoticeConfig::XML_PATH_DECLINE_BUTTON_GROUP . '/label',
SettingsBarConfig::XML_PATH_DECLINE_BUTTON_GROUP . '/label',
],
];
/** @var \Magento\Framework\App\Config\Value $config */
foreach ($configDataCollection as $config) {
$oldPath = $config->getData('path');
if (! array_key_exists($oldPath, $mapping)) {
continue;
}
if (is_array($mapping[$oldPath])) {
$config->setData('path', $mapping[$oldPath][0]);
foreach ($mapping[$oldPath] as $key => $path) {
if ($key === 0) {
continue;
}
$relatedConfig = $configDataCollection->getNewEmptyItem();
$relatedConfig->setData($config->getData());
$relatedConfig->setId(null);
$relatedConfig->setData('path', $path);
$configDataCollection->addItem($relatedConfig);
}
} else {
$config->setData('path', $mapping[$oldPath]);
}
}
$configDataCollection->save();
}
/**
* @inheritdoc
*/
public static function getDependencies(): array
{
return [];
}
/**
* @inheritdoc
*/
public function getAliases(): array
{
return [];
}
}