Merge branch '1.9.x' into dev

Conflicts:
	src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs
	src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs
	src/Orchard.Web/Modules/Orchard.Search/Drivers/AdminSearchSettingsPartDriver.cs
	src/Orchard/Environment/DefaultOrchardShell.cs
	src/Orchard/Mvc/HttpContextAccessor.cs
	src/Orchard/Orchard.Framework.csproj
	src/Orchard/Tasks/BackgroundService.cs
This commit is contained in:
Sebastien Ros
2015-09-04 13:15:43 -07:00
86 changed files with 679 additions and 538 deletions

View File

@@ -29,7 +29,8 @@ namespace Lucene.Services {
public static readonly Version LuceneVersion = Version.LUCENE_29;
public static readonly DateTime DefaultMinDateTime = new DateTime(1980, 1, 1);
public static readonly int BatchSize = BooleanQuery.MaxClauseCount;
public LuceneIndexProvider(
IAppDataFolder appDataFolder,
ShellSettings shellSettings,
@@ -152,17 +153,25 @@ namespace Lucene.Services {
}
using (var writer = new IndexWriter(GetDirectory(indexName), _analyzerProvider.GetAnalyzer(indexName), false, IndexWriter.MaxFieldLength.UNLIMITED)) {
var query = new BooleanQuery();
// Process documents by batch as there is a max number of terms a query can contain (1024 by default).
var pageCount = documentIds.Count() / BatchSize + 1;
for (int page = 0; page < pageCount; page++) {
var query = new BooleanQuery();
try {
foreach (var id in documentIds) {
query.Add(new BooleanClause(new TermQuery(new Term("id", id.ToString(CultureInfo.InvariantCulture))), Occur.SHOULD));
try {
var batch = documentIds
.Skip(page * BatchSize)
.Take(BatchSize);
foreach (var id in batch) {
query.Add(new BooleanClause(new TermQuery(new Term("id", id.ToString(CultureInfo.InvariantCulture))), Occur.SHOULD));
}
writer.DeleteDocuments(query);
}
catch (Exception ex) {
Logger.Error(ex, "An unexpected error occured while removing the documents [{0}] from the index [{1}].", String.Join(", ", documentIds), indexName);
}
writer.DeleteDocuments(query);
}
catch (Exception ex) {
Logger.Error(ex, "An unexpected error occured while removing the documents [{0}] from the index [{1}].", String.Join(", ", documentIds), indexName);
}
}
}

View File

@@ -1,7 +1,4 @@
using System;
using System.Linq;
using Orchard.Alias.Implementation.Holder;
using Orchard.Alias.Implementation.Storage;
using Orchard.Environment;
using Orchard.Tasks;
using Orchard.Logging;

View File

@@ -42,6 +42,11 @@ namespace Orchard.AntiSpam.Drivers {
}
protected override void Importing(SpamFilterPart part, ImportContentContext context) {
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
var status = context.Attribute(part.PartDefinition.Name, "Status");
if (status != null) {

View File

@@ -92,10 +92,14 @@ namespace Orchard.ArchiveLater.Drivers {
}
protected override void Importing(ArchiveLaterPart part, ImportContentContext context) {
var scheduledUtc = context.Attribute(part.PartDefinition.Name, "ScheduledArchiveUtc");
if (scheduledUtc != null) {
part.ScheduledArchiveUtc.Value = XmlConvert.ToDateTime(scheduledUtc, XmlDateTimeSerializationMode.Utc);
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
context.ImportAttribute(part.PartDefinition.Name, "ScheduledArchiveUtc", scheduledUtc =>
part.ScheduledArchiveUtc.Value = XmlConvert.ToDateTime(scheduledUtc, XmlDateTimeSerializationMode.Utc)
);
}
protected override void Exporting(ArchiveLaterPart part, ExportContentContext context) {

View File

@@ -154,6 +154,11 @@ namespace Orchard.Autoroute.Drivers {
}
protected override void Importing(AutoroutePart part, ImportContentContext context) {
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
context.ImportAttribute(part.PartDefinition.Name, "Alias", s => part.DisplayAlias = s);
context.ImportAttribute(part.PartDefinition.Name, "CustomPattern", s => part.CustomPattern = s);
context.ImportAttribute(part.PartDefinition.Name, "UseCustomPattern", s => part.UseCustomPattern = XmlHelper.Parse<bool>(s));

View File

@@ -1,4 +1,5 @@
using Orchard.Autoroute.Models;
using Orchard.ContentManagement;
using Orchard.Autoroute.Services;
using Orchard.Autoroute.Settings;
using Orchard.ContentManagement;

View File

@@ -53,10 +53,14 @@ namespace Orchard.Blogs.Drivers {
}
protected override void Importing(BlogArchivesPart part, ImportContentContext context) {
var blog = context.Attribute(part.PartDefinition.Name, "Blog");
if (blog != null) {
part.BlogId = context.GetItemFromSession(blog).Id;
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
context.ImportAttribute(part.PartDefinition.Name, "Blog", blog =>
part.BlogId = context.GetItemFromSession(blog).Id
);
}
protected override void Exporting(BlogArchivesPart part, ExportContentContext context) {

View File

@@ -43,20 +43,22 @@ namespace Orchard.Blogs.Drivers {
}
protected override void Importing(BlogPart part, ContentManagement.Handlers.ImportContentContext context) {
var description = context.Attribute(part.PartDefinition.Name, "Description");
if (description != null) {
part.Description = description;
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
var postCount = context.Attribute(part.PartDefinition.Name, "PostCount");
if (postCount != null) {
part.PostCount = Convert.ToInt32(postCount);
}
context.ImportAttribute(part.PartDefinition.Name, "Description", description =>
part.Description = description
);
var feedProxyUrl = context.Attribute(part.PartDefinition.Name, "FeedProxyUrl");
if (feedProxyUrl != null) {
part.FeedProxyUrl = feedProxyUrl;
}
context.ImportAttribute(part.PartDefinition.Name, "PostCount", postCount =>
part.PostCount = Convert.ToInt32(postCount)
);
context.ImportAttribute(part.PartDefinition.Name, "FeedProxyUrl", feedProxyUrl =>
part.FeedProxyUrl = feedProxyUrl
);
}
protected override void Exporting(BlogPart part, ContentManagement.Handlers.ExportContentContext context) {

View File

@@ -66,22 +66,25 @@ namespace Orchard.Blogs.Drivers {
}
protected override void Importing(RecentBlogPostsPart part, ImportContentContext context) {
var blog = context.Attribute(part.PartDefinition.Name, "Blog");
if (blog != null) {
part.BlogId = context.GetItemFromSession(blog).Id;
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
var count = context.Attribute(part.PartDefinition.Name, "Count");
if (count != null) {
part.Count = Convert.ToInt32(count);
}
context.ImportAttribute(part.PartDefinition.Name, "Blog", blog =>
part.BlogId = context.GetItemFromSession(blog).Id
);
context.ImportAttribute(part.PartDefinition.Name, "Count", count =>
part.Count = Convert.ToInt32(count)
);
}
protected override void Exporting(RecentBlogPostsPart part, ExportContentContext context) {
var blog = _contentManager.Get(part.BlogId);
var blogIdentity = _contentManager.GetItemMetadata(blog).Identity;
context.Element(part.PartDefinition.Name).SetAttributeValue("Blog", blogIdentity);
context.Element(part.PartDefinition.Name).SetAttributeValue("Blog", blogIdentity);
context.Element(part.PartDefinition.Name).SetAttributeValue("Count", part.Count);
}
}

View File

@@ -132,71 +132,65 @@ namespace Orchard.Comments.Drivers {
}
protected override void Importing(CommentPart part, ContentManagement.Handlers.ImportContentContext context) {
var author = context.Attribute(part.PartDefinition.Name, "Author");
if (author != null) {
part.Record.Author = author;
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
var siteName = context.Attribute(part.PartDefinition.Name, "SiteName");
if (siteName != null) {
part.Record.SiteName = siteName;
}
context.ImportAttribute(part.PartDefinition.Name, "Author", author =>
part.Record.Author = author
);
var userName = context.Attribute(part.PartDefinition.Name, "UserName");
if (userName != null) {
part.Record.UserName = userName;
}
context.ImportAttribute(part.PartDefinition.Name, "SiteName", siteName =>
part.Record.SiteName = siteName
);
var email = context.Attribute(part.PartDefinition.Name, "Email");
if (email != null) {
part.Record.Email = email;
}
context.ImportAttribute(part.PartDefinition.Name, "UserName", userName =>
part.Record.UserName = userName
);
var position = context.Attribute(part.PartDefinition.Name, "Position");
if (position != null) {
part.Record.Position = decimal.Parse(position, CultureInfo.InvariantCulture);
}
context.ImportAttribute(part.PartDefinition.Name, "Email", email =>
part.Record.Email = email
);
var status = context.Attribute(part.PartDefinition.Name, "Status");
if (status != null) {
part.Record.Status = (CommentStatus)Enum.Parse(typeof(CommentStatus), status);
}
context.ImportAttribute(part.PartDefinition.Name, "Position", position =>
part.Record.Position = decimal.Parse(position, CultureInfo.InvariantCulture)
);
var commentDate = context.Attribute(part.PartDefinition.Name, "CommentDateUtc");
if (commentDate != null) {
part.Record.CommentDateUtc = XmlConvert.ToDateTime(commentDate, XmlDateTimeSerializationMode.Utc);
}
context.ImportAttribute(part.PartDefinition.Name, "Status", status =>
part.Record.Status = (CommentStatus)Enum.Parse(typeof(CommentStatus), status)
);
var text = context.Attribute(part.PartDefinition.Name, "CommentText");
if (text != null) {
part.Record.CommentText = text;
}
context.ImportAttribute(part.PartDefinition.Name, "CommentDateUtc", commentDate =>
part.Record.CommentDateUtc = XmlConvert.ToDateTime(commentDate, XmlDateTimeSerializationMode.Utc)
);
var commentedOn = context.Attribute(part.PartDefinition.Name, "CommentedOn");
if (commentedOn != null) {
context.ImportAttribute(part.PartDefinition.Name, "CommentText", text =>
part.Record.CommentText = text
);
context.ImportAttribute(part.PartDefinition.Name, "CommentedOn", commentedOn => {
var contentItem = context.GetItemFromSession(commentedOn);
if (contentItem != null) {
part.Record.CommentedOn = contentItem.Id;
}
contentItem.As<CommentsPart>().Record.CommentPartRecords.Add(part.Record);
}
});
var repliedOn = context.Attribute(part.PartDefinition.Name, "RepliedOn");
if (repliedOn != null) {
context.ImportAttribute(part.PartDefinition.Name, "RepliedOn", repliedOn => {
var contentItem = context.GetItemFromSession(repliedOn);
if (contentItem != null) {
part.Record.RepliedOn = contentItem.Id;
}
}
});
var commentedOnContainer = context.Attribute(part.PartDefinition.Name, "CommentedOnContainer");
if (commentedOnContainer != null) {
context.ImportAttribute(part.PartDefinition.Name, "CommentedOnContainer", commentedOnContainer => {
var container = context.GetItemFromSession(commentedOnContainer);
if (container != null) {
part.Record.CommentedOnContainer = container.Id;
}
}
});
}
protected override void Exporting(CommentPart part, ContentManagement.Handlers.ExportContentContext context) {

View File

@@ -111,20 +111,22 @@ namespace Orchard.Comments.Drivers {
}
protected override void Importing(CommentsPart part, ContentManagement.Handlers.ImportContentContext context) {
var commentsShown = context.Attribute(part.PartDefinition.Name, "CommentsShown");
if (commentsShown != null) {
part.CommentsShown = Convert.ToBoolean(commentsShown);
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
var commentsActive = context.Attribute(part.PartDefinition.Name, "CommentsActive");
if (commentsActive != null) {
part.CommentsActive = Convert.ToBoolean(commentsActive);
}
context.ImportAttribute(part.PartDefinition.Name, "CommentsShown", commentsShown =>
part.CommentsShown = Convert.ToBoolean(commentsShown)
);
var threadedComments = context.Attribute(part.PartDefinition.Name, "ThreadedComments");
if (threadedComments != null) {
part.ThreadedComments = Convert.ToBoolean(threadedComments);
}
context.ImportAttribute(part.PartDefinition.Name, "CommentsActive", commentsActive =>
part.CommentsActive = Convert.ToBoolean(commentsActive)
);
context.ImportAttribute(part.PartDefinition.Name, "ThreadedComments", threadedComments =>
part.ThreadedComments = Convert.ToBoolean(threadedComments)
);
}
protected override void Exporting(CommentsPart part, ContentManagement.Handlers.ExportContentContext context) {

View File

@@ -162,6 +162,11 @@ namespace Orchard.ContentPermissions.Drivers {
}
protected override void Importing(ContentPermissionsPart part, ImportContentContext context) {
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
context.ImportAttribute(part.PartDefinition.Name, "Enabled", s => part.Enabled = XmlConvert.ToBoolean(s));
context.ImportAttribute(part.PartDefinition.Name, "ViewContent", s => part.ViewContent = s);
context.ImportAttribute(part.PartDefinition.Name, "EditContent", s => part.EditContent = s);

View File

@@ -60,14 +60,18 @@ namespace Orchard.ContentPicker.Drivers {
}
protected override void Importing(ContentMenuItemPart part, ImportContentContext context) {
var contentItemId = context.Attribute(part.PartDefinition.Name, "ContentItem");
if (contentItemId != null) {
var contentItem = context.GetItemFromSession(contentItemId);
part.Content = contentItem;
}
else {
part.Content = null;
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
context.ImportAttribute(part.PartDefinition.Name, "ContentItem",
contentItemId => {
var contentItem = context.GetItemFromSession(contentItemId);
part.Content = contentItem;
}, () =>
part.Content = null
);
}
protected override void Exporting(ContentMenuItemPart part, ExportContentContext context) {

View File

@@ -59,21 +59,20 @@ namespace Orchard.CustomForms.Drivers {
}
protected override void Importing(CustomFormPart part, ImportContentContext context) {
IfNotNull(context.Attribute(part.PartDefinition.Name, "ContentType"), x => part.Record.ContentType = x);
IfNotNull(context.Attribute(part.PartDefinition.Name, "SaveContentItem"), x => part.Record.SaveContentItem = Boolean.Parse(x));
IfNotNull(context.Attribute(part.PartDefinition.Name, "CustomMessage"), x => part.Record.CustomMessage = Boolean.Parse(x));
IfNotNull(context.Attribute(part.PartDefinition.Name, "Message"), x => part.Record.Message = x);
IfNotNull(context.Attribute(part.PartDefinition.Name, "Redirect"), x => part.Record.Redirect = Boolean.Parse(x));
IfNotNull(context.Attribute(part.PartDefinition.Name, "RedirectUrl"), x => part.Record.RedirectUrl = x);
IfNotNull(context.Attribute(part.PartDefinition.Name, "SubmitButtonText"), x => part.Record.SubmitButtonText = x);
}
private static void IfNotNull<T>(T value, Action<T> then) {
if (value != null) {
then(value);
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
}
context.ImportAttribute(part.PartDefinition.Name, "ContentType", x => part.Record.ContentType = x);
context.ImportAttribute(part.PartDefinition.Name, "SaveContentItem", x => part.Record.SaveContentItem = Boolean.Parse(x));
context.ImportAttribute(part.PartDefinition.Name, "CustomMessage", x => part.Record.CustomMessage = Boolean.Parse(x));
context.ImportAttribute(part.PartDefinition.Name, "Message", x => part.Record.Message = x);
context.ImportAttribute(part.PartDefinition.Name, "Redirect", x => part.Record.Redirect = Boolean.Parse(x));
context.ImportAttribute(part.PartDefinition.Name, "RedirectUrl", x => part.Record.RedirectUrl = x);
context.ImportAttribute(part.PartDefinition.Name, "SubmitButtonText", x => part.Record.SubmitButtonText = x);
}
protected override void Exporting(CustomFormPart part, ExportContentContext context) {
context.Element(part.PartDefinition.Name).SetAttributeValue("ContentType", part.Record.ContentType);
context.Element(part.PartDefinition.Name).SetAttributeValue("SaveContentItem", part.Record.SaveContentItem);

View File

@@ -140,6 +140,11 @@ namespace Orchard.Layouts.Drivers {
}
protected override void Importing(LayoutPart part, ImportContentContext context) {
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
context.ImportChildEl(part.PartDefinition.Name, "LayoutData", s => {
part.LayoutData = s;
_layoutManager.Importing(new ImportLayoutContext {

View File

@@ -290,11 +290,11 @@ namespace Orchard.Layouts.Drivers {
var query = element.QueryId != null ? _contentManager.Get<QueryPart>(element.QueryId.Value) : default(QueryPart);
var layout = query != null && element.LayoutId != null ? _layoutRepository.Get(element.LayoutId.Value) : default(LayoutRecord);
var queryIdentity = query != null ? _contentManager.GetItemMetadata(query).Identity.ToString() : default(string);
var layoutIndex = layout != null ? query.Layouts.IndexOf(layout) : default(int?);
var layoutIndex = layout != null ? query.Layouts.IndexOf(layout) : -1; // -1 is the Default Layout.
if (queryIdentity != null && layoutIndex != null) {
if (queryIdentity != null) {
context.ExportableData["QueryId"] = queryIdentity;
context.ExportableData["LayoutIndex"] = layoutIndex.Value.ToString();
context.ExportableData["LayoutIndex"] = layoutIndex.ToString();
}
}

View File

@@ -16,7 +16,6 @@ namespace Orchard.Layouts.Handlers {
private readonly IContentPartDisplay _contentPartDisplay;
private readonly IShapeDisplay _shapeDisplay;
private readonly ILayoutSerializer _serializer;
private readonly IStaticHttpContextScopeFactory _staticHttpContextScopeFactory;
private readonly IAliasService _aliasService;
public LayoutPartHandler(
@@ -26,7 +25,6 @@ namespace Orchard.Layouts.Handlers {
IContentPartDisplay contentPartDisplay,
IShapeDisplay shapeDisplay,
ILayoutSerializer serializer,
IStaticHttpContextScopeFactory staticHttpContextScopeFactory,
IAliasService aliasService) {
_layoutManager = layoutManager;
@@ -34,7 +32,6 @@ namespace Orchard.Layouts.Handlers {
_contentPartDisplay = contentPartDisplay;
_shapeDisplay = shapeDisplay;
_serializer = serializer;
_staticHttpContextScopeFactory = staticHttpContextScopeFactory;
_aliasService = aliasService;
Filters.Add(StorageFilter.For(repository));
@@ -44,22 +41,13 @@ namespace Orchard.Layouts.Handlers {
private void IndexLayout(IndexContentContext context, LayoutPart part) {
var layoutShape = _contentPartDisplay.BuildDisplay(part);
var layoutHtml = RenderShape(layoutShape);
var layoutHtml = _shapeDisplay.Display(layoutShape);
context.DocumentIndex
.Add("body", layoutHtml).RemoveTags().Analyze()
.Add("format", "html").Store();
}
/// <summary>
/// This method of rendering is safe even in background tasks.
/// </summary>
private string RenderShape(dynamic shape) {
using (_staticHttpContextScopeFactory.CreateStaticScope()) {
return _shapeDisplay.Display(shape);
}
}
private void UpdateTemplateClients(PublishContentContext context, LayoutPart part) {
UpdateTemplateClients(part);
}

View File

@@ -108,16 +108,19 @@ namespace Orchard.Localization.Drivers {
}
protected override void Importing(LocalizationPart part, ContentManagement.Handlers.ImportContentContext context) {
var masterContentItem = context.Attribute(part.PartDefinition.Name, "MasterContentItem");
if (masterContentItem != null) {
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
context.ImportAttribute(part.PartDefinition.Name, "MasterContentItem", masterContentItem => {
var contentItem = context.GetItemFromSession(masterContentItem);
if (contentItem != null) {
part.MasterContentItem = contentItem;
}
}
});
var culture = context.Attribute(part.PartDefinition.Name, "Culture");
if (culture != null) {
context.ImportAttribute(part.PartDefinition.Name, "Culture", culture => {
var targetCulture = _cultureManager.GetCultureByName(culture);
// Add Culture.
if (targetCulture == null && _cultureManager.IsValidCulture(culture)) {
@@ -125,7 +128,7 @@ namespace Orchard.Localization.Drivers {
targetCulture = _cultureManager.GetCultureByName(culture);
}
part.Culture = targetCulture;
}
});
}
protected override void Exporting(LocalizationPart part, ContentManagement.Handlers.ExportContentContext context) {

View File

@@ -17,10 +17,14 @@ namespace Orchard.MediaLibrary.Drivers {
}
protected override void Importing(AudioPart part, ContentManagement.Handlers.ImportContentContext context) {
var length = context.Attribute(part.PartDefinition.Name, "Length");
if (length != null) {
part.Length = int.Parse(length);
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
context.ImportAttribute(part.PartDefinition.Name, "Length", length =>
part.Length = int.Parse(length)
);
}
}
}

View File

@@ -17,10 +17,14 @@ namespace Orchard.MediaLibrary.Drivers {
}
protected override void Importing(DocumentPart part, ContentManagement.Handlers.ImportContentContext context) {
var length = context.Attribute(part.PartDefinition.Name, "Length");
if (length != null) {
part.Length = int.Parse(length);
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
context.ImportAttribute(part.PartDefinition.Name, "Length", length =>
part.Length = int.Parse(length)
);
}
}
}

View File

@@ -20,15 +20,18 @@ namespace Orchard.MediaLibrary.Drivers {
}
protected override void Importing(ImagePart part, ContentManagement.Handlers.ImportContentContext context) {
var height = context.Attribute(part.PartDefinition.Name, "Height");
if (height != null) {
part.Height = int.Parse(height);
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
var width = context.Attribute(part.PartDefinition.Name, "Width");
if (width != null) {
part.Width = int.Parse(width);
}
context.ImportAttribute(part.PartDefinition.Name, "Height", height =>
part.Height = int.Parse(height)
);
context.ImportAttribute(part.PartDefinition.Name, "Width", width =>
part.Width = int.Parse(width)
);
}
}
}

View File

@@ -36,30 +36,30 @@ namespace Orchard.MediaLibrary.Drivers {
}
protected override void Importing(MediaPart part, ContentManagement.Handlers.ImportContentContext context) {
var mimeType = context.Attribute(part.PartDefinition.Name, "MimeType");
if (mimeType != null) {
part.MimeType = mimeType;
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
var caption = context.Attribute(part.PartDefinition.Name, "Caption");
if (caption != null) {
part.Caption = caption;
}
context.ImportAttribute(part.PartDefinition.Name, "MimeType", mimeType =>
part.MimeType = mimeType
);
var alternateText = context.Attribute(part.PartDefinition.Name, "AlternateText");
if (alternateText != null) {
part.AlternateText = alternateText;
}
context.ImportAttribute(part.PartDefinition.Name, "Caption", caption =>
part.Caption = caption
);
var folderPath = context.Attribute(part.PartDefinition.Name, "FolderPath");
if (folderPath != null) {
part.FolderPath = folderPath;
}
context.ImportAttribute(part.PartDefinition.Name, "AlternateText", alternateText =>
part.AlternateText = alternateText
);
var fileName = context.Attribute(part.PartDefinition.Name, "FileName");
if (fileName != null) {
part.FileName = fileName;
}
context.ImportAttribute(part.PartDefinition.Name, "FolderPath", folderPath =>
part.FolderPath = folderPath
);
context.ImportAttribute(part.PartDefinition.Name, "FileName", fileName =>
part.FileName = fileName
);
}
protected override void Exporting(MediaPart part, ContentManagement.Handlers.ExportContentContext context) {

View File

@@ -17,10 +17,14 @@ namespace Orchard.MediaLibrary.Drivers {
}
protected override void Importing(OEmbedPart part, ContentManagement.Handlers.ImportContentContext context) {
var source = context.Attribute(part.PartDefinition.Name, "Source");
if (source != null) {
part.Source = source;
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
context.ImportAttribute(part.PartDefinition.Name, "Source", source =>
part.Source = source
);
}
}
}

View File

@@ -17,10 +17,14 @@ namespace Orchard.MediaLibrary.Drivers {
}
protected override void Importing(VideoPart part, ContentManagement.Handlers.ImportContentContext context) {
var length = context.Attribute(part.PartDefinition.Name, "Length");
if (length != null) {
part.Length = int.Parse(length);
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
context.ImportAttribute(part.PartDefinition.Name, "Length", length =>
part.Length = int.Parse(length)
);
}
}
}

View File

@@ -85,6 +85,11 @@ namespace Orchard.MediaProcessing.Drivers {
}
protected override void Importing(ImageProfilePart part, ImportContentContext context) {
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
var element = context.Data.Element(part.PartDefinition.Name);
part.Name = element.Attribute("Name").Value;

View File

@@ -54,8 +54,13 @@ namespace Orchard.Projections.Drivers {
}
protected override void Importing(NavigationQueryPart part, ImportContentContext context) {
IfNotNull(context.Attribute(part.PartDefinition.Name, "Items"), x => part.Record.Items = Int32.Parse(x));
IfNotNull(context.Attribute(part.PartDefinition.Name, "Offset"), x => part.Record.Skip = Int32.Parse(x));
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
context.ImportAttribute(part.PartDefinition.Name, "Items", x => part.Record.Items = Int32.Parse(x));
context.ImportAttribute(part.PartDefinition.Name, "Offset", x => part.Record.Skip = Int32.Parse(x));
}
protected override void Imported(NavigationQueryPart part, ImportContentContext context) {
@@ -65,13 +70,7 @@ namespace Orchard.Projections.Drivers {
part.Record.QueryPartRecord = context.GetItemFromSession(query).As<QueryPart>().Record;
}
}
private static void IfNotNull<T>(T value, Action<T> then) where T : class {
if(value != null) {
then(value);
}
}
protected override void Exporting(NavigationQueryPart part, ExportContentContext context) {
context.Element(part.PartDefinition.Name).SetAttributeValue("Items", part.Record.Items);
context.Element(part.PartDefinition.Name).SetAttributeValue("Offset", part.Record.Skip);

View File

@@ -294,12 +294,17 @@ namespace Orchard.Projections.Drivers {
}
protected override void Importing(ProjectionPart part, ImportContentContext context) {
IfNotNull(context.Attribute(part.PartDefinition.Name, "Items"), x => part.Record.Items = Int32.Parse(x));
IfNotNull(context.Attribute(part.PartDefinition.Name, "ItemsPerPage"), x => part.Record.ItemsPerPage = Int32.Parse(x));
IfNotNull(context.Attribute(part.PartDefinition.Name, "Offset"), x => part.Record.Skip = Int32.Parse(x));
IfNotNull(context.Attribute(part.PartDefinition.Name, "PagerSuffix"), x => part.Record.PagerSuffix = x);
IfNotNull(context.Attribute(part.PartDefinition.Name, "MaxItems"), x => part.Record.MaxItems = Int32.Parse(x));
IfNotNull(context.Attribute(part.PartDefinition.Name, "DisplayPager"), x => part.Record.DisplayPager = Boolean.Parse(x));
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
context.ImportAttribute(part.PartDefinition.Name, "Items", x => part.Record.Items = Int32.Parse(x));
context.ImportAttribute(part.PartDefinition.Name, "ItemsPerPage", x => part.Record.ItemsPerPage = Int32.Parse(x));
context.ImportAttribute(part.PartDefinition.Name, "Offset", x => part.Record.Skip = Int32.Parse(x));
context.ImportAttribute(part.PartDefinition.Name, "PagerSuffix", x => part.Record.PagerSuffix = x);
context.ImportAttribute(part.PartDefinition.Name, "MaxItems", x => part.Record.MaxItems = Int32.Parse(x));
context.ImportAttribute(part.PartDefinition.Name, "DisplayPager", x => part.Record.DisplayPager = Boolean.Parse(x));
}
protected override void Imported(ProjectionPart part, ImportContentContext context) {
@@ -318,13 +323,7 @@ namespace Orchard.Projections.Drivers {
}
}
}
private static void IfNotNull<T>(T value, Action<T> then) {
if(value != null) {
then(value);
}
}
protected override void Exporting(ProjectionPart part, ExportContentContext context) {
context.Element(part.PartDefinition.Name).SetAttributeValue("Items", part.Record.Items);
context.Element(part.PartDefinition.Name).SetAttributeValue("ItemsPerPage", part.Record.ItemsPerPage);

View File

@@ -103,6 +103,11 @@ namespace Orchard.Projections.Drivers {
}
protected override void Importing(QueryPart part, ImportContentContext context) {
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
var queryElement = context.Data.Element(part.PartDefinition.Name);
part.Record.FilterGroups.Clear();

View File

@@ -110,10 +110,14 @@ namespace Orchard.PublishLater.Drivers {
}
protected override void Importing(PublishLaterPart part, ImportContentContext context) {
var scheduledUtc = context.Attribute(part.PartDefinition.Name, "ScheduledPublishUtc");
if (scheduledUtc != null) {
part.ScheduledPublishUtc.Value = XmlConvert.ToDateTime(scheduledUtc, XmlDateTimeSerializationMode.Utc);
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
context.ImportAttribute(part.PartDefinition.Name, "ScheduledPublishUtc", scheduledUtc =>
part.ScheduledPublishUtc.Value = XmlConvert.ToDateTime(scheduledUtc, XmlDateTimeSerializationMode.Utc)
);
}
protected override void Exporting(PublishLaterPart part, ExportContentContext context) {

View File

@@ -96,29 +96,32 @@ namespace Orchard.Roles.Drivers {
}
protected override void Importing(UserRolesPart part, ContentManagement.Handlers.ImportContentContext context) {
var roles = context.Attribute(part.PartDefinition.Name, "Roles");
if(string.IsNullOrEmpty(roles)) {
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
var userRoles = roles.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries);
context.ImportAttribute(part.PartDefinition.Name, "Roles", roles => {
// create new roles
foreach (var role in userRoles) {
var roleRecord = _roleService.GetRoleByName(role);
var userRoles = roles.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
// create the role if it doesn't already exist
if (roleRecord == null) {
_roleService.CreateRole(role);
// create new roles
foreach (var role in userRoles) {
var roleRecord = _roleService.GetRoleByName(role);
// create the role if it doesn't already exist
if (roleRecord == null) {
_roleService.CreateRole(role);
}
}
}
var currentUserRoleRecords = _userRolesRepository.Fetch(x => x.UserId == part.ContentItem.Id).ToList();
var currentRoleRecords = currentUserRoleRecords.Select(x => x.Role).ToList();
var targetRoleRecords = userRoles.Select(x => _roleService.GetRoleByName(x)).ToList();
foreach (var addingRole in targetRoleRecords.Where(x => !currentRoleRecords.Contains(x))) {
_userRolesRepository.Create(new UserRolesPartRecord { UserId = part.ContentItem.Id, Role = addingRole });
}
var currentUserRoleRecords = _userRolesRepository.Fetch(x => x.UserId == part.ContentItem.Id).ToList();
var currentRoleRecords = currentUserRoleRecords.Select(x => x.Role).ToList();
var targetRoleRecords = userRoles.Select(x => _roleService.GetRoleByName(x)).ToList();
foreach (var addingRole in targetRoleRecords.Where(x => !currentRoleRecords.Contains(x))) {
_userRolesRepository.Create(new UserRolesPartRecord { UserId = part.ContentItem.Id, Role = addingRole });
}
});
}
protected override void Exporting(UserRolesPart part, ContentManagement.Handlers.ExportContentContext context) {

View File

@@ -1,6 +1,7 @@
using System.Linq;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.Environment.Extensions;
using Orchard.Indexing;
using Orchard.Search.Models;
@@ -37,5 +38,16 @@ namespace Orchard.Search.Drivers {
return shapeHelper.EditorTemplate(TemplateName: "Parts/AdminSearch.SiteSettings", Model: model, Prefix: Prefix);
}).OnGroup("search");
}
protected override void Importing(AdminSearchSettingsPart part, ImportContentContext context) {
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
context.ImportAttribute(part.PartDefinition.Name, "SearchFields", value => {
part.Store("SearchFields", value);
});
}
}
}
}

View File

@@ -79,15 +79,14 @@ namespace Orchard.Search.Drivers {
}
protected override void Importing(SearchSettingsPart part, ImportContentContext context) {
var xElement = context.Data.Element(part.PartDefinition.Name);
if (xElement == null) return;
var searchFields = xElement.Attribute("SearchFields");
if (searchFields != null) {
searchFields.Remove();
part.Store("SearchFields", searchFields.Value);
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
context.ImportAttribute(part.PartDefinition.Name, "SearchFields", value => {
part.Store("SearchFields", value);
});
}
}
}

View File

@@ -36,7 +36,6 @@ namespace Orchard.SecureSocketsLayer.Drivers {
}
protected override void Importing(SslSettingsPart part, ImportContentContext context) {
base.Importing(part, context);
_signals.Trigger(SslSettingsPart.CacheKey);
}
}

View File

@@ -43,6 +43,11 @@ namespace Orchard.Tags.Drivers {
}
protected override void Importing(TagCloudPart part, ImportContentContext context) {
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
part.Slug = context.Attribute(part.PartDefinition.Name, "Slug");
part.Buckets = Convert.ToInt32(context.Attribute(part.PartDefinition.Name, "Buckets"));
}

View File

@@ -70,6 +70,11 @@ namespace Orchard.Tags.Drivers {
}
protected override void Importing(TagsPart part, ImportContentContext context) {
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
var tagString = context.Attribute(part.PartDefinition.Name, "Tags");
if (tagString != null) {
var tags = tagString.Split(new[] {","}, StringSplitOptions.RemoveEmptyEntries);

View File

@@ -101,6 +101,11 @@ namespace Orchard.Taxonomies.Drivers {
}
protected override void Importing(TaxonomyNavigationPart part, ImportContentContext context) {
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
part.DisplayContentCount = Boolean.Parse(context.Attribute(part.PartDefinition.Name, "DisplayContentCount"));
part.DisplayRootTerm = Boolean.Parse(context.Attribute(part.PartDefinition.Name, "DisplayRootTerm"));
part.HideEmptyTerms = Boolean.Parse(context.Attribute(part.PartDefinition.Name, "HideEmptyTerms"));

View File

@@ -65,6 +65,11 @@ namespace Orchard.Taxonomies.Drivers {
}
protected override void Importing(TaxonomyPart part, ImportContentContext context) {
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
part.TermTypeName = context.Attribute(part.PartDefinition.Name, "TermTypeName");
}
}

View File

@@ -126,6 +126,11 @@ namespace Orchard.Taxonomies.Drivers {
}
protected override void Importing(TermPart part, ImportContentContext context) {
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
part.Count = Int32.Parse(context.Attribute(part.PartDefinition.Name, "Count"));
part.Selectable = Boolean.Parse(context.Attribute(part.PartDefinition.Name, "Selectable"));
part.Weight = Int32.Parse(context.Attribute(part.PartDefinition.Name, "Weight"));

View File

@@ -58,6 +58,11 @@ namespace Orchard.Templates.Drivers {
}
protected override void Importing(ShapePart part, ImportContentContext context) {
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
var shapeElement = context.Data.Element(part.PartDefinition.Name);
if (shapeElement != null)

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.UI;
using System.Web.WebPages;
@@ -14,6 +15,7 @@ namespace Orchard.Templates.Services {
[OrchardFeature("Orchard.Templates.Razor")]
public class RazorTemplateProcessor : TemplateProcessorImpl {
private readonly IRazorCompiler _compiler;
private readonly HttpContextBase _httpContextBase;
private readonly IWorkContextAccessor _wca;
public override string Type {
@@ -22,9 +24,11 @@ namespace Orchard.Templates.Services {
public RazorTemplateProcessor(
IRazorCompiler compiler,
HttpContextBase httpContextBase,
IWorkContextAccessor wca) {
_compiler = compiler;
_httpContextBase = httpContextBase;
_wca = wca;
Logger = NullLogger.Instance;
}
@@ -37,7 +41,7 @@ namespace Orchard.Templates.Services {
public override string Process(string template, string name, DisplayContext context = null, dynamic model = null) {
if (String.IsNullOrEmpty(template))
return String.Empty;
return string.Empty;
var compiledTemplate = _compiler.CompileRazor(template, name, new Dictionary<string, object>());
var result = ActivateAndRenderTemplate(compiledTemplate, context, null, model);
@@ -69,10 +73,9 @@ namespace Orchard.Templates.Services {
// Setup a fake view context in order to support razor syntax inside of HTML attributes,
// for instance: <a href="@WorkContext.CurrentSite.BaseUrl">Homepage</a>.
var viewData = new ViewDataDictionary(model);
var httpContext = _wca.GetContext().HttpContext;
obj.ViewContext = new ViewContext(
new ControllerContext(
httpContext.Request.RequestContext,
_httpContextBase.Request.RequestContext,
new StubController()),
new StubView(),
viewData,
@@ -80,7 +83,7 @@ namespace Orchard.Templates.Services {
htmlWriter);
obj.ViewData = viewData;
obj.WebPageContext = new WebPageContext(httpContext, obj as WebPageRenderingBase, model);
obj.WebPageContext = new WebPageContext(_httpContextBase, obj as WebPageRenderingBase, model);
obj.WorkContext = _wca.GetContext();
}

View File

@@ -11,6 +11,11 @@ namespace Orchard.Users.Drivers {
public class UserPartDriver : ContentPartDriver<UserPart> {
protected override void Importing(UserPart part, ContentManagement.Handlers.ImportContentContext context) {
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
part.Email = context.Attribute(part.PartDefinition.Name, "Email");
part.EmailChallengeToken = context.Attribute(part.PartDefinition.Name, "EmailChallengeToken");
part.EmailStatus = (UserStatus)Enum.Parse(typeof(UserStatus), context.Attribute(part.PartDefinition.Name, "EmailStatus"));

View File

@@ -64,6 +64,11 @@ namespace Orchard.Widgets.Drivers {
}
protected override void Importing(LayerPart part, ImportContentContext context) {
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
var name = context.Attribute(part.PartDefinition.Name, "Name");
if (name != null) {
part.Name = name;

View File

@@ -75,6 +75,11 @@ namespace Orchard.Widgets.Drivers {
}
protected override void Importing(WidgetPart part, ContentManagement.Handlers.ImportContentContext context) {
// Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) {
return;
}
var title = context.Attribute(part.PartDefinition.Name, "Title");
if (title != null) {
part.Title = title;

View File

@@ -23,6 +23,7 @@ using Orchard.UI.Notify;
using Orchard.Workflows.Models;
using Orchard.Workflows.Services;
using Orchard.Workflows.ViewModels;
using Orchard.Workflows.Helpers;
namespace Orchard.Workflows.Controllers {
[ValidateInput(false)]
@@ -298,7 +299,7 @@ namespace Orchard.Workflows.Controllers {
dynamic activity = new JObject();
activity.Name = x.Name;
activity.Id = x.Id;
activity.ClientId = x.Name + "_" + x.Id;
activity.ClientId = x.GetClientId();
activity.Left = x.X;
activity.Top = x.Y;
activity.Start = x.Start;
@@ -323,7 +324,7 @@ namespace Orchard.Workflows.Controllers {
[HttpPost, ActionName("Edit")]
[FormValueRequired("submit.Save")]
public ActionResult EditPost(int id, string localId, string data) {
public ActionResult EditPost(int id, string localId, string data, bool clearWorkflows) {
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to edit workflows")))
return new HttpUnauthorizedResult();
@@ -339,7 +340,6 @@ namespace Orchard.Workflows.Controllers {
var activitiesIndex = new Dictionary<string, ActivityRecord>();
workflowDefinitionRecord.ActivityRecords.Clear();
workflowDefinitionRecord.WorkflowRecords.Clear();
foreach (var activity in state.Activities) {
ActivityRecord activityRecord;
@@ -367,9 +367,32 @@ namespace Orchard.Workflows.Controllers {
});
}
if (clearWorkflows) {
workflowDefinitionRecord.WorkflowRecords.Clear();
}
else {
foreach (var workflowRecord in workflowDefinitionRecord.WorkflowRecords) {
// Update any awaiting activity records with the new activity record.
foreach (var awaitingActivityRecord in workflowRecord.AwaitingActivities) {
var clientId = awaitingActivityRecord.ActivityRecord.GetClientId();
if (activitiesIndex.ContainsKey(clientId)) {
awaitingActivityRecord.ActivityRecord = activitiesIndex[clientId];
}
else {
workflowRecord.AwaitingActivities.Remove(awaitingActivityRecord);
}
}
// Remove any workflows with no awaiting activities.
if (!workflowRecord.AwaitingActivities.Any()) {
workflowDefinitionRecord.WorkflowRecords.Remove(workflowRecord);
}
}
}
Services.Notifier.Information(T("Workflow saved successfully"));
return RedirectToAction("Edit", new { id, localId });
// Don't pass the localId to force the activites to refresh and use the deterministic clientId.
return RedirectToAction("Edit", new { id });
}
[HttpPost, ActionName("Edit")]

View File

@@ -38,5 +38,14 @@ namespace Orchard.Workflows.Models {
/// containing this activity.
/// </summary>
public virtual WorkflowDefinitionRecord WorkflowDefinitionRecord { get; set; }
/// <summary>
/// Gets the Id which can be used on the client.
/// </summary>
/// <returns>An unique Id to represent this activity on the client.</returns>
public string GetClientId() {
return Name + "_" + Id;
}
}
}

View File

@@ -7,6 +7,7 @@
Style.Require("WorkflowsAdmin");
Style.Require("WorkflowsActivities");
Style.Require("jQueryUI_Orchard");
Script.Require("jQueryUI_Dialog").AtFoot();
Script.Require("jsPlumb").AtFoot();
Script.Include("orchard-workflows-serialize.js").AtFoot();
Script.Include("orchard-workflows.js").AtFoot();
@@ -74,23 +75,41 @@
@Html.Hidden("data", String.Empty)
@Html.Hidden("confirm-delete-activity", T("Are you sure you want to remove this activity?"))
@Html.Hidden("confirm-delete-instances", T("Are you sure you want to remove running instances of this workflow?"))
@Html.Hidden("confirm-delete-instances", T("You have running instances of this workflow, do you want to stop them?"))
using (Script.Foot()) {
<script type="text/javascript">
//<![CDATA[
$("form").submit(function () {
saveLocal(localId);
var workflow = loadWorkflow(localId);
var data = JSON.stringify(workflow);
$("[name='data']").val(data);
$("form").submit(function (e, submit, clearWorkflows) {
if(submit){
saveLocal(localId);
var workflow = loadWorkflow(localId);
var data = JSON.stringify(workflow);
$("[name='data']").val(data);
var values = [$("<input>", { type: "hidden", name: "clearWorkflows", value: clearWorkflows }), $("<input>", { type: "hidden", name: "submit.Save", value: "Save" })];
$(this).append(values);
return true;
}
e.preventDefault();
$.ajax({
url: stateUrl + "/" + $("#id").val(),
async: false,
success: function(state) {
if(state.isRunning && !confirm($("#confirm-delete-instances").val())) {
e.preventDefault();
if (state.isRunning) {
var dialog = $('<p>' + $("#confirm-delete-instances").val() + '</p>').dialog({
buttons: {
'@T("Yes")': function() { $('form').trigger('submit', [true, true]); },
'@T("No")': function() { $('form').trigger('submit', [true, false]); },
'@T("Cancel")': function() {
dialog.dialog('close');
}
}
});
}
else {
$('form').trigger('submit', [true, false]);
}
}
});