21
21
class ConfigOptionsList implements ConfigOptionsListInterface
22
22
{
23
23
/**
24
- * Input key for the option
25
- */
26
- private const INPUT_KEY_SALT ='id_salt ' ;
27
-
28
- /**
29
- * Path to the values in the deployment config
24
+ * @var Random
30
25
*/
31
- private const CONFIG_PATH_SALT = ' cache/graphql/id_salt ' ;
26
+ private $ random ;
32
27
33
28
/**
34
- * @var Random
29
+ * Deployment configuration
30
+ *
31
+ * @var DeploymentConfig
35
32
*/
36
- private $ random ;
33
+ private $ deploymentConfig ;
37
34
38
35
/**
39
36
* @param Random $random
37
+ * @param DeploymentConfig $deploymentConfig
40
38
*/
41
- public function __construct (Random $ random )
42
- {
39
+ public function __construct (
40
+ Random $ random ,
41
+ DeploymentConfig $ deploymentConfig
42
+ ) {
43
43
$ this ->random = $ random ;
44
+ $ this ->deploymentConfig = $ deploymentConfig ;
44
45
}
45
46
46
47
/**
@@ -50,9 +51,9 @@ public function getOptions(): array
50
51
{
51
52
return [
52
53
new TextConfigOption (
53
- self ::INPUT_KEY_SALT ,
54
+ ConfigOptionsListConstants ::INPUT_KEY_SALT ,
54
55
TextConfigOption::FRONTEND_WIZARD_TEXT ,
55
- self ::CONFIG_PATH_SALT ,
56
+ ConfigOptionsListConstants ::CONFIG_PATH_SALT ,
56
57
'GraphQl Salt '
57
58
),
58
59
];
@@ -64,11 +65,18 @@ public function getOptions(): array
64
65
*/
65
66
public function createConfig (array $ data , DeploymentConfig $ deploymentConfig )
66
67
{
68
+ $ currentIdSalt = $ this ->deploymentConfig ->get (ConfigOptionsListConstants::CONFIG_PATH_SALT );
69
+
67
70
$ configData = new ConfigData (ConfigFilePool::APP_ENV );
68
71
69
- if (!$ this ->isDataEmpty ($ data , self ::INPUT_KEY_SALT )) {
70
- $ salt = $ this ->random ->getRandomString (ConfigOptionsListConstants::STORE_KEY_RANDOM_STRING_SIZE );
71
- $ configData ->set (self ::CONFIG_PATH_SALT , $ salt );
72
+ // Use given salt if set, else use current
73
+ $ id_salt = $ data [ConfigOptionsListConstants::INPUT_KEY_SALT ] ?? $ currentIdSalt ;
74
+
75
+ // If there is no id_salt given or currently set, generate a new one
76
+ $ id_salt = $ id_salt ?? $ this ->random ->getRandomString (ConfigOptionsListConstants::STORE_KEY_RANDOM_STRING_SIZE );
77
+
78
+ if (!$ this ->isDataEmpty ($ data , ConfigOptionsListConstants::INPUT_KEY_SALT )) {
79
+ $ configData ->set (ConfigOptionsListConstants::CONFIG_PATH_SALT , $ id_salt );
72
80
}
73
81
74
82
return [$ configData ];
0 commit comments