Skip to content

Commit bd605cd

Browse files
authored
Merge pull request #1 from senthilengg/senthilengg-patch-for-github-issue-39530
Fix for issue magento#39530 to avoid regenerating admin grid flat table
2 parents 6cfb9b6 + e881f57 commit bd605cd

File tree

1 file changed

+62
-0
lines changed
  • app/code/Magento/EncryptionKey/Model/ResourceModel/Key

1 file changed

+62
-0
lines changed

app/code/Magento/EncryptionKey/Model/ResourceModel/Key/Change.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@
1414
use Magento\Framework\Config\Data\ConfigData;
1515
use Magento\Framework\Config\File\ConfigFilePool;
1616
use Magento\Framework\Encryption\EncryptorInterface;
17+
use Magento\Framework\Encryption\Encryptor;
1718
use Magento\Framework\Exception\FileSystemException;
1819
use Magento\Framework\Exception\LocalizedException;
1920
use Magento\Framework\Filesystem;
2021
use Magento\Framework\Filesystem\Directory\WriteInterface;
2122
use Magento\Framework\Math\Random;
2223
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
2324
use Magento\Framework\Model\ResourceModel\Db\Context;
25+
use Magento\Framework\Indexer\ConfigInterface;
26+
use Magento\Framework\Json\EncoderInterface;
27+
use Magento\Indexer\Model\ResourceModel\Indexer\State\CollectionFactory;
2428

2529
/**
2630
* Encryption key changer resource model
@@ -71,13 +75,37 @@ class Change extends AbstractDb
7175
*/
7276
protected $random;
7377

78+
/**
79+
* Indexer Config
80+
*
81+
* @var IndexerConfig
82+
*/
83+
protected $indexerConfig;
84+
85+
/**
86+
* Json Encoder
87+
*
88+
* @var Encoder
89+
*/
90+
protected $encoder;
91+
92+
/**
93+
* Indexer State Collection Factory
94+
*
95+
* @var IndexerStateCollection
96+
*/
97+
protected $indexerStateCollection;
98+
7499
/**
75100
* @param Context $context
76101
* @param Filesystem $filesystem
77102
* @param Structure $structure
78103
* @param EncryptorInterface $encryptor
79104
* @param Writer $writer
80105
* @param Random $random
106+
* @param ConfigInterface $indexerConfig
107+
* @param EncoderInterface $encoder
108+
* @param CollectionFactory $indexerStateCollection
81109
* @param string $connectionName
82110
*/
83111
public function __construct(
@@ -87,6 +115,9 @@ public function __construct(
87115
EncryptorInterface $encryptor,
88116
Writer $writer,
89117
Random $random,
118+
ConfigInterface $indexerConfig,
119+
EncoderInterface $encoder,
120+
CollectionFactory $indexerStateCollection,
90121
$connectionName = null
91122
) {
92123
$this->encryptor = clone $encryptor;
@@ -95,6 +126,9 @@ public function __construct(
95126
$this->structure = $structure;
96127
$this->writer = $writer;
97128
$this->random = $random;
129+
$this->indexerConfig = $indexerConfig;
130+
$this->encoder = $encoder;
131+
$this->indexerStateCollection = $indexerStateCollection;
98132
}
99133

100134
/**
@@ -139,6 +173,7 @@ public function changeEncryptionKey($key = null)
139173
try {
140174
$this->_reEncryptSystemConfigurationValues();
141175
$this->_reEncryptCreditCardNumbers();
176+
$this->_updateIndexersHash();
142177
$this->writer->saveConfig($configData);
143178
$this->commit();
144179
return $key;
@@ -207,4 +242,31 @@ protected function _reEncryptCreditCardNumbers()
207242
);
208243
}
209244
}
245+
246+
/**
247+
* Retrieve indexer state and update the hash with new encryption key
248+
*
249+
* @return void
250+
*/
251+
protected function _updateIndexersHash(){
252+
253+
$stateIndexers = [];
254+
$stateCollection = $this->indexerStateCollection->create();
255+
foreach ($stateCollection->getItems() as $state) {
256+
/** @var \Magento\Indexer\Model\Indexer\State $state */
257+
$stateIndexers[$state->getIndexerId()] = $state;
258+
}
259+
260+
foreach ($this->indexerConfig->getIndexers() as $indexerId => $indexerConfig) {
261+
$newHashConfig = $this->encryptor->hash(
262+
$this->encoder->encode($indexerConfig),
263+
Encryptor::HASH_VERSION_MD5
264+
);
265+
266+
if (isset($stateIndexers[$indexerId])) {
267+
$stateIndexers[$indexerId]->setHashConfig($newHashConfig);
268+
$stateIndexers[$indexerId]->save();
269+
}
270+
}
271+
}
210272
}

0 commit comments

Comments
 (0)