diff --git a/src/Umbraco.Core/Events/MigrationEventArgs.cs b/src/Umbraco.Core/Events/MigrationEventArgs.cs index 008e50d2ee..89dfe56294 100644 --- a/src/Umbraco.Core/Events/MigrationEventArgs.cs +++ b/src/Umbraco.Core/Events/MigrationEventArgs.cs @@ -128,8 +128,14 @@ namespace Umbraco.Core.Events get { return TargetSemVersion.GetVersion(); } } + /// + /// Gets the origin version of the migration, i.e. the one that is currently installed. + /// public SemVersion ConfiguredSemVersion { get; private set; } + /// + /// Gets the target version of the migration. + /// public SemVersion TargetSemVersion { get; private set; } public string ProductName { get; private set; } diff --git a/src/Umbraco.Web/Strategies/Migrations/RebuildMediaXmlCacheAfterUpgrade.cs b/src/Umbraco.Web/Strategies/Migrations/RebuildMediaXmlCacheAfterUpgrade.cs deleted file mode 100644 index c3920677c5..0000000000 --- a/src/Umbraco.Web/Strategies/Migrations/RebuildMediaXmlCacheAfterUpgrade.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using Umbraco.Core; -using Umbraco.Core.Events; -using Umbraco.Core.Persistence.Migrations; -using Umbraco.Core.Services; -using umbraco.interfaces; -using Umbraco.Core.Configuration; - -namespace Umbraco.Web.Strategies.Migrations -{ - /// - /// This will execute after upgrading to rebuild the xml cache - /// - /// - /// This cannot execute as part of a db migration since we need access to the services/repos. - /// - /// This will execute for specific versions - - /// - /// * If current is less than or equal to 7.0.0 - /// - public class RebuildMediaXmlCacheAfterUpgrade : MigrationStartupHander - { - protected override void AfterMigration(MigrationRunner sender, MigrationEventArgs e) - { - if (e.ProductName != GlobalSettings.UmbracoMigrationName) return; - - var target70 = new Version(7, 0, 0); - - if (e.ConfiguredVersion <= target70) - { - var mediasvc = (MediaService)ApplicationContext.Current.Services.MediaService; - mediasvc.RebuildXmlStructures(); - } - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Web/Strategies/Migrations/RebuildXmlCachesAfterUpgrade.cs b/src/Umbraco.Web/Strategies/Migrations/RebuildXmlCachesAfterUpgrade.cs new file mode 100644 index 0000000000..e62a738675 --- /dev/null +++ b/src/Umbraco.Web/Strategies/Migrations/RebuildXmlCachesAfterUpgrade.cs @@ -0,0 +1,52 @@ +using System; +using umbraco; +using Umbraco.Core; +using Umbraco.Core.Events; +using Umbraco.Core.Persistence.Migrations; +using Umbraco.Core.Services; +using GlobalSettings = Umbraco.Core.Configuration.GlobalSettings; + +namespace Umbraco.Web.Strategies.Migrations +{ + /// + /// Rebuilds the Xml caches after upgrading. + /// This will execute after upgrading to rebuild the xml cache + /// + /// + /// This cannot execute as part of a DB migration since it needs access to services and repositories. + /// Executes for: + /// - Media Xml : if current is less than, or equal to, 7.0.0 (superceeded by the next rule) + /// - Media & Content Xml : if current is less than, or equal to, 7.3.0 - because 7.3.0 adds .Key to cached items + /// + /// + public class RebuildXmlCachesAfterUpgrade : MigrationStartupHander + { + protected override void AfterMigration(MigrationRunner sender, MigrationEventArgs e) + { + if (e.ProductName != GlobalSettings.UmbracoMigrationName) return; + + var v730 = new Semver.SemVersion(new Version(7, 3, 0)); + + var doMedia = e.ConfiguredSemVersion < v730; + var doContent = e.ConfiguredSemVersion < v730; + + if (doMedia) + { + var mediaService = (MediaService) ApplicationContext.Current.Services.MediaService; + mediaService.RebuildXmlStructures(); + + // note: not re-indexing medias? + } + + if (doContent) + { + // rebuild Xml in database + var contentService = (ContentService) ApplicationContext.Current.Services.ContentService; + contentService.RebuildXmlStructures(); + + // refresh the Xml cache + content.Instance.RefreshContentFromDatabase(); + } + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index c86eb5cf04..4fccaab6f0 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -914,7 +914,7 @@ Resources.resx - +