Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SodiumChachaPatch.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
11 
16 {
20  private $moduleDataSetup;
21 
25  private $structure;
26 
30  private $encryptor;
31 
35  private $state;
36 
43  public function __construct(
44  \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup,
45  \Magento\Config\Model\Config\Structure\Proxy $structure,
46  \Magento\Framework\Encryption\EncryptorInterface $encryptor,
47  \Magento\Framework\App\State $state
48  ) {
49  $this->moduleDataSetup = $moduleDataSetup;
50  $this->structure = $structure;
51  $this->encryptor = $encryptor;
52  $this->state = $state;
53  }
54 
58  public function apply()
59  {
60  $this->moduleDataSetup->startSetup();
61 
62  $this->reEncryptSystemConfigurationValues();
63 
64  $this->moduleDataSetup->endSetup();
65  }
66 
70  public static function getDependencies()
71  {
72  return [];
73  }
74 
78  public function getAliases()
79  {
80  return [];
81  }
82 
83  private function reEncryptSystemConfigurationValues()
84  {
85  $structure = $this->structure;
86  $paths = $this->state->emulateAreaCode(
87  \Magento\Framework\App\Area::AREA_ADMINHTML,
88  function () use ($structure) {
89  return $structure->getFieldPathsByAttribute(
90  'backend_model',
91  \Magento\Config\Model\Config\Backend\Encrypted::class
92  );
93  }
94  );
95  // walk through found data and re-encrypt it
96  if ($paths) {
97  $table = $this->moduleDataSetup->getTable('core_config_data');
98  $values = $this->moduleDataSetup->getConnection()->fetchPairs(
99  $this->moduleDataSetup->getConnection()
100  ->select()
101  ->from($table, ['config_id', 'value'])
102  ->where('path IN (?)', $paths)
103  ->where('value NOT LIKE ?', '')
104  );
105  foreach ($values as $configId => $value) {
106  $this->moduleDataSetup->getConnection()->update(
107  $table,
108  ['value' => $this->encryptor->encrypt($this->encryptor->decrypt($value))],
109  ['config_id = ?' => (int)$configId]
110  );
111  }
112  }
113  }
114 }
$values
Definition: options.phtml:88
__construct(\Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup, \Magento\Config\Model\Config\Structure\Proxy $structure, \Magento\Framework\Encryption\EncryptorInterface $encryptor, \Magento\Framework\App\State $state)
$value
Definition: gender.phtml:16
$paths
Definition: _bootstrap.php:83
$table
Definition: trigger.php:14