7
7
8
8
namespace Magento \Config \Model \Data \ReEncryptorList \CoreConfigDataReEncryptor ;
9
9
10
- use Magento \Framework \App \Config \Initial ;
11
10
use Magento \Framework \App \ResourceConnection ;
12
- use Magento \Config \Model \Config \Backend \Encrypted ;
13
11
use Magento \Framework \Encryption \EncryptorInterface ;
14
12
use Magento \EncryptionKey \Model \Data \ReEncryptorList \ReEncryptor \HandlerInterface ;
15
13
use Magento \EncryptionKey \Model \Data \ReEncryptorList \ReEncryptor \Handler \ErrorFactory ;
@@ -22,17 +20,17 @@ class Handler implements HandlerInterface
22
20
/**
23
21
* @var string
24
22
*/
25
- private const TABLE_NAME = "core_config_data " ;
23
+ private const PATTERN = "^[[:digit:]]+:[[:digit:]]+:.*$ " ;
26
24
27
25
/**
28
26
* @var string
29
27
*/
30
- private const BACKEND_MODEL = Encrypted::class ;
28
+ private const TABLE_NAME = " core_config_data " ;
31
29
32
30
/**
33
- * @var Initial
31
+ * @var int
34
32
*/
35
- private Initial $ config ;
33
+ private const QUERY_SIZE = 1000 ;
36
34
37
35
/**
38
36
* @var EncryptorInterface
@@ -50,18 +48,15 @@ class Handler implements HandlerInterface
50
48
private ErrorFactory $ errorFactory ;
51
49
52
50
/**
53
- * @param Initial $config
54
51
* @param EncryptorInterface $encryptor
55
52
* @param ResourceConnection $resourceConnection
56
53
* @param ErrorFactory $errorFactory
57
54
*/
58
55
public function __construct (
59
- Initial $ config ,
60
56
EncryptorInterface $ encryptor ,
61
57
ResourceConnection $ resourceConnection ,
62
58
ErrorFactory $ errorFactory
63
59
) {
64
- $ this ->config = $ config ;
65
60
$ this ->encryptor = $ encryptor ;
66
61
$ this ->resourceConnection = $ resourceConnection ;
67
62
$ this ->errorFactory = $ errorFactory ;
@@ -72,46 +67,34 @@ public function __construct(
72
67
*/
73
68
public function reEncrypt (): array
74
69
{
75
- $ paths = [];
76
70
$ errors = [];
77
-
78
- foreach ($ this ->config ->getMetadata () as $ path => $ processor ) {
79
- if (isset ($ processor ['backendModel ' ]) &&
80
- $ processor ['backendModel ' ] === self ::BACKEND_MODEL
81
- ) {
82
- $ paths [] = $ path ;
83
- }
84
- }
85
-
86
- if ($ paths ) {
87
- $ tableName = $ this ->resourceConnection ->getTableName (
88
- self ::TABLE_NAME
89
- );
90
-
91
- $ connection = $ this ->resourceConnection ->getConnection ();
92
-
93
- $ select = $ connection ->select ()
94
- ->from ($ tableName , ['config_id ' , 'value ' ])
95
- ->where ('path IN (?) ' , $ paths )
96
- ->where ('value != ? ' , '' )
97
- ->where ('value IS NOT NULL ' );
98
-
99
- foreach ($ connection ->fetchPairs ($ select ) as $ configId => $ value ) {
100
- try {
101
- $ connection ->update (
102
- $ tableName ,
103
- ['value ' => $ this ->encryptor ->encrypt ($ this ->encryptor ->decrypt ($ value ))],
104
- ['config_id = ? ' => (int ) $ configId ]
105
- );
106
- } catch (\Throwable $ e ) {
107
- $ errors [] = $ this ->errorFactory ->create (
108
- "config_id " ,
109
- $ configId ,
110
- $ e ->getMessage ()
111
- );
112
-
113
- continue ;
114
- }
71
+ $ tableName = $ this ->resourceConnection ->getTableName (
72
+ self ::TABLE_NAME
73
+ );
74
+ $ connection = $ this ->resourceConnection ->getConnection ();
75
+
76
+ $ select = $ connection ->select ()
77
+ ->from ($ tableName , ['config_id ' , 'value ' ])
78
+ ->where ('value != ? ' , '' )
79
+ ->where ('value IS NOT NULL ' )
80
+ ->where ('value REGEXP ? ' , self ::PATTERN )
81
+ ->limit (self ::QUERY_SIZE );
82
+
83
+ foreach ($ connection ->fetchPairs ($ select ) as $ configId => $ value ) {
84
+ try {
85
+ $ connection ->update (
86
+ $ tableName ,
87
+ ['value ' => $ this ->encryptor ->encrypt ($ this ->encryptor ->decrypt ($ value ))],
88
+ ['config_id = ? ' => (int )$ configId ]
89
+ );
90
+ } catch (\Throwable $ e ) {
91
+ $ errors [] = $ this ->errorFactory ->create (
92
+ "config_id " ,
93
+ $ configId ,
94
+ $ e ->getMessage ()
95
+ );
96
+
97
+ continue ;
115
98
}
116
99
}
117
100
0 commit comments