@@ -12,7 +12,7 @@ class Converter implements ConverterInterface
12
12
*/
13
13
private static $ importTypesWithRequiredFields = [
14
14
'files ' => [
15
- 'source ' => ['type ' => 'string ' ],
15
+ 'source ' => ['type ' => 'string ' , ' default ' => \ Jh \ Import \ Source \Csv::class ],
16
16
'incoming_directory ' => ['type ' => 'string ' , 'default ' => 'jh_import/incoming ' ],
17
17
'archived_directory ' => ['type ' => 'string ' , 'default ' => 'jh_import/archived ' ],
18
18
'failed_directory ' => ['type ' => 'string ' , 'default ' => 'jh_import/failed ' ],
@@ -24,10 +24,12 @@ class Converter implements ConverterInterface
24
24
'cron_group ' => ['type ' => 'string ' , 'default ' => 'default ' ],
25
25
'archive_old_files ' => ['type ' => 'bool ' , 'default ' => false ],
26
26
'delete_old_files ' => ['type ' => 'bool ' , 'default ' => false ],
27
+ 'archive_date_format ' => ['type ' => 'string ' , 'default ' => 'dmYhis ' ],
28
+ 'directory_permissions ' => ['type ' => 'int ' , 'default ' => 0755 ],
27
29
],
28
30
'db ' => [
29
31
'connection_name ' => ['type ' => 'string ' ],
30
- 'source ' => ['type ' => 'string ' ],
32
+ 'source ' => ['type ' => 'string ' , ' default ' => \ Jh \ Import \ Source \Db::class ],
31
33
'specification ' => ['type ' => 'string ' ],
32
34
'writer ' => ['type ' => 'string ' ],
33
35
'id_field ' => ['type ' => 'string ' ],
@@ -38,7 +40,7 @@ class Converter implements ConverterInterface
38
40
'cron_group ' => ['type ' => 'string ' , 'default ' => 'default ' ]
39
41
],
40
42
'webapi ' => [
41
- 'source ' => ['type ' => 'string ' ],
43
+ 'source ' => ['type ' => 'string ' , ' default ' => \ Jh \ Import \ Source \Webapi::class ],
42
44
'source_id ' => ['type ' => 'string ' ],
43
45
'specification ' => ['type ' => 'string ' ],
44
46
'writer ' => ['type ' => 'string ' ],
@@ -55,6 +57,13 @@ class Converter implements ConverterInterface
55
57
]
56
58
];
57
59
60
+ private AppConfigProvider $ appConfigProvider ;
61
+
62
+ public function __construct (AppConfigProvider $ appConfigProvider )
63
+ {
64
+ $ this ->appConfigProvider = $ appConfigProvider ;
65
+ }
66
+
58
67
public function convert ($ source ): array
59
68
{
60
69
$ names = collect (static ::$ importTypesWithRequiredFields )
@@ -91,24 +100,26 @@ private function getOptions(\DOMElement $import, array $requiredFields, string $
91
100
/** @var \DOMNodeList $elements */
92
101
$ elements = $ import ->getElementsByTagName ($ requiredField );
93
102
103
+ // load default value from app config
104
+ $ value = $ this ->appConfigProvider ->getImportTypeOptionDefaultValue ($ importType , $ requiredField );
105
+
106
+ // override by import config
94
107
if ($ elements ->length > 0 ) {
95
108
$ value = $ elements ->item (0 )->nodeValue ;
109
+ }
96
110
111
+ if ($ value !== null ) {
97
112
switch ($ spec ['type ' ]) {
98
113
case 'bool ' :
99
114
return $ this ->castBool ($ value );
115
+ case 'int ' :
116
+ return $ this ->castInt ($ value );
100
117
case 'string ' :
101
118
return $ this ->castString ($ value );
102
119
}
103
-
104
- return $ value ;
105
120
}
106
121
107
- if (isset ($ spec ['default ' ])) {
108
- return $ spec ['default ' ];
109
- }
110
-
111
- return null ;
122
+ return $ value ?? $ spec ['default ' ] ?? null ;
112
123
});
113
124
114
125
//parse required indexers
@@ -145,8 +156,17 @@ private function castString($value): string
145
156
return (string ) $ value ;
146
157
}
147
158
159
+ private function castInt ($ value ): int
160
+ {
161
+ return (int ) $ value ;
162
+ }
163
+
148
164
private function castBool ($ value ): bool
149
165
{
166
+ if (is_bool ($ value )) {
167
+ return $ value ;
168
+ }
169
+
150
170
return $ value === 'true ' || $ value === '1 ' ;
151
171
}
152
172
}
0 commit comments