70 lines
2.4 KiB
C#
70 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Web;
|
|
using Umbraco.Core;
|
|
using Umbraco.Web.Install.Models;
|
|
|
|
namespace Umbraco.Web.Install.InstallSteps
|
|
{
|
|
[InstallSetupStep("StarterKitDownload", "starterKit", 6)]
|
|
internal class StarterKitDownloadStep : InstallSetupStep<Guid>
|
|
{
|
|
private readonly InstallStatusType _status;
|
|
|
|
public StarterKitDownloadStep(InstallStatusType status)
|
|
{
|
|
_status = status;
|
|
}
|
|
|
|
private const string RepoGuid = "65194810-1f85-11dd-bd0b-0800200c9a66";
|
|
|
|
public override InstallSetupResult Execute(Guid starterKitId)
|
|
{
|
|
if (_status != InstallStatusType.NewInstall) return null;
|
|
|
|
var result = DownloadPackageFiles(starterKitId);
|
|
|
|
return new InstallSetupResult(new Dictionary<string, object>
|
|
{
|
|
{"manifestId", result.Item2},
|
|
{"packageFile", result.Item1}
|
|
});
|
|
}
|
|
|
|
private Tuple<string, int> DownloadPackageFiles(Guid kitGuid)
|
|
{
|
|
var repo = global::umbraco.cms.businesslogic.packager.repositories.Repository.getByGuid(RepoGuid);
|
|
if (repo == null)
|
|
{
|
|
throw new InvalidOperationException("No repository found with id " + RepoGuid);
|
|
}
|
|
if (repo.HasConnection() == false)
|
|
{
|
|
throw new InvalidOperationException("Cannot connect to repository");
|
|
}
|
|
var installer = new global::umbraco.cms.businesslogic.packager.Installer();
|
|
|
|
var tempFile = installer.Import(repo.fetch(kitGuid.ToString()));
|
|
installer.LoadConfig(tempFile);
|
|
var pId = installer.CreateManifest(tempFile, kitGuid.ToString(), RepoGuid);
|
|
|
|
InstallPackageFiles(pId, tempFile);
|
|
|
|
return new Tuple<string, int>(tempFile, pId);
|
|
}
|
|
|
|
private void InstallPackageFiles(int manifestId, string packageFile)
|
|
{
|
|
packageFile = HttpUtility.UrlDecode(packageFile);
|
|
var installer = new global::umbraco.cms.businesslogic.packager.Installer();
|
|
installer.LoadConfig(packageFile);
|
|
installer.InstallFiles(manifestId, packageFile);
|
|
|
|
}
|
|
|
|
public override bool RequiresExecution()
|
|
{
|
|
return _status == InstallStatusType.NewInstall;
|
|
}
|
|
}
|
|
} |