|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Algolia\AlgoliaSearch\Setup\Patch\Data; |
| 4 | + |
| 5 | +use Algolia\AlgoliaSearch\Helper\ConfigHelper; |
| 6 | +use Magento\Framework\Setup\ModuleDataSetupInterface; |
| 7 | +use Magento\Framework\Setup\Patch\DataPatchInterface; |
| 8 | +use Magento\Framework\Setup\Patch\PatchInterface; |
| 9 | + |
| 10 | +class MigrateIndexingConfigPatch implements DataPatchInterface |
| 11 | +{ |
| 12 | + public function __construct( |
| 13 | + protected ModuleDataSetupInterface $moduleDataSetup, |
| 14 | + ) {} |
| 15 | + |
| 16 | + /** |
| 17 | + * @inheritDoc |
| 18 | + */ |
| 19 | + public function apply(): PatchInterface |
| 20 | + { |
| 21 | + $this->moduleDataSetup->getConnection()->startSetup(); |
| 22 | + |
| 23 | + $this->moveIndexingSettings(); |
| 24 | + |
| 25 | + $this->moduleDataSetup->getConnection()->endSetup(); |
| 26 | + |
| 27 | + return $this; |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Migrate old Indexing configurations |
| 32 | + * @return void |
| 33 | + */ |
| 34 | + protected function moveIndexingSettings(): void |
| 35 | + { |
| 36 | + $movedConfig = [ |
| 37 | + 'algoliasearch_credentials/credentials/enable_backend' => ConfigHelper::ENABLE_INDEXING, |
| 38 | + 'algoliasearch_credentials/credentials/enable_query_suggestions_index' => ConfigHelper::ENABLE_QUERY_SUGGESTIONS_INDEX, |
| 39 | + 'algoliasearch_credentials/credentials/enable_pages_index' => ConfigHelper::ENABLE_PAGES_INDEX, |
| 40 | + ]; |
| 41 | + |
| 42 | + $connection = $this->moduleDataSetup->getConnection(); |
| 43 | + foreach ($movedConfig as $from => $to) { |
| 44 | + $configDataTable = $this->moduleDataSetup->getTable('core_config_data'); |
| 45 | + $whereConfigPath = $connection->quoteInto('path = ?', $from); |
| 46 | + $connection->update($configDataTable, ['path' => $to], $whereConfigPath); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * @inheritDoc |
| 52 | + */ |
| 53 | + public static function getDependencies(): array |
| 54 | + { |
| 55 | + return []; |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @inheritDoc |
| 60 | + */ |
| 61 | + public function getAliases(): array |
| 62 | + { |
| 63 | + return []; |
| 64 | + } |
| 65 | +} |
0 commit comments