-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathDataMigration7000012.cs
More file actions
58 lines (53 loc) · 2.51 KB
/
DataMigration7000012.cs
File metadata and controls
58 lines (53 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) 2015 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)
using System.Xml.Linq;
namespace SIL.LCModel.DomainServices.DataMigration
{
/// ------------------------------------------------------------------------------------
/// <summary>
/// Migrates from 7000011 to 7000012
/// </summary>
/// ------------------------------------------------------------------------------------
internal class DataMigration7000012 : IDataMigration
{
/// ------------------------------------------------------------------------------------
/// <summary>
/// Deletes unused fields in UserViewField.
/// </summary>
/// <param name="domainObjectDtoRepository">Repository of all CmObject DTOs available for
/// one migration step.</param>
/// ------------------------------------------------------------------------------------
public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
{
DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000011);
// 1) Select the UserViewField classes.
// 2) Delete the following attributes: Details, Visibility, IsCustomField, SubfieldOf, PossList
foreach (var uvfDto in domainObjectDtoRepository.AllInstancesSansSubclasses("UserViewField"))
{
XElement rtElement = XElement.Parse(uvfDto.Xml);
XElement uvfElement = rtElement.Element("UserViewField");
RemoveField(uvfDto, uvfElement, "Details");
RemoveField(uvfDto, uvfElement, "Visibility");
RemoveField(uvfDto, uvfElement, "SubfieldOf");
RemoveField(uvfDto, uvfElement, "IsCustomField");
DataMigrationServices.UpdateDTO(domainObjectDtoRepository, uvfDto, rtElement.ToString());
}
DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
}
/// ------------------------------------------------------------------------------------
/// <summary>
/// Removes the specified field.
/// </summary>
/// <param name="dto">The domain transfer object that has a field that may need to be deleted.</param>
/// <param name="objElement">Name of the object containing fieldToDelete.</param>
/// <param name="fieldToDelete">The name of the field to delete.</param>
/// ------------------------------------------------------------------------------------
private void RemoveField(DomainObjectXMLDTO dto, XElement objElement, string fieldToDelete)
{
XElement rmElement = objElement.Element(fieldToDelete);
if (rmElement != null)
rmElement.Remove();
}
}
}