Skip to content

Commit f6f8132

Browse files
committed
Umbraco Installer fix for upgrades so that if values are modified in the form the new values are saved back to the config
1 parent 03b5eb8 commit f6f8132

File tree

4 files changed

+39
-40
lines changed

4 files changed

+39
-40
lines changed

build/transforms/FileSystemProviders.config.install.xdt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
</Provider>
99

1010
<Provider alias="media" type="Our.Umbraco.FileSystemProviders.Azure.AzureBlobFileSystem, Our.Umbraco.FileSystemProviders.Azure" xdt:Locator="Match(type)" xdt:Transform="InsertIfMissing">
11-
<Parameters xdt:Transform="InsertIfMissing">
11+
<Parameters xdt:Transform="Remove"/>
12+
<Parameters xdt:Transform="InsertIfMissing">
1213
<add key="containerName" value="media" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing" />
1314
<add key="rootUrl" value="http://[myAccountName].blob.core.windows.net/" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing" />
1415
<add key="connectionString" value="DefaultEndpointsProtocol=https;AccountName=[myAccountName];AccountKey=[myAccountKey]" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing" />

src/UmbracoFileSystemProviders.Azure.Installer/InstallerController.cs

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,47 @@
11
// --------------------------------------------------------------------------------------------------------------------
22
// <copyright file="InstallerController.cs" company="James Jackson-South">
3-
// Copyright (c) James Jackson-South. All rights reserved. Licensed under the Apache License, Version 2.0.
3+
// Copyright (c) James Jackson-South. All rights reserved.
4+
// Licensed under the Apache License, Version 2.0.
45
// </copyright>
56
// --------------------------------------------------------------------------------------------------------------------
67

7-
using System.Configuration;
88
using System.Runtime.CompilerServices;
9-
using Microsoft.WindowsAzure.Storage;
10-
using Microsoft.WindowsAzure.Storage.Blob;
11-
using Our.Umbraco.FileSystemProviders.Azure.Installer.Enums;
129

10+
// ReSharper disable InconsistentNaming
1311
[assembly: InternalsVisibleTo("Our.Umbraco.FileSystemProviders.Azure.Tests")]
1412
namespace Our.Umbraco.FileSystemProviders.Azure.Installer
1513
{
1614
using System;
1715
using System.Collections.Generic;
16+
using System.Configuration;
1817
using System.Linq;
1918
using System.Web.Hosting;
2019
using System.Web.Http;
2120
using System.Xml;
2221

22+
using Microsoft.WindowsAzure.Storage;
23+
2324
using global::Umbraco.Core;
2425
using global::Umbraco.Core.Logging;
2526
using global::Umbraco.Web.Mvc;
2627
using global::Umbraco.Web.WebApi;
2728
using umbraco.cms.businesslogic.packager.standardPackageActions;
2829

30+
using Enums;
2931
using Models;
3032

3133
[PluginController("FileSystemProviders")]
3234
public class InstallerController : UmbracoAuthorizedApiController
3335
{
3436
private const string ProviderType = "Our.Umbraco.FileSystemProviders.Azure.AzureBlobFileSystem, Our.Umbraco.FileSystemProviders.Azure";
35-
private readonly string _fileSystemProvidersConfigInstallXdtPath = HostingEnvironment.MapPath("~/App_Plugins/UmbracoFileSystemProviders/Azure/Install/FileSystemProviders.config.install.xdt");
36-
private readonly string _fileSystemProvidersConfigPath = HostingEnvironment.MapPath("~/Config/FileSystemProviders.config");
37+
private readonly string fileSystemProvidersConfigInstallXdtPath = HostingEnvironment.MapPath("~/App_Plugins/UmbracoFileSystemProviders/Azure/Install/FileSystemProviders.config.install.xdt");
38+
private readonly string fileSystemProvidersConfigPath = HostingEnvironment.MapPath("~/Config/FileSystemProviders.config");
3739

3840

3941
// /Umbraco/backoffice/FileSystemProviders/Installer/GetParameters
4042
public IEnumerable<Parameter> GetParameters()
4143
{
42-
return GetParametersFromXdt(_fileSystemProvidersConfigInstallXdtPath, _fileSystemProvidersConfigPath);
44+
return GetParametersFromXdt(this.fileSystemProvidersConfigInstallXdtPath, this.fileSystemProvidersConfigPath);
4345
}
4446

4547
// /Umbraco/backoffice/FileSystemProviders/Installer/PostParameters
@@ -49,12 +51,12 @@ public InstallerStatus PostParameters(IEnumerable<Parameter> parameters)
4951
var connection = parameters.SingleOrDefault(k => k.Key == "connectionString").Value;
5052
var containerName = parameters.SingleOrDefault(k => k.Key == "containerName").Value;
5153

52-
if (!this.TestAzureCredentials(connection, containerName))
54+
if (!TestAzureCredentials(connection, containerName))
5355
{
5456
return InstallerStatus.ConnectionError;
5557
}
5658

57-
if (SaveParametersToXdt(_fileSystemProvidersConfigInstallXdtPath, parameters))
59+
if (SaveParametersToXdt(this.fileSystemProvidersConfigInstallXdtPath, parameters))
5860
{
5961
if (!ExecuteFileSystemConfigTransform() || !ExecuteWebConfigTransform())
6062
{
@@ -164,22 +166,32 @@ internal static IEnumerable<Parameter> GetParametersFromXml(string xmlPath)
164166
return settings;
165167
}
166168

167-
private bool TestAzureCredentials(string connectionString, string containerName)
169+
private static bool ExecuteFileSystemConfigTransform()
170+
{
171+
var transFormConfigAction = helper.parseStringToXmlNode("<Action runat=\"install\" undo=\"true\" alias=\"UmbracoFileSystemProviders.Azure.TransformConfig\" file=\"~/Config/FileSystemProviders.config\" xdtfile=\"~/app_plugins/UmbracoFileSystemProviders/Azure/install/FileSystemProviders.config\">" +
172+
"</Action>").FirstChild;
173+
174+
var transformConfig = new PackageActions.TransformConfig();
175+
return transformConfig.Execute("UmbracoFileSystemProviders.Azure", transFormConfigAction);
176+
}
177+
178+
private static bool ExecuteWebConfigTransform()
179+
{
180+
var transFormConfigAction = helper.parseStringToXmlNode("<Action runat=\"install\" undo=\"true\" alias=\"UmbracoFileSystemProviders.Azure.TransformConfig\" file=\"~/web.config\" xdtfile=\"~/app_plugins/UmbracoFileSystemProviders/Azure/install/web.config\">" +
181+
"</Action>").FirstChild;
182+
183+
var transformConfig = new PackageActions.TransformConfig();
184+
return transformConfig.Execute("UmbracoFileSystemProviders.Azure", transFormConfigAction);
185+
}
186+
187+
private static bool TestAzureCredentials(string connectionString, string containerName)
168188
{
169189
var useEmulator = ConfigurationManager.AppSettings[Azure.Constants.Configuration.UseStorageEmulatorKey] != null
170190
&& ConfigurationManager.AppSettings[Azure.Constants.Configuration.UseStorageEmulatorKey]
171191
.Equals("true", StringComparison.InvariantCultureIgnoreCase);
172192
try
173193
{
174-
CloudStorageAccount cloudStorageAccount;
175-
if (useEmulator)
176-
{
177-
cloudStorageAccount = CloudStorageAccount.DevelopmentStorageAccount;
178-
}
179-
else
180-
{
181-
cloudStorageAccount = CloudStorageAccount.Parse(connectionString);
182-
}
194+
var cloudStorageAccount = useEmulator ? CloudStorageAccount.DevelopmentStorageAccount : CloudStorageAccount.Parse(connectionString);
183195

184196
var cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
185197
var blobContainer = cloudBlobClient.GetContainerReference(containerName);
@@ -195,23 +207,5 @@ private bool TestAzureCredentials(string connectionString, string containerName)
195207

196208
return true;
197209
}
198-
199-
private static bool ExecuteFileSystemConfigTransform()
200-
{
201-
var transFormConfigAction = helper.parseStringToXmlNode("<Action runat=\"install\" undo=\"true\" alias=\"UmbracoFileSystemProviders.Azure.TransformConfig\" file=\"~/Config/FileSystemProviders.config\" xdtfile=\"~/app_plugins/UmbracoFileSystemProviders/Azure/install/FileSystemProviders.config\">" +
202-
"</Action>").FirstChild;
203-
204-
var transformConfig = new PackageActions.TransformConfig();
205-
return transformConfig.Execute("UmbracoFileSystemProviders.Azure", transFormConfigAction);
206-
}
207-
208-
private static bool ExecuteWebConfigTransform()
209-
{
210-
var transFormConfigAction = helper.parseStringToXmlNode("<Action runat=\"install\" undo=\"true\" alias=\"UmbracoFileSystemProviders.Azure.TransformConfig\" file=\"~/web.config\" xdtfile=\"~/app_plugins/UmbracoFileSystemProviders/Azure/install/web.config\">" +
211-
"</Action>").FirstChild;
212-
213-
var transformConfig = new PackageActions.TransformConfig();
214-
return transformConfig.Execute("UmbracoFileSystemProviders.Azure", transFormConfigAction);
215-
}
216210
}
217211
}

src/UmbracoFileSystemProviders.Azure.Tests/FileSystemProviders.config.install.xdt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
</Provider>
99

1010
<Provider alias="media" type="Our.Umbraco.FileSystemProviders.Azure.AzureBlobFileSystem, Our.Umbraco.FileSystemProviders.Azure" xdt:Locator="Match(type)" xdt:Transform="InsertIfMissing">
11-
<Parameters xdt:Transform="InsertIfMissing">
11+
<Parameters xdt:Transform="Remove"/>
12+
<Parameters xdt:Transform="InsertIfMissing">
1213
<add key="containerName" value="media" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing" />
1314
<add key="rootUrl" value="http://[myAccountName].blob.core.windows.net/" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing" />
1415
<add key="connectionString" value="DefaultEndpointsProtocol=https;AccountName=[myAccountName];AccountKey=[myAccountKey]" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing" />

src/UmbracoFileSystemProviders.Azure.Tests/UmbracoFileSystemProviders.Azure.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@
240240
</ItemGroup>
241241
<ItemGroup>
242242
<None Include="app.config" />
243+
<None Include="FileSystemProviders.config.install.xdt" />
244+
<None Include="FileSystemProviders.default.config" />
245+
<None Include="FileSystemProviders.upgrade.config" />
243246
<None Include="packages.config" />
244247
<None Include="stylecop.json" />
245248
</ItemGroup>

0 commit comments

Comments
 (0)