@@ -262,7 +262,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
262262 // add the section to the linker
263263 $ linker ->addObject ($ originalId , $ item );
264264
265- // Import the questions
265+ // Import each question
266+ $ importedItems = [];
266267 if (isset ($ input ['_questions ' ])) {
267268 // sort questions by order
268269 usort ($ input ['_questions ' ], function ($ a , $ b ) {
@@ -273,9 +274,24 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
273274 });
274275
275276 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 ;
277283 }
278284 }
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+ ]);
279295
280296 // Import conditions
281297 if (isset ($ input ['_conditions ' ])) {
0 commit comments