Implements unattended package migrations for both explicit and implicit migrations (#10418)
* Clean up and changes to backoffice for the nuget only packages * temp commit of package logic removal * Lots of package code cleanup and removal * Removes old package data from the test package xml * Updates packaging code to take in XDocument instead of a file since we'll not be dealing with files, starts creating expressions for the package migrations scripting. * fixing tests * Fixes runtime state and boot failed middleware so that it actually runs. Separates out unattended install/upgrade into notification handlers. * Gets unattended package migrations working and running * Gets embedded package.xml resources able to install from package migration. * Implements automatic package migrations for package that just declare an xml data manifest. * fix build * small cleanups * fix build * adds some tests * Fix export test * Fix newlines in test for linux * Typo * removes old todos and updates AutomaticPackgeMigrationPlan to use getter with backing field. Co-authored-by: Bjarke Berg <mail@bergmania.dk>
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Umbraco.Cms.Core.Hosting;
|
||||
using Umbraco.Cms.Core.Install.Models;
|
||||
|
||||
namespace Umbraco.Cms.Core.Install.InstallSteps
|
||||
{
|
||||
[InstallSetupStep(InstallationType.NewInstall,
|
||||
"StarterKitCleanup", 32, "Almost done")]
|
||||
internal class StarterKitCleanupStep : InstallSetupStep<object>
|
||||
{
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
|
||||
public StarterKitCleanupStep(IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
}
|
||||
|
||||
public override Task<InstallSetupResult> ExecuteAsync(object model)
|
||||
{
|
||||
var installSteps = InstallStatusTracker.GetStatus().ToArray();
|
||||
var previousStep = installSteps.Single(x => x.Name == "StarterKitDownload");
|
||||
var packageId = Convert.ToInt32(previousStep.AdditionalData["packageId"]);
|
||||
var packageFile = (string)previousStep.AdditionalData["packageFile"];
|
||||
|
||||
CleanupInstallation(packageId, packageFile);
|
||||
|
||||
return Task.FromResult<InstallSetupResult>(null);
|
||||
}
|
||||
|
||||
private void CleanupInstallation(int packageId, string packageFile)
|
||||
{
|
||||
var zipFile = new FileInfo(Path.Combine(_hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.Packages), WebUtility.UrlDecode(packageFile)));
|
||||
|
||||
if (zipFile.Exists)
|
||||
zipFile.Delete();
|
||||
}
|
||||
|
||||
public override bool RequiresExecution(object model)
|
||||
{
|
||||
var installSteps = InstallStatusTracker.GetStatus().ToArray();
|
||||
//this step relies on the previous one completed - because it has stored some information we need
|
||||
if (installSteps.Any(x => x.Name == "StarterKitDownload" && x.AdditionalData.ContainsKey("packageId")) == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Umbraco.Cms.Core.Hosting;
|
||||
using Umbraco.Cms.Core.Install.Models;
|
||||
using Umbraco.Cms.Core.Security;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
|
||||
namespace Umbraco.Cms.Core.Install.InstallSteps
|
||||
{
|
||||
[InstallSetupStep(InstallationType.NewInstall,
|
||||
"StarterKitInstall", 31, "",
|
||||
PerformsAppRestart = true)]
|
||||
internal class StarterKitInstallStep : InstallSetupStep<object>
|
||||
{
|
||||
private readonly IUmbracoApplicationLifetime _umbracoApplicationLifetime;
|
||||
private readonly IBackOfficeSecurityAccessor _backofficeSecurityAccessor;
|
||||
private readonly IPackagingService _packagingService;
|
||||
|
||||
public StarterKitInstallStep(IUmbracoApplicationLifetime umbracoApplicationLifetime, IBackOfficeSecurityAccessor backofficeSecurityAccessor, IPackagingService packagingService)
|
||||
{
|
||||
_umbracoApplicationLifetime = umbracoApplicationLifetime;
|
||||
_backofficeSecurityAccessor = backofficeSecurityAccessor;
|
||||
_packagingService = packagingService;
|
||||
}
|
||||
|
||||
|
||||
public override Task<InstallSetupResult> ExecuteAsync(object model)
|
||||
{
|
||||
var installSteps = InstallStatusTracker.GetStatus().ToArray();
|
||||
var previousStep = installSteps.Single(x => x.Name == "StarterKitDownload");
|
||||
var packageId = Convert.ToInt32(previousStep.AdditionalData["packageId"]);
|
||||
|
||||
InstallBusinessLogic(packageId);
|
||||
|
||||
_umbracoApplicationLifetime.Restart();
|
||||
|
||||
|
||||
|
||||
return Task.FromResult<InstallSetupResult>(null);
|
||||
}
|
||||
|
||||
private void InstallBusinessLogic(int packageId)
|
||||
{
|
||||
var definition = _packagingService.GetInstalledPackageById(packageId);
|
||||
if (definition == null) throw new InvalidOperationException("Not package definition found with id " + packageId);
|
||||
|
||||
var packageFile = new FileInfo(definition.PackagePath);
|
||||
|
||||
_packagingService.InstallCompiledPackageData(definition, packageFile, _backofficeSecurityAccessor.BackOfficeSecurity.GetUserId().ResultOr(-1));
|
||||
}
|
||||
|
||||
public override bool RequiresExecution(object model)
|
||||
{
|
||||
var installSteps = InstallStatusTracker.GetStatus().ToArray();
|
||||
//this step relies on the previous one completed - because it has stored some information we need
|
||||
if (installSteps.Any(x => x.Name == "StarterKitDownload" && x.AdditionalData.ContainsKey("packageId")) == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user