forked from LittleBigRefresh/Refresh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoveSubjectsOutOfGamePhotosMigration.cs
More file actions
52 lines (42 loc) · 1.76 KB
/
Copy pathMoveSubjectsOutOfGamePhotosMigration.cs
File metadata and controls
52 lines (42 loc) · 1.76 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
using Refresh.Database.Models.Photos;
using Refresh.Workers;
namespace Refresh.Interfaces.Workers.Migrations;
public class MoveSubjectsOutOfGamePhotosMigration : MigrationJob<GamePhoto>
{
protected override IQueryable<GamePhoto> SortAndFilter(IQueryable<GamePhoto> query)
{
return query
.Where(p => p.Subjects.Count == 0)
.OrderBy(p => p.PhotoId);
}
protected override int Migrate(WorkContext context, GamePhoto[] batch)
{
foreach (GamePhoto photo in batch)
{
// Extra check to be sure
if (context.Database.GetTotalSubjectsInPhoto(photo) > 0)
continue;
#pragma warning disable CS0618 // obsoletion
// If DisplayName is not null, there is a subject in that spot
if (photo.Subject1DisplayName != null)
{
context.Database.AddSubjectForPhoto(photo, 1, photo.Subject1DisplayName, photo.Subject1User, photo.Subject1Bounds, false);
}
if (photo.Subject2DisplayName != null)
{
context.Database.AddSubjectForPhoto(photo, 2, photo.Subject2DisplayName, photo.Subject2User, photo.Subject2Bounds, false);
}
if (photo.Subject3DisplayName != null)
{
context.Database.AddSubjectForPhoto(photo, 3, photo.Subject3DisplayName, photo.Subject3User, photo.Subject3Bounds, false);
}
if (photo.Subject4DisplayName != null)
{
context.Database.AddSubjectForPhoto(photo, 4, photo.Subject4DisplayName, photo.Subject4User, photo.Subject4Bounds, false);
}
#pragma warning restore CS0618
}
context.Database.SaveChanges();
return batch.Length;
}
}