@@ -262,7 +262,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
262
262
// add the section to the linker
263
263
$ linker ->addObject ($ originalId , $ item );
264
264
265
- // Import the questions
265
+ // Import each question
266
+ $ importedItems = [];
266
267
if (isset ($ input ['_questions ' ])) {
267
268
// sort questions by order
268
269
usort ($ input ['_questions ' ], function ($ a , $ b ) {
@@ -273,9 +274,24 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
273
274
});
274
275
275
276
foreach ($ input ['_questions ' ] as $ question ) {
276
- PluginFormcreatorQuestion::import ($ linker , $ question , $ itemId );
277
+ $ importedItem = PluginFormcreatorQuestion::import ($ linker , $ question , $ itemId );
278
+ if ($ importedItem === false ) {
279
+ // Falied to import a question
280
+ return false ;
281
+ }
282
+ $ importedItems [] = $ importedItem ;
277
283
}
278
284
}
285
+ // Delete all other questions
286
+ $ deleteCriteria = [];
287
+ if (count ($ importedItems ) > 0 ) {
288
+ $ deleteCriteria = ['NOT ' => ['id ' => $ importedItems ]];
289
+ }
290
+ $ FormProfile = new PluginFormcreatorSection ();
291
+ $ FormProfile ->deleteByCriteria ([
292
+ $ formFk => $ itemId ,
293
+ $ deleteCriteria ,
294
+ ]);
279
295
280
296
// Import conditions
281
297
if (isset ($ input ['_conditions ' ])) {
0 commit comments