Merge pull request #101 from umbraco/temp-CON-1267

CON-1267 Update Our to not offer v6 to people on < 7.6.0
This commit is contained in:
Shannon Deminick
2017-04-26 18:25:15 +10:00
committed by GitHub
8 changed files with 497 additions and 116 deletions
@@ -1,4 +1,6 @@
@using OurUmbraco.Project
@using OurUmbraco.Repository.Services
@using Umbraco.Core
@using Umbraco.Web
@{
System.Web.Helpers.AntiForgeryConfig.SuppressXFrameOptionsHeader = true;
@@ -7,6 +9,7 @@
int projectId;
if (int.TryParse(Request.QueryString["project_id"], out projectId) == false)
{
//TODO: Exception probably !
return;
}
@@ -14,6 +17,11 @@
var callback = Request.QueryString["callback"];
var Project = ProjectsProvider.GetListing(projectId, false);
if (Project == null)
{
throw new InvalidOperationException("No project found with id " + projectId);
}
var node = new umbraco.NodeFactory.Node(projectId);
var parentId = node.Parent.Id;
var categoryName = node.Parent.Name;
@@ -30,10 +38,26 @@
descCssClass = "wrap";
}
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
var packageRepoService = new PackageRepositoryService(umbracoHelper, umbracoHelper.MembershipHelper, ApplicationContext.Current.DatabaseContext);
//This doesn't matter what we set it to so long as it's below 7.5 since that is the version we introduce strict dependencies
var currUmbracoVersion = new Version(4, 0, 0);
var packageDetails = packageRepoService.GetDetails(Project.ProjectGuid, currUmbracoVersion);
if (packageDetails == null)
{
throw new InvalidOperationException("No package found with id " + Project.ProjectGuid);
}
if (packageDetails.ZipUrl.IsNullOrWhiteSpace())
{
throw new InvalidOperationException("This package is not compatible with the Umbraco version " + currUmbracoVersion);
}
int currentReleaseFile = 0;
if (int.TryParse(Project.CurrentReleaseFile, out currentReleaseFile))
{
var file = Project.PackageFile.Where(x => x.Id == currentReleaseFile).FirstOrDefault();
var file = Project.PackageFile.FirstOrDefault(x => x.Id == currentReleaseFile);
if (file != null)
{
var ct = "This project is compaitible with ";
@@ -66,27 +90,33 @@
}
}
<script type="text/javascript">
jQuery("#projectDescriptionText a").click(function(event){event.preventDefault(); });
jQuery("#projectDescriptionText a").click(function (event) { event.preventDefault(); });
</script>
<ul id="breadcrumb">
<li><a href="/repo?@qs">Repository</a> &rarr;</li>
<li><a href="/repo_category?@qs&category_id=@parentId">@categoryName</a> &rarr;</li>
<li><a href="/repo_category?@qs&category_id=@parentId">@categoryName</a> &rarr;</li>
<li>@Project.Name</li>
</ul>
<div id="project">
@if (currentReleaseFile != 0)
@if (string.IsNullOrWhiteSpace(packageDetails.ZipUrl) == false)
{
<h1 class="projectName">
<span>@Project.Name</span>
<a href="#" title="@Project.Name" rel="@Project.ProjectGuid" class="btn">Install package</a>
</h1>
}
else if (currentReleaseFile != 0)
{
<span style="color: red;">Unfortunately, this package is not compatible with the version of Umbraco you are running.</span><br />
<a href="https://our.umbraco.org/@node.NiceUrl" target="_blank">Go to the package page to learn more</a>
}
else
{
<span style="color: red;">Unfortunately, this package has no current release file to install at the moment.</span><br />
<a href="https://our.umbraco.org/@node.NiceUrl" target="_blank">Go to the package page to learn more</a>}
<a href="https://our.umbraco.org/@node.NiceUrl" target="_blank">Go to the package page to learn more</a>
}
<div class="meta">
<div class="box">
@@ -94,10 +124,10 @@
<dl class="projetProps summary">
<dt>Project owner:</dt>
@{
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
var ownerName = umbracoHelper.MembershipHelper.GetById(Project.VendorId).Name;
}
<dd>@ownerName</dd>
<dd>@ownerName</dd>
<dt>Package downloads</dt>
<dd>@Project.Downloads</dd>
@@ -119,9 +149,9 @@
@if (Project.Stable)
{
<dt>Is Stable:</dt>
<dd>
<span class="green">Project is stable</span>
</dd>
<dd>
<span class="green">Project is stable</span>
</dd>
}
<dt>Current version</dt>
<dd>
@@ -130,9 +160,9 @@
@if (!string.IsNullOrEmpty(Project.LicenseName))
{
<dt>License</dt>
<dd>
<a target="_blank" href="@Project.LicenseUrl">@Project.LicenseName</a>
</dd>
<dd>
<a target="_blank" href="@Project.LicenseUrl">@Project.LicenseName</a>
</dd>
}
</dl>
</div>
@@ -158,7 +188,7 @@
image.Path.EndsWith("jpeg"))
{
<a href="@image.Path" class="projectscreenshot" rel="shadowbox[gallery]">
<img src="@image.Path?bgcolor=fff&width=100&height=100&format=png" style="border: 0;"/>
<img src="@image.Path?bgcolor=fff&width=100&height=100&format=png" style="border: 0;" />
</a>
}
}
@@ -9,6 +9,11 @@ using Umbraco.Core.Cache;
using Umbraco.Web.WebApi;
using System.Net.Http;
using System.Net;
using System.Net.Http.Headers;
using OurUmbraco.Wiki.BusinessLogic;
using Semver;
using Umbraco.Core;
using Umbraco.Web;
namespace OurUmbraco.Repository.Controllers
{
@@ -87,21 +92,90 @@ namespace OurUmbraco.Repository.Controllers
TimeSpan.FromMinutes(1)); //cache for 1 min
}
public Models.PackageDetails GetDetails(Guid id)
/// <summary>
/// Returns the package details for the package Id passed in and ensures that
/// the resulting ZipUrl is the compatible package for the version passed in.
/// </summary>
/// <param name="id"></param>
/// <param name="version">The umbraco version requesting the details, if null than the ZipUrl will be the latest package zip</param>
/// <param name="asFile">pass in true to get the package file otherwise leave blank or set to false to retreive the package details</param>
/// <returns></returns>
public HttpResponseMessage Get(Guid id, string version = null, bool? asFile = false)
{
SemVersion parsed = null;
if (version.IsNullOrWhiteSpace() == false)
{
SemVersion.TryParse(version, out parsed);
}
else
{
//if the version is null then the current umbraco version must be 7.5.x because this endpoint was only ever used by 7.5.x and 7.6.x and above will always
// suppy the version, therefore we can assume that this is 7.5.x, let's make it 7.5.13 which is the latest 7.5 we have right now
parsed = new SemVersion(7, 5, 13);
}
//this should never be null, if it is return not found
if (parsed == null)
{
throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
}
var v = new System.Version(parsed.Major, parsed.Minor, parsed.Patch);
return asFile.HasValue && asFile.Value
? GetPackageFile(id, v)
: GetDetails(id, v);
}
private HttpResponseMessage GetDetails(Guid id, System.Version currUmbracoVersion)
{
//return the results, but cache for 1 minute
var key = string.Format("PackageRepositoryController.GetDetails.{0}", id);
var key = string.Format("PackageRepositoryController.GetDetails.{0}.{1}", id, currUmbracoVersion.ToString(3));
var package = ApplicationContext.ApplicationCache.RuntimeCache.GetCacheItem<PackageDetails>
(key,
() => Service.GetDetails(id),
TimeSpan.FromMinutes(1)); //cache for 1 min
(key,
() =>
{
var details = Service.GetDetails(id, currUmbracoVersion);
if (details.ZipUrl.IsNullOrWhiteSpace())
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "This package is not compatible with the Umbraco version " + currUmbracoVersion));
return details;
},
TimeSpan.FromMinutes(1)); //cache for 1 min
if (package == null)
{
throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
}
return package;
return Request.CreateResponse(HttpStatusCode.OK, package);
}
private HttpResponseMessage GetPackageFile(Guid packageId, System.Version currUmbracoVersion)
{
var pckRepoService = new PackageRepositoryService(Umbraco, Members, DatabaseContext);
var details = pckRepoService.GetDetails(packageId, currUmbracoVersion);
if (details == null)
throw new InvalidOperationException("No package found with id " + packageId);
if (details.ZipUrl.IsNullOrWhiteSpace())
throw new InvalidOperationException("This package is not compatible with the Umbraco version " + currUmbracoVersion);
var wf = new WikiFile(details.ZipFileId);
if (wf == null)
throw new InvalidOperationException("Could not find wiki file by id " + details.ZipFileId);
wf.UpdateDownloadCounter(true, true);
var result = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new ByteArrayContent(wf.ToByteArray())
};
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
return result;
}
}
}
+5 -9
View File
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
namespace OurUmbraco.Repository.Models
{
@@ -27,18 +28,13 @@ namespace OurUmbraco.Repository.Models
public string Category { get; set; }
/// <summary>
/// The latest version of this package
/// </summary>
public string LatestVersion { get; set; }
public PackageOwnerInfo OwnerInfo { get; set; }
/// <summary>
/// This is the minimum Umbraco version that this package supports
/// </summary>
/// <remarks>
/// This could be null if it is a legacy package
/// </remarks>
public string MinimumVersion { get; set; }
public long Score { get; set; }
}
}
@@ -24,7 +24,6 @@ namespace OurUmbraco.Repository.Models
this.Name = package.Name;
this.Icon = package.Icon;
this.LatestVersion = package.LatestVersion;
this.MinimumVersion = package.MinimumVersion;
this.OwnerInfo = package.OwnerInfo;
}
}
@@ -35,6 +34,11 @@ namespace OurUmbraco.Repository.Models
public List<PackageCompatibility> Compatibility { get; set; }
/// <summary>
/// A list of all supported/targeted Umbraco versions for all files for this package
/// </summary>
public string[] TargetedUmbracoVersions { get; set; }
public List<ExternalSource> ExternalSources { get; set; }
public string LicenseName { get; set; }
@@ -44,5 +48,7 @@ namespace OurUmbraco.Repository.Models
public string NetVersion { get; set; }
public string ZipUrl { get; set; }
public int ZipFileId { get; set; }
}
}
+5 -2
View File
@@ -352,9 +352,12 @@ namespace OurUmbraco.Repository
if (xpn.MoveNext())
{
if (xpn.Current is IHasXmlNode)
var xmlNode = xpn.Current as IHasXmlNode;
if (xmlNode != null)
{
Node node = new Node(((IHasXmlNode)xpn.Current).GetNode());
//This will get the latest marked file id
Node node = new Node(xmlNode.GetNode());
string fileId = safeProperty(node, "file");
int _id;
@@ -29,7 +29,7 @@ using Umbraco.Web.Security;
namespace OurUmbraco.Repository.Services
{
internal class PackageRepositoryService
public class PackageRepositoryService
{
private readonly DatabaseContext DatabaseContext;
private readonly MembershipHelper MembershipHelper;
@@ -145,8 +145,19 @@ namespace OurUmbraco.Repository.Services
};
}
public PackageDetails GetDetails(Guid id)
/// <summary>
/// Returns the package details for the package Id passed in and ensures that
/// the resulting ZipUrl is the compatible package for the version passed in.
/// </summary>
/// <param name="id"></param>
/// <param name="version">The umbraco version requesting the details, if null than the ZipUrl will be the latest package zip</param>
/// <returns>
/// If the current umbraco version is not compatible with any package files, the ZipUrl and ZipFileId will be empty
/// </returns>
public PackageDetails GetDetails(Guid id, System.Version version)
{
if (version == null) throw new ArgumentNullException(nameof(version));
// [LK:2016-06-13@CGRT16] We're using XPath as we experienced issues with query Examine for GUIDs,
// (it might worth but we were up against the clock).
// The XPath 'translate' is being used to force the 'packageGuid' to be lowercase for comparison.
@@ -156,16 +167,14 @@ namespace OurUmbraco.Repository.Services
if (item == null)
return null;
return MapContentToPackageDetails(item);
return MapContentToPackageDetails(item, version);
}
private Models.Package MapContentToPackage(IPublishedContent content)
{
if (content == null)
return null;
var wikiFiles = WikiFile.CurrentFiles(content.Id);
return new Models.Package
{
Category = content.Parent.Name,
@@ -177,29 +186,116 @@ namespace OurUmbraco.Repository.Services
Name = content.Name,
Icon = GetThumbnailUrl(BASE_URL + content.GetPropertyValue<string>("defaultScreenshotPath", "/css/img/package2.png"), 154, 281),
LatestVersion = content.GetPropertyValue<string>("version"),
MinimumVersion = GetMinimumVersion(content.GetPropertyValue<int>("file"), wikiFiles.Where(x => x.FileType.InvariantEquals("package"))),
OwnerInfo = GetPackageOwnerInfo(content.GetPropertyValue<int>("owner"), content.GetPropertyValue<bool>("openForCollab", false), content.Id),
Url = string.Concat(BASE_URL, content.Url)
};
}
private PackageDetails MapContentToPackageDetails(IPublishedContent content)
{
if (content == null)
return null;
/// <summary>
/// Returns a PackageDetails instance
/// </summary>
/// <param name="content"></param>
/// <param name="currentUmbracoVersion"></param>
/// <returns>
/// If the current umbraco version is not compatible with any package files, the ZipUrl and ZipFileId will be empty
/// </returns>
private PackageDetails MapContentToPackageDetails(IPublishedContent content, System.Version currentUmbracoVersion)
{
if (currentUmbracoVersion == null) throw new ArgumentNullException(nameof(currentUmbracoVersion));
if (content == null) return null;
var package = MapContentToPackage(content);
var packageDetails = new PackageDetails(package);
if (package == null)
return null;
var wikiFiles = WikiFile.CurrentFiles(content.Id);
packageDetails.Compatibility = GetPackageCompatibility(content);
packageDetails.NetVersion = content.GetPropertyValue<string>("dotNetVersion");
packageDetails.LicenseName = content.GetPropertyValue<string>("licenseName");
packageDetails.LicenseUrl = content.GetPropertyValue<string>("licenseUrl");
packageDetails.Description = content.GetPropertyValue<string>("description").CleanHtmlAttributes();
packageDetails.Images = GetPackageImages(wikiFiles.Where(x => x.FileType.InvariantEquals("screenshot")), 154, 281);
packageDetails.ExternalSources = GetExternalSources(content);
packageDetails.ZipUrl = string.Concat(BASE_URL, "/FileDownload?id=", content.GetPropertyValue<string>("file"));
//TODO: SD: I dunno where these come from or if we care about it?
//var deliCompatVersions = Utils.GetProjectCompatibleVersions(content.Id) ?? new List<string>();
var allPackageFiles = wikiFiles.Where(x => x.FileType.InvariantEquals("package")).ToArray();
//get the strict packages in the correct desc order
var strictPackageFileVersions = GetAllStrictSupportedPackageVersions(allPackageFiles).ToArray();
var packageDetails = new PackageDetails(package)
{
TargetedUmbracoVersions = GetAllFilePackageVersions(allPackageFiles).Select(x => x.ToString(3)).ToArray(),
Compatibility = GetPackageCompatibility(content),
NetVersion = content.GetPropertyValue<string>("dotNetVersion"),
LicenseName = content.GetPropertyValue<string>("licenseName"),
LicenseUrl = content.GetPropertyValue<string>("licenseUrl"),
Description = content.GetPropertyValue<string>("description").CleanHtmlAttributes(),
Images = GetPackageImages(wikiFiles.Where(x => x.FileType.InvariantEquals("screenshot")), 154, 281),
ExternalSources = GetExternalSources(content)
};
var version75 = new System.Version(7, 5, 0);
//this is the file marked as the current/latest release
var currentReleaseFile = content.GetPropertyValue<int>("file");
if (strictPackageFileVersions.Length == 0)
{
//if there are no strict package files then return the latest package file
packageDetails.ZipUrl = string.Concat(BASE_URL, "/FileDownload?id=", currentReleaseFile);
packageDetails.ZipFileId = currentReleaseFile;
}
else if (currentUmbracoVersion < version75)
{
//if the umbraco version is < 7.5 it means that strict package formats are not supported
//TODO: Now we have to do the opposite of below and filter out any package file versions that have strict
// umbraco dependencies applied. Anything that has 7.5 (which would be the very minimum strict dependency) we can check for
//these are ordered by package version desc
var nonStrictPackageFiles = GetNonStrictSupportedPackageVersions(wikiFiles).ToArray();
if (nonStrictPackageFiles.Length != 0)
{
//there might be a case where the 'current release file' is not the latest version found, so let's check if
//the latest release file is included in the non-strict packages and if so we'll use that, otherwise we'll use the latest
var found = nonStrictPackageFiles.FirstOrDefault(x => x.PackageId == currentReleaseFile);
if (found != null)
{
//it's included in the non strict packages so use it
packageDetails.ZipUrl = string.Concat(BASE_URL, "/FileDownload?id=", currentReleaseFile);
packageDetails.ZipFileId = currentReleaseFile;
}
else
{
//use the latest available package version
packageDetails.ZipUrl = string.Concat(BASE_URL, "/FileDownload?id=", nonStrictPackageFiles[0].PackageId);
packageDetails.ZipFileId = nonStrictPackageFiles[0].PackageId;
}
}
}
else
{
//this package has some strict version dependency files, so we need to figure out which one is
// compatible with the current umbraco version passed in and also use the latest available
// package version that is compatible.
int found = -1;
foreach (var pckVersion in strictPackageFileVersions)
{
//if this version will work with the umbraco version, then use it
if (currentUmbracoVersion >= pckVersion.MinUmbracoVersion)
{
found = pckVersion.PackageId;
break;
}
}
if (found != -1)
{
//got one! so use it's id for the file download
packageDetails.ZipUrl = string.Concat(BASE_URL, "/FileDownload?id=", found);
packageDetails.ZipFileId = found;
}
}
packageDetails.Created = content.CreateDate;
return packageDetails;
@@ -222,29 +318,139 @@ namespace OurUmbraco.Repository.Services
.ToList();
}
private string GetMinimumVersion(int filePropertyValue, IEnumerable<WikiFile> packages)
/// <summary>
/// Based on all of the files that this package go retrieve all targeted Umbraco versions
/// </summary>
/// <param name="packages"></param>
/// <returns></returns>
private IEnumerable<System.Version> GetAllFilePackageVersions(IEnumerable<WikiFile> packages)
{
var currentVersion = filePropertyValue;
var latest = packages.FirstOrDefault(x => x.Id == currentVersion);
var allVersions = packages
.Select(x => ConvertToVersion(x.Version.Version))
.WhereNotNull()
.Distinct()
.OrderBy(x => x)
.ToArray();
if (latest == null || string.IsNullOrWhiteSpace(latest.Version.Version) || latest.Version.Version.InvariantEquals("nan"))
return null;
return allVersions;
}
if (latest.Version.Version.InvariantStartsWith("v"))
/// <summary>
/// Based on all of the files that this package go retrieve all targeted Umbraco versions
/// </summary>
/// <param name="packages"></param>
/// <returns>
/// Order from latest package version and lastest min umb version and start from the top, we want to return the most recent
/// available package version for the current Umbraco version
/// </returns>
private IEnumerable<PackageVersionSupport> GetAllStrictSupportedPackageVersions(IEnumerable<WikiFile> packages)
{
var allVersions = packages
.Where(x => x.MinimumVersionStrict.IsNullOrWhiteSpace() == false)
.Select(x => new PackageVersionSupport(x.Id, ConvertToVersion(x.Version.Version), ConvertToVersion(x.MinimumVersionStrict)))
.Where(x => x.PackageVersion != null && x.MinUmbracoVersion != null)
.OrderByDescending(x => x.PackageVersion)
.ThenByDescending(x => x.MinUmbracoVersion)
.ToArray();
return allVersions;
}
/// <summary>
/// Based on all of the files that this package go retrieve all non targeted Umbraco versions
/// </summary>
/// <param name="packages"></param>
/// <returns>
/// Order from latest package version and start from the top, we want to return the most recent
/// available package version for the current Umbraco version
/// </returns>
private IEnumerable<PackageVersionSupport> GetNonStrictSupportedPackageVersions(IEnumerable<WikiFile> packages)
{
var allVersions = packages
.Where(x => x.MinimumVersionStrict.IsNullOrWhiteSpace())
.Select(x => new PackageVersionSupport(x.Id, ConvertToVersion(x.Version.Version), null))
.Where(x => x.PackageVersion != null)
.OrderByDescending(x => x.PackageVersion)
.ToArray();
return allVersions;
}
private class PackageVersionSupport : IEquatable<PackageVersionSupport>
{
private readonly int _packageId;
public PackageVersionSupport(int packageId, System.Version packageVersion, System.Version minUmbracoVersion)
{
var legacyFormat = latest.Version.Version;
_packageId = packageId;
MinUmbracoVersion = minUmbracoVersion;
PackageVersion = packageVersion;
}
if (legacyFormat.InvariantStartsWith("v4"))
public int PackageId
{
get { return _packageId; }
}
public System.Version MinUmbracoVersion { get; private set; }
public System.Version PackageVersion { get; private set; }
public bool Equals(PackageVersionSupport other)
{
return _packageId == other._packageId;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
return obj is PackageVersionSupport && Equals((PackageVersionSupport) obj);
}
public override int GetHashCode()
{
return _packageId;
}
public static bool operator ==(PackageVersionSupport left, PackageVersionSupport right)
{
return left.Equals(right);
}
public static bool operator !=(PackageVersionSupport left, PackageVersionSupport right)
{
return !left.Equals(right);
}
}
/// <summary>
/// Try to convert the string to a real version based on legacy version formats
/// </summary>
/// <param name="ver"></param>
/// <returns></returns>
private System.Version ConvertToVersion(string ver)
{
string normalized = ver;
if (ver.InvariantStartsWith("v"))
{
if (ver.InvariantStartsWith("v4"))
{
return string.Concat(legacyFormat.Replace("v4", "4."), ".0");
normalized = string.Concat(ver.Replace("v4", "4."), ".0");
}
else
{
return string.Join(".", legacyFormat.ToCharArray().Skip(1));
normalized = string.Join(".", ver.ToCharArray().Skip(1));
}
}
return latest.Version.Version;
if (normalized.EndsWith(".x"))
{
normalized = normalized.TrimEnd(".x").EnsureEndsWith(".0");
}
System.Version result;
if (System.Version.TryParse(normalized, out result))
{
return result;
}
return null;
}
private PackageOwnerInfo GetPackageOwnerInfo(int ownerId, bool openForCollab, int contentId)
@@ -4,8 +4,11 @@ using System.ComponentModel;
using System.IO;
using System.Web.Services;
using System.Xml.XPath;
using OurUmbraco.Repository.Services;
using OurUmbraco.Wiki.BusinessLogic;
using umbraco.cms.businesslogic.web;
using Umbraco.Core;
using Umbraco.Web;
namespace OurUmbraco.Repository.webservices
{
@@ -76,12 +79,82 @@ namespace OurUmbraco.Repository.webservices
}
}
/// <summary>
/// This will return the byte array for the package file for the package id specified
/// </summary>
/// <param name="packageGuid"></param>
/// <param name="umbracoVersion">The Version of the umbraco install requesting the package file, this is in the normaly version format such as 7.6.0</param>
/// <returns></returns>
/// <remarks>
/// This endpoint is new and is only referenced from 7.5.14 and above
/// </remarks>
[WebMethod]
public byte[] GetPackageFile(string packageGuid, string umbracoVersion)
{
var umbHelper = new UmbracoHelper(UmbracoContext.Current);
var pckRepoService = new PackageRepositoryService(umbHelper, umbHelper.MembershipHelper, ApplicationContext.Current.DatabaseContext);
System.Version currUmbracoVersion;
if (!System.Version.TryParse(umbracoVersion, out currUmbracoVersion))
throw new InvalidOperationException("Could not parse the version specified " + umbracoVersion);
var guid = new Guid(packageGuid);
var details = pckRepoService.GetDetails(guid, currUmbracoVersion);
if (details == null)
throw new InvalidOperationException("No package found with id " + packageGuid);
if (details.ZipUrl.IsNullOrWhiteSpace())
throw new InvalidOperationException("This package is not compatible with the Umbraco version " + umbracoVersion);
var wf = new WikiFile(details.ZipFileId);
if (wf == null)
throw new InvalidOperationException("Could not find wiki file by id " + details.ZipFileId);
wf.UpdateDownloadCounter(true, true);
return wf.ToByteArray();
}
/// <summary>
/// This will return the byte array for the package file for the package id specified - since this endpoint is ONLY used
/// for Umbraco installs that are less than 7.6.0 and only when legacy XML schema is enabled, we know that this is only used for old umbraco versions
/// </summary>
/// <param name="packageGuid"></param>
/// <returns></returns>
[WebMethod]
public byte[] fetchPackage(string packageGuid)
{
return OurUmbraco.Repository.Packages.PackageFileByGuid(new Guid(packageGuid)).ToByteArray();
var umbHelper = new UmbracoHelper(UmbracoContext.Current);
var pckRepoService = new PackageRepositoryService(umbHelper, umbHelper.MembershipHelper, ApplicationContext.Current.DatabaseContext);
//This doesn't matter what we set it to so long as it's below 7.5 since that is the version we introduce strict dependencies
var currUmbracoVersion = new System.Version(4, 0, 0);
var guid = new Guid(packageGuid);
var details = pckRepoService.GetDetails(guid, currUmbracoVersion);
if (details == null)
throw new InvalidOperationException("No package found with id " + packageGuid);
if (details.ZipUrl.IsNullOrWhiteSpace())
throw new InvalidOperationException("This package is not compatible with your Umbraco version");
var wf = new WikiFile(details.ZipFileId);
if (wf == null)
throw new InvalidOperationException("Could not find wiki file by id " + details.ZipFileId);
wf.UpdateDownloadCounter(true, true);
return wf.ToByteArray();
}
/// <summary>
/// This will return the byte array for the package file for the package id specified - since this endpoint is ONLY used
/// for Umbraco installs that are less than 7.6.0 and only when legacy XML schema is enabled, we know that this is only used for old umbraco versions
/// </summary>
/// <param name="packageGuid"></param>
/// <param name="repoVersion">
/// This is a strange Umbraco version parameter - but it's not really an umbraco version, it's a special/odd version format like Version41
///
/// The repoVersion will never be null for for 7.5.x and this method will never be used by 7.6+
/// </param>
/// <returns></returns>
[WebMethod]
public byte[] fetchPackageByVersion(string packageGuid, string repoVersion)
{
@@ -112,51 +185,59 @@ namespace OurUmbraco.Repository.webservices
break;
}
WikiFile wf = OurUmbraco.Repository.Packages.PackageFileByGuid(new Guid(packageGuid));
var umbHelper = new UmbracoHelper(UmbracoContext.Current);
var pckRepoService = new PackageRepositoryService(umbHelper, umbHelper.MembershipHelper, ApplicationContext.Current.DatabaseContext);
//This doesn't matter what we set it to so long as it's below 7.5 since that is the version we introduce strict dependencies
//Side note: Umbraco 7.5.0 uses this endpoint but since 7.5.0 is already out there's nothing we can do about this, if we pass in 7.5.x then
// the logic will use strict file versions which we cannot do because this endpoint is also used for < 7.5!
// The worst that can happen in this case is that a strict package dependency has been made on 7.5 and then an umbraco 7.5 package
// requests the file, well it won't get it because this will only return non strict packages.
var currUmbracoVersion = new System.Version(4, 0, 0);
var guid = new Guid(packageGuid);
var details = pckRepoService.GetDetails(guid, currUmbracoVersion);
if (details == null)
return new byte[0];
if (wf != null)
if (details.ZipUrl.IsNullOrWhiteSpace())
throw new InvalidOperationException("This package is not compatible with the Umbraco version " + currUmbracoVersion);
var wf = new WikiFile(details.ZipFileId);
//WikiFile wf = OurUmbraco.Repository.Packages.PackageFileByGuid(new Guid(packageGuid));
//if the package doesn't care about the umbraco version needed...
if (wf.Version.Version == "nan")
return wf.ToByteArray();
//if v45
if (version == "v45")
{
int v = 0;
if (int.TryParse(wf.Version.Version.Replace("v", ""), out v))
if (v >= 45)
return wf.ToByteArray();
//if the package doesn't care about the umbraco version needed...
if (wf.Version.Version == "nan")
if (wf.Version.Version == "v47" || wf.Version.Version == "v45")
return wf.ToByteArray();
//if v45
if (version == "v45")
if (wf.Version.Version != version && wf.Version.Version != "nan")
{
int v = 0;
if (int.TryParse(wf.Version.Version.Replace("v", ""), out v))
if (v >= 45)
return wf.ToByteArray();
if (wf.Version.Version == "v47" || wf.Version.Version == "v45")
return wf.ToByteArray();
else if (wf.Version.Version != version && wf.Version.Version != "nan")
{
wf = WikiFile.FindPackageForUmbracoVersion(wf.NodeId, version);
return wf.ToByteArray();
}
wf = WikiFile.FindPackageForUmbracoVersion(wf.NodeId, version);
return wf.ToByteArray();
}
}
return new byte[0];
/*
if (wf.Version.Version != version && wf.Version.Version != "nan")
wf = uWiki.Businesslogic.WikiFile.FindPackageForUmbracoVersion(wf.NodeId, version);
if(wf != null)
return wf.ToByteArray();
else
return new byte[0];*/
return new byte[0];
}
/// <summary>
/// SD: Pretty sure this is no longer used/needed it should probably be removed - maybe really old versions might try to use this?
/// </summary>
/// <param name="packageGuid"></param>
/// <param name="memberKey"></param>
/// <returns></returns>
[WebMethod]
public byte[] fetchProtectedPackage(string packageGuid, string memberKey)
{
@@ -225,24 +306,6 @@ namespace OurUmbraco.Repository.webservices
return item;
}
private static umbraco.cms.businesslogic.contentitem.ContentItem repositoryContentItem(string guid)
{
umbraco.cms.businesslogic.contentitem.ContentItem item = new umbraco.cms.businesslogic.contentitem.ContentItem(1052);
XPathNodeIterator xpn = umbraco.library.GetXmlNodeByXPath("descendant::node[data [@alias = 'repositoryGuid'] = '" + guid + "']");
if (xpn.MoveNext())
{
int id = int.Parse(xpn.Current.GetAttribute("id", "")); ;
item = new umbraco.cms.businesslogic.contentitem.ContentItem(id);
}
return item;
}
private static string md5(string input)
{
@@ -497,6 +497,9 @@ namespace OurUmbraco.Wiki.BusinessLogic
byte[] packageByteArray;
if(File.Exists(path) == false)
throw new InvalidOperationException("The file " + path + " does not exist on the server");
using (var fileStream = File.Open(path, FileMode.Open, FileAccess.Read))
{
packageByteArray = new byte[fileStream.Length];