ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Setup\Model;
|
||||
|
||||
use InvalidArgumentException as InvalidArgumentException;
|
||||
use Magento\Framework\Filesystem\Io\File as FileSystem;
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
class ModuleDataProvider
|
||||
{
|
||||
public const MODULE_DATA_FOLDER = 'data';
|
||||
|
||||
/**
|
||||
* @var FileSystem
|
||||
*/
|
||||
private $fileSystem;
|
||||
|
||||
/**
|
||||
* @var ComponentRegistrar
|
||||
*/
|
||||
private $moduleDirectoryProvider;
|
||||
|
||||
public function __construct(
|
||||
FileSystem $fileSystem,
|
||||
ComponentRegistrar $moduleDirectoryProvider
|
||||
) {
|
||||
$this->fileSystem = $fileSystem;
|
||||
$this->moduleDirectoryProvider = $moduleDirectoryProvider;
|
||||
}
|
||||
|
||||
public function getModuleDataFilePath(string $fileName, string $directory = ''): string
|
||||
{
|
||||
if (!preg_match('/(^[a-z_]+$)|(^$)/m', $directory)) {
|
||||
throw new InvalidArgumentException(__('Invalid directory provided')->render());
|
||||
}
|
||||
|
||||
$moduleDirectory = $this->moduleDirectoryProvider->getPath(
|
||||
ComponentRegistrar::MODULE,
|
||||
'Amasty_ElasticSearch'
|
||||
);
|
||||
$moduleDataDirectory = $moduleDirectory . DIRECTORY_SEPARATOR . self::MODULE_DATA_FOLDER;
|
||||
|
||||
if ($directory !== '') {
|
||||
$moduleDataDirectory .= DIRECTORY_SEPARATOR . $directory;
|
||||
}
|
||||
|
||||
$filePath = $moduleDataDirectory . DIRECTORY_SEPARATOR . $fileName;
|
||||
|
||||
if (!$this->fileSystem->fileExists($filePath)) {
|
||||
throw new InvalidArgumentException(__('Module data file doesn\'t exists.')->render());
|
||||
}
|
||||
|
||||
return $filePath;
|
||||
}
|
||||
|
||||
public function getModuleDataFileContent(string $fileName, string $directory = ''): string
|
||||
{
|
||||
return $this->fileSystem->read(
|
||||
$this->getModuleDataFilePath($fileName, $directory)
|
||||
);
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Setup\Patch\Data;
|
||||
|
||||
use Amasty\ElasticSearch\Setup\Model\ModuleDataProvider;
|
||||
use Magento\Framework\Setup\Patch\DataPatchInterface;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
|
||||
class DeployModuleSearchSettings implements DataPatchInterface
|
||||
{
|
||||
public const SEARCH_CONFIG_FILE = 'search_config.json';
|
||||
|
||||
/**
|
||||
* @var ModuleDataSetupInterface
|
||||
*/
|
||||
private $moduleDataSetup;
|
||||
|
||||
/**
|
||||
* @var ModuleDataProvider
|
||||
*/
|
||||
private $moduleDataProvider;
|
||||
|
||||
public function __construct(
|
||||
ModuleDataSetupInterface $moduleDataSetup,
|
||||
ModuleDataProvider $moduleDataProvider
|
||||
) {
|
||||
$this->moduleDataSetup = $moduleDataSetup;
|
||||
$this->moduleDataProvider = $moduleDataProvider;
|
||||
}
|
||||
|
||||
public static function getDependencies(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAliases(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function apply(): DeployModuleSearchSettings
|
||||
{
|
||||
$data = [
|
||||
'scope' => 'default',
|
||||
'scope_id' => 0,
|
||||
'path' => 'amasty_elastic/catalog/query_settings',
|
||||
'value' => $this->moduleDataProvider->getModuleDataFileContent(self::SEARCH_CONFIG_FILE)
|
||||
];
|
||||
|
||||
$connection = $this->moduleDataSetup->getConnection();
|
||||
$connection->insertOnDuplicate(
|
||||
$this->moduleDataSetup->getTable('core_config_data'),
|
||||
$data,
|
||||
['value']
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Setup\Patch\Data;
|
||||
|
||||
use Amasty\ElasticSearch\Api\Data\StopWordInterface;
|
||||
use Amasty\ElasticSearch\Api\StopWordRepositoryInterface;
|
||||
use Amasty\ElasticSearch\Setup\Model\ModuleDataProvider;
|
||||
use Magento\Framework\Locale\Resolver as LocaleResolver;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Framework\Setup\Patch\DataPatchInterface;
|
||||
use Magento\Framework\Setup\Patch\NonTransactionableInterface;
|
||||
use Magento\Store\Api\Data\StoreInterface;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Zend_Db_Expr;
|
||||
|
||||
class DeployStopWords implements DataPatchInterface, NonTransactionableInterface
|
||||
{
|
||||
public const STOP_WORDS_DIR = 'stop_words';
|
||||
public const FILE_EXTENSION = '.csv';
|
||||
|
||||
/**
|
||||
* @var ModuleDataSetupInterface
|
||||
*/
|
||||
private $moduleDataSetup;
|
||||
|
||||
/**
|
||||
* @var ModuleDataProvider
|
||||
*/
|
||||
private $moduleDataProvider;
|
||||
|
||||
/**
|
||||
* @var StoreManagerInterface
|
||||
*/
|
||||
private $storeManager;
|
||||
|
||||
/**
|
||||
* @var LocaleResolver
|
||||
*/
|
||||
private $localeResolver;
|
||||
|
||||
/**
|
||||
* @var LocaleResolver
|
||||
*/
|
||||
private $debug;
|
||||
|
||||
/**
|
||||
* @var StopWordRepositoryInterface
|
||||
*/
|
||||
private $stopWordRepository;
|
||||
|
||||
public function __construct(
|
||||
StopWordRepositoryInterface $stopWordRepository,
|
||||
ModuleDataSetupInterface $moduleDataSetup,
|
||||
ModuleDataProvider $moduleDataProvider,
|
||||
StoreManagerInterface $storeManager,
|
||||
LocaleResolver $localeResolver,
|
||||
LoggerInterface $debug
|
||||
) {
|
||||
$this->moduleDataSetup = $moduleDataSetup;
|
||||
$this->moduleDataProvider = $moduleDataProvider;
|
||||
$this->storeManager = $storeManager;
|
||||
$this->localeResolver = $localeResolver;
|
||||
$this->debug = $debug;
|
||||
$this->stopWordRepository = $stopWordRepository;
|
||||
}
|
||||
|
||||
public static function getDependencies(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAliases(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function apply(): DeployStopWords
|
||||
{
|
||||
if ($this->isCanApply()) {
|
||||
$currentStore = $this->storeManager->getStore();
|
||||
|
||||
foreach ($this->storeManager->getStores(false) as $store) {
|
||||
try {
|
||||
$this->localeResolver->emulate($store->getId());
|
||||
$locale = $this->localeResolver->getLocale();
|
||||
|
||||
if ($locale) {
|
||||
$this->runImportProcess($locale, $store);
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
$this->debug->debug($exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$this->localeResolver->emulate($currentStore->getId());
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function isCanApply(): bool
|
||||
{
|
||||
$connection = $this->moduleDataSetup->getConnection();
|
||||
$select = $connection->select();
|
||||
$select->from(
|
||||
$this->moduleDataSetup->getTable(StopWordInterface::TABLE_NAME),
|
||||
[new Zend_Db_Expr('COUNT(*)')]
|
||||
);
|
||||
|
||||
return !$connection->fetchOne($select);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $locale
|
||||
* @param StoreInterface $store
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function runImportProcess(string $locale, StoreInterface $store): void
|
||||
{
|
||||
$fileName = $locale . self::FILE_EXTENSION;
|
||||
|
||||
try {
|
||||
$count = $this->stopWordRepository->importStopWords(
|
||||
$this->moduleDataProvider->getModuleDataFilePath($fileName, self::STOP_WORDS_DIR),
|
||||
$store->getId()
|
||||
);
|
||||
$this->debug->debug(
|
||||
__('%1 StopWords were imported for store %2', $count, $store->getName())->render()
|
||||
);
|
||||
} catch (\InvalidArgumentException $exception) {
|
||||
$this->debug->debug(__('There are no file for locale: %1', $locale)->render());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Setup\Patch\Schema;
|
||||
|
||||
use Magento\Framework\Setup\Patch\SchemaPatchInterface;
|
||||
use Magento\Framework\Setup\SchemaSetupInterface;
|
||||
|
||||
/**
|
||||
* @see \Amasty\Base\Plugin\Framework\Setup\Declaration\Schema\Diff\Diff\RestrictDropTables
|
||||
*/
|
||||
class DropOldIndexTable implements SchemaPatchInterface
|
||||
{
|
||||
public const OLD_INDEX_TABLE = 'amasty_elastic_relevance_rule_index';
|
||||
|
||||
/**
|
||||
* @var SchemaSetupInterface
|
||||
*/
|
||||
private $schemaSetup;
|
||||
|
||||
public function __construct(
|
||||
SchemaSetupInterface $schemaSetup
|
||||
) {
|
||||
$this->schemaSetup = $schemaSetup;
|
||||
}
|
||||
|
||||
public static function getDependencies(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAliases(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function apply(): DropOldIndexTable
|
||||
{
|
||||
$connection = $this->schemaSetup->getConnection();
|
||||
$oldTableName = $this->schemaSetup->getTable(self::OLD_INDEX_TABLE);
|
||||
|
||||
if ($connection->isTableExists($oldTableName)) {
|
||||
$connection->dropTable($oldTableName);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Setup;
|
||||
|
||||
use Amasty\ElasticSearch\Api\Data\RelevanceRuleInterface;
|
||||
use Amasty\ElasticSearch\Api\Data\StopWordInterface;
|
||||
use Amasty\ElasticSearch\Api\Data\SynonymInterface;
|
||||
use Amasty\ElasticSearch\Model\Indexer\RelevanceRule\IndexBuilder;
|
||||
use Magento\Framework\Setup\ModuleContextInterface;
|
||||
use Magento\Framework\Setup\SchemaSetupInterface;
|
||||
use Magento\Framework\Setup\UninstallInterface;
|
||||
|
||||
class Uninstall implements UninstallInterface
|
||||
{
|
||||
public const TABLES_TO_DELETE = [
|
||||
RelevanceRuleInterface::TABLE_NAME,
|
||||
IndexBuilder::TABLE_NAME,
|
||||
SynonymInterface::TABLE_NAME,
|
||||
StopWordInterface::TABLE_NAME
|
||||
];
|
||||
|
||||
public function uninstall(SchemaSetupInterface $setup, ModuleContextInterface $context): void
|
||||
{
|
||||
$setup->startSetup();
|
||||
|
||||
foreach (self::TABLES_TO_DELETE as $table) {
|
||||
$setup->getConnection()->dropTable($setup->getTable($table));
|
||||
}
|
||||
|
||||
$setup->endSetup();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user