3
3
namespace CtiDigital \Configurator \Component ;
4
4
5
5
use CtiDigital \Configurator \Api \ComponentInterface ;
6
+ use CtiDigital \Configurator \Api \VersionManagementInterface ;
6
7
use CtiDigital \Configurator \Exception \ComponentException ;
7
8
use CtiDigital \Configurator \Api \LoggerInterface ;
8
9
use Exception ;
@@ -38,7 +39,8 @@ public function __construct(
38
39
private readonly LoggerInterface $ log ,
39
40
private readonly Filesystem $ filesystem ,
40
41
private readonly ViewModelRegistry $ viewModelRegistry ,
41
- private readonly Escaper $ escaper
42
+ private readonly Escaper $ escaper ,
43
+ private readonly VersionManagementInterface $ versionManagement
42
44
) {
43
45
}
44
46
@@ -79,6 +81,19 @@ private function processBlock(string $identifier, array $blockData, string $mode
79
81
$ canSave = false ;
80
82
$ block = null ;
81
83
84
+ $ version = $ data ['version ' ] ?? null ;
85
+ $ versionId = $ this ->alias . '_ ' . $ identifier ;
86
+
87
+ if (isset ($ data ['stores ' ])) {
88
+ $ versionId .= implode ('_ ' , $ data ['stores ' ]);
89
+ }
90
+
91
+ if ($ version ) {
92
+ unset($ data ['version ' ]);
93
+ }
94
+
95
+ $ isNewVersion = isset ($ version ) && $ this ->versionManagement ->isNewVersion ($ versionId , (int ) $ version );
96
+
82
97
// Check if there are existing blocks
83
98
if ($ blocks ->count ()) {
84
99
$ stores = [];
@@ -97,7 +112,7 @@ private function processBlock(string $identifier, array $blockData, string $mode
97
112
$ block = $ this ->blockFactory ->create ();
98
113
$ block ->setIdentifier ($ identifier );
99
114
$ canSave = true ;
100
- } elseif ($ mode === Processor::MODE_CREATE ) {
115
+ } elseif ($ mode === Processor::MODE_CREATE && ! $ isNewVersion ) {
101
116
// In create mode we skip modifying block
102
117
$ this ->log ->logComment (sprintf ("'%s' Block exists, skip modifying it (create mode) " , $ identifier ));
103
118
continue ;
@@ -184,6 +199,10 @@ private function processBlock(string $identifier, array $blockData, string $mode
184
199
$ identifier . ' ( ' . $ block ->getId () . ') '
185
200
));
186
201
}
202
+
203
+ if ($ version ) {
204
+ $ this ->versionManagement ->setVersion ($ versionId , (int ) $ version );
205
+ }
187
206
}
188
207
} catch (ComponentException $ e ) {
189
208
$ this ->log ->logError ($ e ->getMessage ());
0 commit comments