Skip to content

Commit

Permalink
Fix for Issue kevinobee#12 InstallUploadPackage breaks naming convent…
Browse files Browse the repository at this point in the history
…ion for recorded package history
  • Loading branch information
kevinobee committed Jul 21, 2013
1 parent 52aa9b1 commit f1ce68c
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 16 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ Example:

Refer to the `Install Package - Specify Server File Path` above for details of the commands response format.

*Note* that if you have `recordInstallationHistory` enabled you will need to provide `PackageId` and `Description` form parameters in the request that you make.


#### Package - Latest Version

Expand Down
2 changes: 1 addition & 1 deletion build/Build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
<Exec Command="$(CurlExePath) -i -X POST $(TestWebsiteUrl)/services/package/install -H &quot;Accept:application/json&quot; -F &quot;path=$(TestPackagePath)&quot;" />

<!-- Package install via File Upload -->
<Exec Command="$(CurlExePath) -i --form &quot;path=@$(TestPackagePath)&quot; $(TestWebsiteUrl)/services/package/install/fileupload" />
<Exec Command="$(CurlExePath) -i --form &quot;path=@$(TestPackagePath)&quot; $(TestWebsiteUrl)/services/package/install/fileupload -F &quot;PackageId=02&quot; -F &quot;Description=File Upload&quot;" />

<!-- Package latest version check -->
<Exec Command="$(CurlExePath) -i -X POST $(TestWebsiteUrl)/services/package/latestversion --header &quot;Content-Length: 0&quot; " />
Expand Down
15 changes: 14 additions & 1 deletion src/Sitecore.Ship.AspNet/Package/InstallUploadPackageCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,16 @@ public override void HandleRequest(HttpContextBase context)

var file = context.Request.Files[0];

var uploadPackage = GetRequest(context.Request);

PackageManifest manifest;
try
{
var package = new InstallPackage { Path = _tempPackager.GetPackageToInstall(file.InputStream) };
manifest = _repository.AddPackage(package);
_installationRecorder.RecordInstall(package.Path, DateTime.Now);

_installationRecorder.RecordInstall(uploadPackage.PackageId, uploadPackage.Description, DateTime.Now);

}
finally
{
Expand Down Expand Up @@ -84,5 +88,14 @@ private static bool CanHandle(HttpContextBase context)
context.Request.Url.PathAndQuery.EndsWith("/services/package/install/fileupload", StringComparison.InvariantCultureIgnoreCase) &&
context.Request.HttpMethod == "POST";
}

private static InstallUploadPackage GetRequest(HttpRequestBase request)
{
return new InstallUploadPackage
{
PackageId = request.Form["packageId"],
Description = request.Form["description"]
};
}
}
}
2 changes: 2 additions & 0 deletions src/Sitecore.Ship.Core/Contracts/IInstallationRecorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace Sitecore.Ship.Core.Contracts
public interface IInstallationRecorder
{
void RecordInstall(string packageFileName, DateTime dateInstalled);
void RecordInstall(string packageId, string description, DateTime dateInstalled);

InstalledPackage GetLatestPackage();
}
}
8 changes: 8 additions & 0 deletions src/Sitecore.Ship.Core/Domain/InstallUploadPackage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Sitecore.Ship.Core.Domain
{
public class InstallUploadPackage
{
public string PackageId { get; set; }
public string Description { get; set; }
}
}
45 changes: 33 additions & 12 deletions src/Sitecore.Ship.Core/Services/InstallationRecorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;

using Sitecore.Ship.Core.Contracts;
using Sitecore.Ship.Core.Domain;

Expand All @@ -20,18 +21,38 @@ public InstallationRecorder(IPackageHistoryRepository packageHistoryRepository,

public void RecordInstall(string packagePath, DateTime dateInstalled)
{
if (_configurationProvider.Settings.RecordInstallationHistory)
{
var packageId = GetPackageIdFromName(packagePath);
var description = GetDescription(packagePath);
var record = new InstalledPackage
{
DateInstalled = dateInstalled,
PackageId = packageId,
Description = description
};
_packageHistoryRepository.Add(record);
}
if (!_configurationProvider.Settings.RecordInstallationHistory) return;

var packageId = GetPackageIdFromName(packagePath);
var description = GetDescription(packagePath);

var record = new InstalledPackage
{
DateInstalled = dateInstalled,
PackageId = packageId,
Description = description
};

_packageHistoryRepository.Add(record);
}

public void RecordInstall(string packageId, string description, DateTime dateInstalled)
{
if (!_configurationProvider.Settings.RecordInstallationHistory) return;

const string formatString = "Missing {0} parameter, required as installation is being recorded";

if (string.IsNullOrEmpty(packageId)) throw new ArgumentException(string.Format(formatString, "PackageId"));
if (string.IsNullOrEmpty(description)) throw new ArgumentException(string.Format(formatString, "Description"));

var record = new InstalledPackage
{
DateInstalled = dateInstalled,
PackageId = packageId,
Description = description
};

_packageHistoryRepository.Add(record);
}

public InstalledPackage GetLatestPackage()
Expand Down
1 change: 1 addition & 0 deletions src/Sitecore.Ship.Core/Sitecore.Ship.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<Compile Include="Domain\InstallPackage.cs" />
<Compile Include="Contracts\IPackageRepository.cs" />
<Compile Include="Contracts\IPublishService.cs" />
<Compile Include="Domain\InstallUploadPackage.cs" />
<Compile Include="Domain\PackageManifest.cs" />
<Compile Include="Domain\PackageManifestEntry.cs" />
<Compile Include="Domain\PublishLastCompleted.cs" />
Expand Down
4 changes: 3 additions & 1 deletion src/Sitecore.Ship/Package/Install/InstallerModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ private dynamic InstallUploadPackage(dynamic o)
{
var file = Request.Files.FirstOrDefault();

var uploadPackage = this.Bind<InstallUploadPackage>();

if (file == null)
{
return new Response {StatusCode = HttpStatusCode.BadRequest};
Expand All @@ -100,7 +102,7 @@ private dynamic InstallUploadPackage(dynamic o)
{
var package = new InstallPackage { Path = _tempPackager.GetPackageToInstall(file.Value) };
manifest = _repository.AddPackage(package);
_installationRecorder.RecordInstall(package.Path, DateTime.Now);
_installationRecorder.RecordInstall(uploadPackage.PackageId, uploadPackage.Description, DateTime.Now);
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class PackageReaderTests

public PackageReaderTests()
{
_testPackagePath = @"..\..\..\..\acceptance-test\package.update";
_testPackagePath = @"..\..\..\..\acceptance-test\01-package.update";
}

[Fact]
Expand Down

0 comments on commit f1ce68c

Please sign in to comment.