mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Including Renaud's fixes to package updates
--HG-- branch : 1.x
This commit is contained in:
@@ -67,7 +67,8 @@ namespace Orchard.Packaging.Controllers {
|
||||
|
||||
public ActionResult ReloadUpdates(string returnUrl) {
|
||||
_packageUpdateService.TriggerRefresh();
|
||||
|
||||
_backgroundPackageUpdateStatus.Value = null;
|
||||
|
||||
Services.Notifier.Warning(T("The feed has been notified for update. It might take a few minutes before the updates are displayed."));
|
||||
|
||||
return this.RedirectLocal(returnUrl);
|
||||
@@ -97,8 +98,9 @@ namespace Orchard.Packaging.Controllers {
|
||||
|
||||
IEnumerable<UpdatePackageEntry> updatedPackages = _backgroundPackageUpdateStatus.Value.Entries
|
||||
.Where(updatePackageEntry =>
|
||||
updatePackageEntry.ExtensionsDescriptor.ExtensionType.Equals(extensionType) &&
|
||||
updatePackageEntry.NewVersionToInstall != null);
|
||||
updatePackageEntry.ExtensionsDescriptor.ExtensionType.Equals(extensionType) &&
|
||||
updatePackageEntry.NewVersionToInstall != null)
|
||||
.ToList();
|
||||
|
||||
int totalItemCount = updatedPackages.Count();
|
||||
|
||||
@@ -107,6 +109,7 @@ namespace Orchard.Packaging.Controllers {
|
||||
}
|
||||
|
||||
return View(view, new PackagingListViewModel {
|
||||
LastUpdateCheckUtc = _backgroundPackageUpdateStatus.Value.DateTimeUtc,
|
||||
Entries = updatedPackages,
|
||||
Pager = Shape.Pager(pager).TotalItemCount(totalItemCount)
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@ using Orchard.Environment.Extensions.Models;
|
||||
|
||||
namespace Orchard.Packaging.Models {
|
||||
public class PackagesStatusResult {
|
||||
public DateTime DateTimeUtc { get; set; }
|
||||
public IEnumerable<UpdatePackageEntry> Entries { get; set; }
|
||||
public IEnumerable<Exception> Errors { get; set; }
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ namespace Orchard.Packaging.Services {
|
||||
|
||||
foreach (var source in sources) {
|
||||
var sourceResult = GetPackages(source);
|
||||
result.DateTimeUtc = sourceResult.DateTimeUtc;
|
||||
result.Entries = result.Entries.Concat(sourceResult.Entries);
|
||||
result.Errors = result.Errors.Concat(sourceResult.Errors);
|
||||
}
|
||||
@@ -61,28 +62,25 @@ namespace Orchard.Packaging.Services {
|
||||
}
|
||||
|
||||
private PackagesStatusResult GetPackages(PackagingSource packagingSource) {
|
||||
// Refresh every time 5 minutes AND signal was triggered (not or, otherwise the request would go every 5 minutes, whatever)
|
||||
// Signal is triggered when the Modules page is displayed
|
||||
return _cacheManager.Get(packagingSource.FeedUrl, ctx1 => {
|
||||
ctx1.Monitor(_clock.When(TimeSpan.FromMinutes(5)));
|
||||
// Refresh every 23 hours or when signal was triggered
|
||||
return _cacheManager.Get(packagingSource.FeedUrl, ctx => {
|
||||
ctx.Monitor(_clock.When(TimeSpan.FromMinutes(60 * 23)));
|
||||
ctx.Monitor(_signals.When("PackageUpdateService"));
|
||||
|
||||
return _cacheManager.Get(packagingSource.FeedUrl, ctx2 => {
|
||||
ctx2.Monitor(_signals.When("PackageUpdateService"));
|
||||
|
||||
// We cache exception because we are calling on a network feed, and failure may
|
||||
// take quite some time.
|
||||
var result = new PackagesStatusResult {
|
||||
Entries = new List<UpdatePackageEntry>(),
|
||||
Errors = new List<Exception>()
|
||||
};
|
||||
try {
|
||||
result.Entries = GetPackagesWorker(packagingSource);
|
||||
}
|
||||
catch (Exception e) {
|
||||
result.Errors = new[] { e };
|
||||
}
|
||||
return result;
|
||||
});
|
||||
// We cache exception because we are calling on a network feed, and failure may
|
||||
// take quite some time.
|
||||
var result = new PackagesStatusResult {
|
||||
DateTimeUtc = _clock.UtcNow,
|
||||
Entries = new List<UpdatePackageEntry>(),
|
||||
Errors = new List<Exception>()
|
||||
};
|
||||
try {
|
||||
result.Entries = GetPackagesWorker(packagingSource);
|
||||
}
|
||||
catch (Exception e) {
|
||||
result.Errors = new[] { e };
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using Orchard.Data;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Localization;
|
||||
@@ -43,7 +44,7 @@ namespace Orchard.Packaging.Services {
|
||||
/// <param name="feedUrl">The feed url.</param>
|
||||
/// <returns>The feed identifier.</returns>
|
||||
public int AddSource(string feedTitle, string feedUrl) {
|
||||
PackagingSource packagingSource = new PackagingSource { FeedTitle = feedTitle, FeedUrl = feedUrl };
|
||||
var packagingSource = new PackagingSource { FeedTitle = feedTitle, FeedUrl = feedUrl };
|
||||
|
||||
_packagingSourceRecordRepository.Create(packagingSource);
|
||||
|
||||
@@ -70,20 +71,29 @@ namespace Orchard.Packaging.Services {
|
||||
/// <returns>The list of extensions.</returns>
|
||||
public IEnumerable<PackagingEntry> GetExtensionList(bool includeScreenshots, PackagingSource packagingSource = null, Func<IQueryable<PublishedPackage>, IQueryable<PublishedPackage>> query = null) {
|
||||
return (packagingSource == null ? GetSources() : new[] {packagingSource})
|
||||
.SelectMany(
|
||||
source => {
|
||||
var galleryFeedContext = new GalleryFeedContext(new Uri(source.FeedUrl)) { IgnoreMissingProperties = true };
|
||||
IQueryable<PublishedPackage> packages = includeScreenshots
|
||||
? galleryFeedContext.Packages.Expand("Screenshots")
|
||||
: galleryFeedContext.Packages;
|
||||
|
||||
if (query != null) {
|
||||
packages = query(packages);
|
||||
}
|
||||
.SelectMany(source => GetExtensionListFromSource(includeScreenshots, packagingSource, query, source));
|
||||
}
|
||||
|
||||
return packages.ToList().Select(p => CreatePackageEntry(p, packagingSource, galleryFeedContext.GetReadStreamUri(p)));
|
||||
}
|
||||
);
|
||||
private static IEnumerable<PackagingEntry> GetExtensionListFromSource(bool includeScreenshots, PackagingSource packagingSource, Func<IQueryable<PublishedPackage>, IQueryable<PublishedPackage>> query, PackagingSource source) {
|
||||
var galleryFeedContext = new GalleryFeedContext(new Uri(source.FeedUrl)) { IgnoreMissingProperties = true };
|
||||
|
||||
// Setup compression
|
||||
galleryFeedContext.SendingRequest += (o, e) => {
|
||||
if (e.Request is HttpWebRequest) {
|
||||
(e.Request as HttpWebRequest).AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
|
||||
}
|
||||
};
|
||||
|
||||
// Include screenshots if needed
|
||||
IQueryable<PublishedPackage> packages = includeScreenshots
|
||||
? galleryFeedContext.Packages.Expand("Screenshots")
|
||||
: galleryFeedContext.Packages;
|
||||
|
||||
if (query != null) {
|
||||
packages = query(packages);
|
||||
}
|
||||
|
||||
return packages.ToList().Select(p => CreatePackageEntry(p, packagingSource, galleryFeedContext.GetReadStreamUri(p)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -110,7 +120,7 @@ namespace Orchard.Packaging.Services {
|
||||
#endregion
|
||||
|
||||
private static PackagingEntry CreatePackageEntry(PublishedPackage package, PackagingSource source, Uri downloadUri) {
|
||||
Uri baseUri = new Uri(string.Format("{0}://{1}:{2}/",
|
||||
var baseUri = new Uri(string.Format("{0}://{1}:{2}/",
|
||||
downloadUri.Scheme,
|
||||
downloadUri.Host,
|
||||
downloadUri.Port));
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Packaging.Models;
|
||||
|
||||
namespace Orchard.Packaging.ViewModels {
|
||||
public class PackagingListViewModel {
|
||||
public DateTime? LastUpdateCheckUtc { get; set; }
|
||||
public IEnumerable<UpdatePackageEntry> Entries { get; set; }
|
||||
public dynamic Pager { get; set; }
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
}
|
||||
|
||||
<fieldset class="update-actions">
|
||||
<a class="button" href="@Url.Action("ReloadUpdates", new { returnUrl = ViewContext.RequestContext.HttpContext.Request.ToUrlString()})" >@T("Refresh")</a>
|
||||
<a class="button" href="@Url.Action("ReloadUpdates", new { returnUrl = ViewContext.RequestContext.HttpContext.Request.ToUrlString()})" title="@T("Most recent check for updates: {0}", Model.LastUpdateCheckUtc == null ? T("Unknown") : Display.DateTimeRelative(dateTimeUtc: Model.LastUpdateCheckUtc.Value))">@T("Check for Updates")</a>
|
||||
</fieldset>
|
||||
|
||||
@if (Model.Entries.Count() <= 0) {
|
||||
|
||||
@@ -25,6 +25,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
<fieldset class="update-actions">
|
||||
<a class="button" href="@Url.Action("ReloadUpdates", new { returnUrl = ViewContext.RequestContext.HttpContext.Request.ToUrlString()})" title="@T("Most recent check for updates: {0}", Model.LastUpdateCheckUtc == null ? T("Unknown") : Display.DateTimeRelative(dateTimeUtc: Model.LastUpdateCheckUtc.Value))" >@T("Check for Updates")</a>
|
||||
</fieldset>
|
||||
|
||||
@if (Model.Entries.Count() <= 0) {
|
||||
<p>@T("No theme updates available.").ToString()</p>
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user