2017-07-20 11:21:28 +02:00
|
|
|
|
using System;
|
2014-02-26 16:01:31 +01:00
|
|
|
|
using System.Collections.Generic;
|
2019-01-15 22:08:08 +11:00
|
|
|
|
using System.IO;
|
2014-03-04 19:20:36 +11:00
|
|
|
|
using System.Linq;
|
2019-01-11 14:30:04 +11:00
|
|
|
|
using System.Threading.Tasks;
|
2014-02-26 16:01:31 +01:00
|
|
|
|
using System.Web;
|
2016-09-01 19:06:08 +02:00
|
|
|
|
using Umbraco.Core.Services;
|
2017-05-30 10:50:09 +02:00
|
|
|
|
using Umbraco.Core.Configuration;
|
2019-01-14 14:28:00 +11:00
|
|
|
|
using Umbraco.Core.Models.Packaging;
|
2017-05-30 18:13:11 +02:00
|
|
|
|
using Umbraco.Web.Composing;
|
2014-02-26 16:01:31 +01:00
|
|
|
|
using Umbraco.Web.Install.Models;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Install.InstallSteps
|
|
|
|
|
|
{
|
2014-03-04 19:20:36 +11:00
|
|
|
|
[InstallSetupStep(InstallationType.NewInstall,
|
2017-09-08 19:39:13 +02:00
|
|
|
|
"StarterKitDownload", "starterKit", 30, "Adding a simple website to Umbraco, will make it easier for you to get started",
|
|
|
|
|
|
PerformsAppRestart = true)]
|
2014-03-05 12:08:35 +11:00
|
|
|
|
internal class StarterKitDownloadStep : InstallSetupStep<Guid?>
|
2014-02-26 16:01:31 +01:00
|
|
|
|
{
|
2016-09-01 19:06:08 +02:00
|
|
|
|
private readonly InstallHelper _installHelper;
|
2018-04-06 13:51:54 +10:00
|
|
|
|
private readonly UmbracoContext _umbracoContext;
|
2016-09-01 19:06:08 +02:00
|
|
|
|
private readonly IContentService _contentService;
|
2019-01-11 14:30:04 +11:00
|
|
|
|
private readonly IPackagingService _packageService;
|
2014-02-27 10:16:30 +01:00
|
|
|
|
|
2019-01-11 14:30:04 +11:00
|
|
|
|
public StarterKitDownloadStep(IContentService contentService, IPackagingService packageService, InstallHelper installHelper, UmbracoContext umbracoContext)
|
2014-02-27 10:16:30 +01:00
|
|
|
|
{
|
2016-09-01 19:06:08 +02:00
|
|
|
|
_installHelper = installHelper;
|
2018-04-06 13:51:54 +10:00
|
|
|
|
_umbracoContext = umbracoContext;
|
2016-09-01 19:06:08 +02:00
|
|
|
|
_contentService = contentService;
|
2019-01-11 14:30:04 +11:00
|
|
|
|
_packageService = packageService;
|
2014-02-27 10:16:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-14 14:28:00 +11:00
|
|
|
|
//private const string RepoGuid = "65194810-1f85-11dd-bd0b-0800200c9a66";
|
2014-02-26 16:01:31 +01:00
|
|
|
|
|
2019-01-11 14:30:04 +11:00
|
|
|
|
public override async Task<InstallSetupResult> ExecuteAsync(Guid? starterKitId)
|
2014-02-26 16:01:31 +01:00
|
|
|
|
{
|
2014-03-05 12:08:35 +11:00
|
|
|
|
//if there is no value assigned then use the default starter kit
|
|
|
|
|
|
if (starterKitId.HasValue == false)
|
|
|
|
|
|
{
|
2016-09-01 19:06:08 +02:00
|
|
|
|
var starterKits = _installHelper.GetStarterKits().FirstOrDefault();
|
2014-11-30 15:50:55 +01:00
|
|
|
|
if (starterKits != null)
|
|
|
|
|
|
starterKitId = starterKits.Id;
|
|
|
|
|
|
else
|
|
|
|
|
|
return null;
|
2014-03-05 12:08:35 +11:00
|
|
|
|
}
|
2014-03-05 14:30:17 +11:00
|
|
|
|
else if (starterKitId.Value == Guid.Empty)
|
|
|
|
|
|
{
|
|
|
|
|
|
//if the startkit id is an empty GUID then it means the user has decided not to install one
|
|
|
|
|
|
// so we'll just exit
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2014-02-27 10:16:30 +01:00
|
|
|
|
|
2019-01-15 22:08:08 +11:00
|
|
|
|
var (packageFile, packageId) = await DownloadPackageFilesAsync(starterKitId.Value);
|
2014-02-26 16:01:31 +01:00
|
|
|
|
|
2019-01-16 11:37:20 +01:00
|
|
|
|
UmbracoApplication.Restart();
|
2017-09-08 19:39:13 +02:00
|
|
|
|
|
2014-03-04 11:16:42 +11:00
|
|
|
|
return new InstallSetupResult(new Dictionary<string, object>
|
2014-02-26 16:01:31 +01:00
|
|
|
|
{
|
2019-01-15 22:08:08 +11:00
|
|
|
|
{"packageId", packageId},
|
|
|
|
|
|
{"packageFile", packageFile}
|
2014-03-04 11:16:42 +11:00
|
|
|
|
});
|
2014-02-26 16:01:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-15 22:08:08 +11:00
|
|
|
|
private async Task<(string packageFile, int packageId)> DownloadPackageFilesAsync(Guid kitGuid)
|
2017-07-20 11:21:28 +02:00
|
|
|
|
{
|
2017-05-30 10:50:09 +02:00
|
|
|
|
//Go get the package file from the package repo
|
2019-01-15 22:08:08 +11:00
|
|
|
|
var packageFile = await _packageService.FetchPackageFileAsync(kitGuid, UmbracoVersion.Current, _umbracoContext.Security.GetUserId().ResultOr(0));
|
|
|
|
|
|
if (packageFile == null) throw new InvalidOperationException("Could not fetch package file " + kitGuid);
|
2017-05-30 10:50:09 +02:00
|
|
|
|
|
2019-01-14 14:28:00 +11:00
|
|
|
|
//add an entry to the installedPackages.config
|
2019-01-15 22:08:08 +11:00
|
|
|
|
var compiledPackage = _packageService.GetCompiledPackageInfo(packageFile);
|
2019-01-14 14:28:00 +11:00
|
|
|
|
var packageDefinition = PackageDefinition.FromCompiledPackage(compiledPackage);
|
2019-02-12 14:11:47 +00:00
|
|
|
|
packageDefinition.PackagePath = packageFile.FullName;
|
|
|
|
|
|
|
2019-01-14 14:28:00 +11:00
|
|
|
|
_packageService.SaveInstalledPackage(packageDefinition);
|
2014-02-26 16:01:31 +01:00
|
|
|
|
|
2019-01-15 22:08:08 +11:00
|
|
|
|
InstallPackageFiles(packageDefinition, compiledPackage.PackageFile);
|
2014-02-26 16:01:31 +01:00
|
|
|
|
|
2019-01-15 22:08:08 +11:00
|
|
|
|
return (compiledPackage.PackageFile.Name, packageDefinition.Id);
|
2014-02-26 16:01:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-15 22:08:08 +11:00
|
|
|
|
private void InstallPackageFiles(PackageDefinition packageDefinition, FileInfo packageFile)
|
2014-02-26 16:01:31 +01:00
|
|
|
|
{
|
2019-01-14 14:28:00 +11:00
|
|
|
|
if (packageDefinition == null) throw new ArgumentNullException(nameof(packageDefinition));
|
2014-11-30 15:50:55 +01:00
|
|
|
|
|
2019-01-15 22:08:08 +11:00
|
|
|
|
_packageService.InstallCompiledPackageData(packageDefinition, packageFile, _umbracoContext.Security.GetUserId().ResultOr(0));
|
2014-02-26 16:01:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-11 14:30:04 +11:00
|
|
|
|
public override string View => _packageService.GetAllInstalledPackages().Any() ? string.Empty : base.View;
|
2014-03-05 12:44:38 +11:00
|
|
|
|
|
2014-03-05 14:30:17 +11:00
|
|
|
|
public override bool RequiresExecution(Guid? model)
|
2014-03-04 11:16:42 +11:00
|
|
|
|
{
|
2014-03-05 14:30:17 +11:00
|
|
|
|
//Don't execute if it's an empty GUID - meaning the user has chosen not to install one
|
|
|
|
|
|
if (model.HasValue && model.Value == Guid.Empty)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-11 14:30:04 +11:00
|
|
|
|
if (_packageService.GetAllInstalledPackages().Any())
|
2014-03-04 19:20:36 +11:00
|
|
|
|
return false;
|
|
|
|
|
|
|
2016-09-01 19:06:08 +02:00
|
|
|
|
if (_contentService.GetRootContent().Any())
|
2014-03-04 19:20:36 +11:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
2014-03-04 11:16:42 +11:00
|
|
|
|
}
|
2014-02-26 16:01:31 +01:00
|
|
|
|
}
|
2017-07-20 11:21:28 +02:00
|
|
|
|
}
|