Skip to content

Commit 86f344c

Browse files
author
Paul Johnson
committed
Post review feedback
Less logging @ info level More re-usable migration
1 parent bba089c commit 86f344c

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/Umbraco.Core/Migrations/Upgrade/V_8_18_0/AddContentVersionCleanupFeature.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Linq;
2-
using Umbraco.Core.Persistence.Dtos;
1+
using Umbraco.Core.Persistence.Dtos;
32

43
namespace Umbraco.Core.Migrations.Upgrade.V_8_18_0
54
{
@@ -8,12 +7,19 @@ class AddContentVersionCleanupFeature : MigrationBase
87
public AddContentVersionCleanupFeature(IMigrationContext context)
98
: base(context) { }
109

10+
/// <remarks>
11+
/// The conditionals are useful to enable the same migration to be used in multiple
12+
/// migration paths x.x -> 8.18 and x.x -> 9.x
13+
/// </remarks>
1114
public override void Migrate()
1215
{
13-
Create.Table<ContentVersionCleanupPolicyDto>().Do();
16+
var tables = SqlSyntax.GetTablesInSchema(Context.Database);
17+
if (!tables.InvariantContains(ContentVersionCleanupPolicyDto.TableName))
18+
{
19+
Create.Table<ContentVersionCleanupPolicyDto>().Do();
20+
}
1421

15-
// What's this about, we worry someone else edited table with same change?
16-
var columns = SqlSyntax.GetColumnsInSchema(Context.Database).ToList();
22+
var columns = SqlSyntax.GetColumnsInSchema(Context.Database);
1723
AddColumnIfNotExists<ContentVersionDto>(columns, "preventCleanup");
1824
}
1925
}

src/Umbraco.Web/Scheduling/ContentVersionCleanup.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,16 @@ public override bool PerformRun()
6565
return false; // do NOT repeat, going down
6666
}
6767

68-
_logger.Info<ContentVersionCleanup>("Starting ContentVersionCleanup task.");
68+
var count = _cleanupService.PerformContentVersionCleanup(DateTime.Now).Count;
6969

70-
var report = _cleanupService.PerformContentVersionCleanup(DateTime.Now);
71-
72-
_logger.Info<ContentVersionCleanup>("Finished ContentVersionCleanup task. Removed {count} item(s).", report.Count);
70+
if (count > 0)
71+
{
72+
_logger.Info<ContentVersionCleanup>("Deleted {count} ContentVersion(s).", count);
73+
}
74+
else
75+
{
76+
_logger.Debug<ContentVersionCleanup>("Task complete, no items were Deleted.");
77+
}
7378

7479
return true;
7580
}

0 commit comments

Comments
 (0)