Skip to content

Commit d9a0ce8

Browse files
committed
Merge branch 'bugfix/import-deletions' into develop
2 parents 94b9842 + 2393e9c commit d9a0ce8

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

OnTopic.Editor.AspNetCore/Controllers/EditorController.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
| Project Topics Library
55
\=============================================================================================================================*/
66
using System;
7+
using System.Collections.Generic;
78
using System.IO;
89
using System.Linq;
910
using System.Text;
@@ -23,6 +24,7 @@
2324
using OnTopic.Internal.Diagnostics;
2425
using OnTopic.Mapping;
2526
using OnTopic.Metadata;
27+
using OnTopic.Querying;
2628
using OnTopic.Repositories;
2729

2830
namespace OnTopic.Editor.AspNetCore.Controllers {
@@ -694,6 +696,11 @@ public async Task<IActionResult> Import(IFormFile jsonFile, [Bind(Prefix = "Impo
694696
return View(editorViewModel);
695697
}
696698

699+
/*------------------------------------------------------------------------------------------------------------------------
700+
| INDEX TOPICS IN SCOPE
701+
\-----------------------------------------------------------------------------------------------------------------------*/
702+
var topics = target.FindAll(t => t.Id >= 0).ToList();
703+
697704
/*------------------------------------------------------------------------------------------------------------------------
698705
| IMPORT INTO TOPIC GRAPH
699706
>-------------------------------------------------------------------------------------------------------------------------
@@ -704,6 +711,20 @@ public async Task<IActionResult> Import(IFormFile jsonFile, [Bind(Prefix = "Impo
704711
target.Import(topicData, options);
705712
target.Import(topicData, options);
706713

714+
/*------------------------------------------------------------------------------------------------------------------------
715+
| DELETE UNMATCHED TOPICS
716+
>-------------------------------------------------------------------------------------------------------------------------
717+
| ### HACK JJC20200327: The Data Transfer library doesnt have access to the ITopicRepository, so it can't delete topics.
718+
| Instead, it removes them from the topic graph. But the ITopicRepository implementations don't have a means of detecting
719+
| removed topics during a recursive save and, therefore, the deletions aren't persited to the database. To mitigate this,
720+
| we evaluate the topic graph after the save, and then delete any orphans.
721+
\-----------------------------------------------------------------------------------------------------------------------*/
722+
var unmatchedTopics = topics.Except(target.FindAll(t => t.Id >= 0));
723+
724+
foreach (var unmatchedTopic in unmatchedTopics) {
725+
TopicRepository.Delete(unmatchedTopic);
726+
}
727+
707728
/*------------------------------------------------------------------------------------------------------------------------
708729
| SAVE
709730
>-------------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)