[Fixes #5762 #4044] Creating new identities on cloning

This commit is contained in:
Sebastien Ros
2016-01-13 16:46:28 -08:00
parent dec68d454c
commit 0e6955c624
9 changed files with 66 additions and 4 deletions

View File

@@ -28,5 +28,6 @@ namespace Orchard.Core.Common.Drivers {
protected override void Exporting(IdentityPart part, ContentManagement.Handlers.ExportContentContext context) {
context.Element(part.PartDefinition.Name).SetAttributeValue("Identifier", part.Identifier);
}
}
}

View File

@@ -9,17 +9,21 @@ namespace Orchard.Core.Common.Handlers {
public IdentityPartHandler(IRepository<IdentityPartRecord> identityRepository,
IContentManager contentManager) {
Filters.Add(StorageFilter.For(identityRepository));
OnInitializing<IdentityPart>(AssignIdentity);
OnInitializing<IdentityPart>((ctx, part) => AssignIdentity(part));
OnCloning<IdentityPart>((ctx, part) => AssignIdentity(part));
OnIndexing<IdentityPart>((context, part) => {
context.DocumentIndex.Add("identifier", part.Identifier).Store();
});
}
protected void AssignIdentity(InitializingContentContext context, IdentityPart part) {
protected void AssignIdentity(IdentityPart part) {
part.Identifier = Guid.NewGuid().ToString("n");
}
protected override void Cloning(CloneContentContext context) {
}
protected override void GetItemMetadata(GetContentItemMetadataContext context) {
var part = context.ContentItem.As<IdentityPart>();

View File

@@ -0,0 +1,6 @@
namespace Orchard.ContentManagement.Handlers {
public class CloneContentContext : ContentContextBase {
public CloneContentContext(ContentItem contentItem) : base(contentItem) {
}
}
}

View File

@@ -96,6 +96,14 @@ namespace Orchard.ContentManagement.Handlers {
protected void OnIndexed<TPart>(Action<IndexContentContext, TPart> handler) where TPart : class, IContent {
Filters.Add(new InlineStorageFilter<TPart> { OnIndexed = handler });
}
protected void OnCloning<TPart>(Action<CloneContentContext, TPart> handler) where TPart : class, IContent {
Filters.Add(new InlineStorageFilter<TPart> { OnCloning = handler });
}
protected void OnCloned<TPart>(Action<CloneContentContext, TPart> handler) where TPart : class, IContent {
Filters.Add(new InlineStorageFilter<TPart> { OnCloned = handler });
}
protected void OnImporting<TPart>(Action<ImportContentContext, TPart> handler) where TPart : class, IContent {
Filters.Add(new InlineStorageFilter<TPart> { OnImporting = handler });
}
@@ -159,6 +167,8 @@ namespace Orchard.ContentManagement.Handlers {
public Action<RemoveContentContext, TPart> OnRemoved { get; set; }
public Action<IndexContentContext, TPart> OnIndexing { get; set; }
public Action<IndexContentContext, TPart> OnIndexed { get; set; }
public Action<CloneContentContext, TPart> OnCloning { get; set; }
public Action<CloneContentContext, TPart> OnCloned { get; set; }
public Action<ImportContentContext, TPart> OnImporting { get; set; }
public Action<ImportContentContext, TPart> OnImported { get; set; }
public Action<ImportContentContext, TPart> OnImportCompleted { get; set; }
@@ -227,6 +237,14 @@ namespace Orchard.ContentManagement.Handlers {
if (OnIndexed != null)
OnIndexed(context, instance);
}
protected override void Cloning(CloneContentContext context, TPart instance) {
if (OnCloning != null)
OnCloning(context, instance);
}
protected override void Cloned(CloneContentContext context, TPart instance) {
if (OnCloned != null)
OnCloned(context, instance);
}
protected override void Importing(ImportContentContext context, TPart instance) {
if (OnImporting != null)
OnImporting(context, instance);
@@ -410,6 +428,18 @@ namespace Orchard.ContentManagement.Handlers {
Importing(context);
}
void IContentHandler.Cloned(CloneContentContext context) {
foreach (var filter in Filters.OfType<IContentStorageFilter>())
filter.Cloned(context);
Cloned(context);
}
void IContentHandler.Cloning(CloneContentContext context) {
foreach (var filter in Filters.OfType<IContentStorageFilter>())
filter.Cloning(context);
Cloning(context);
}
void IContentHandler.Imported(ImportContentContext context) {
foreach (var filter in Filters.OfType<IContentStorageFilter>())
filter.Imported(context);
@@ -509,6 +539,8 @@ namespace Orchard.ContentManagement.Handlers {
protected virtual void Indexing(IndexContentContext context) { }
protected virtual void Indexed(IndexContentContext context) { }
protected virtual void Cloning(CloneContentContext context) { }
protected virtual void Cloned(CloneContentContext context) { }
protected virtual void Importing(ImportContentContext context) { }
protected virtual void Imported(ImportContentContext context) { }
protected virtual void ImportCompleted(ImportContentContext context) { }

View File

@@ -20,8 +20,10 @@
public virtual void Removed(RemoveContentContext context) {}
public virtual void Indexing(IndexContentContext context) {}
public virtual void Indexed(IndexContentContext context) {}
public virtual void Importing(ImportContentContext context) {}
public virtual void Imported(ImportContentContext context) {}
public virtual void Cloning(CloneContentContext context) { }
public virtual void Cloned(CloneContentContext context) { }
public virtual void Importing(ImportContentContext context) { }
public virtual void Imported(ImportContentContext context) { }
public virtual void ImportCompleted(ImportContentContext importContentContext) {}
public virtual void Exporting(ExportContentContext context) {}
public virtual void Exported(ExportContentContext context) {}

View File

@@ -22,6 +22,8 @@
void Indexed(IndexContentContext context);
void Importing(ImportContentContext context);
void Imported(ImportContentContext context);
void Cloning(CloneContentContext context);
void Cloned(CloneContentContext context);
void ImportCompleted(ImportContentContext importContentContext);
void Exporting(ExportContentContext context);
void Exported(ExportContentContext context);

View File

@@ -19,6 +19,8 @@ namespace Orchard.ContentManagement.Handlers {
void Removed(RemoveContentContext context);
void Indexing(IndexContentContext context);
void Indexed(IndexContentContext context);
void Cloning(CloneContentContext context);
void Cloned(CloneContentContext context);
void Importing(ImportContentContext context);
void Imported(ImportContentContext context);
void ImportCompleted(ImportContentContext context);

View File

@@ -21,6 +21,8 @@ namespace Orchard.ContentManagement.Handlers {
protected virtual void Removed(RemoveContentContext context, TPart instance) { }
protected virtual void Indexing(IndexContentContext context, TPart instance) { }
protected virtual void Indexed(IndexContentContext context, TPart instance) { }
protected virtual void Cloning(CloneContentContext context, TPart instance) { }
protected virtual void Cloned(CloneContentContext context, TPart instance) { }
protected virtual void Importing(ImportContentContext context, TPart instance) { }
protected virtual void Imported(ImportContentContext context, TPart instance) { }
protected virtual void ImportCompleted(ImportContentContext context, TPart instance) { }
@@ -126,6 +128,16 @@ namespace Orchard.ContentManagement.Handlers {
Indexed(context, context.ContentItem.As<TPart>());
}
void IContentStorageFilter.Cloning(CloneContentContext context) {
if (context.ContentItem.Is<TPart>())
Cloning(context, context.ContentItem.As<TPart>());
}
void IContentStorageFilter.Cloned(CloneContentContext context) {
if (context.ContentItem.Is<TPart>())
Cloned(context, context.ContentItem.As<TPart>());
}
void IContentStorageFilter.Importing(ImportContentContext context) {
if (context.ContentItem.Is<TPart>())
Importing(context, context.ContentItem.As<TPart>());

View File

@@ -169,6 +169,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BackgroundHttpContextFactory.cs" />
<Compile Include="ContentManagement\Handlers\CloneContentContext.cs" />
<Compile Include="Environment\Configuration\ExtensionLocations.cs" />
<Compile Include="DisplayManagement\IPositioned.cs" />
<Compile Include="DisplayManagement\PositionWrapper.cs" />