Skip to content

Commit a8f8ecf

Browse files
Fix LT-21976: Merge Create dates when merging entries (#334)
* Store the date at the start of the import and use it in entry creation. We need to have a consistent date recorded to determine if we read a date from the xml data or not. * Add a function to return the newest date that was actually read from the xml data. * Fix missing disposes in tests
1 parent 7120fad commit a8f8ecf

File tree

2 files changed

+345
-288
lines changed

2 files changed

+345
-288
lines changed

src/SIL.LCModel/Application/ApplicationServices/XmlImportData.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ internal string XmlState
165165
private ReferenceTracker m_rglinks = new ReferenceTracker();
166166
private TextWriter m_wrtrLog;
167167
private bool m_createLinks;
168+
private DateTime m_importDate = DateTime.Now;
168169

169170

170171
/// ------------------------------------------------------------------------------------
@@ -470,6 +471,7 @@ private void MergeRedundantEntries(ILexEntry leOld, ILexEntry leNew)
470471
ILexSense[] rgls = leOld.SensesOS.ToArray();
471472
for (int i = 0; i < rgls.Length; ++i)
472473
leNew.SensesOS.Add(rgls[i]);
474+
MergeDates(leOld, leNew);
473475
MergeEntryRefs(leOld, leNew);
474476
CopyCustomFieldData(leOld, leNew);
475477

@@ -479,6 +481,23 @@ private void MergeRedundantEntries(ILexEntry leOld, ILexEntry leNew)
479481
m_mapIdGuid[id] = leNew.Guid;
480482
}
481483

484+
/// Use the newest date between the two dates, as long as it is different from the importDate
485+
private void MergeDates(ILexEntry leOld, ILexEntry leNew)
486+
{
487+
if (leOld.DateCreated == m_importDate)
488+
{
489+
return;
490+
}
491+
if (leNew.DateCreated == m_importDate)
492+
{
493+
leNew.DateCreated = leOld.DateCreated;
494+
}
495+
else if (leOld.DateCreated > leNew.DateCreated)
496+
{
497+
leNew.DateCreated = leOld.DateCreated;
498+
}
499+
}
500+
482501
private void MergeEntryRefs(ILexEntry leOld, ILexEntry leNew)
483502
{
484503
if (leOld.EntryRefsOS.Count == 0)
@@ -1089,6 +1108,7 @@ private void ReadXmlObject(XmlReader xrdr, FieldInfo fi, ICmObject objToUse)
10891108
if (m_factLexEntry == null)
10901109
m_factLexEntry = m_cache.ServiceLocator.GetInstance<ILexEntryFactory>();
10911110
cmo = m_factLexEntry.Create();
1111+
((LexEntry)cmo).DateCreated = m_importDate;
10921112
m_nHomograph = 0;
10931113
break;
10941114
case TextTags.kClassId:

0 commit comments

Comments
 (0)