Skip to content

Commit

Permalink
Added support for detecting EntityTypes that do not exist. Fixes #6.
Browse files Browse the repository at this point in the history
  • Loading branch information
cabal95 committed Sep 25, 2017
1 parent b1b5e96 commit 3b87a7f
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions Controls/ShareWorkflow.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,16 @@ static public bool Import( DataContainer container, bool newGuids, RockContext r
messages = new List<string>();
var helper = new Helper( rockContext );

//
// Ensure we know about all referenced entity types.
//
var missingTypes = container.MissingEntityTypes();
if ( missingTypes.Any() )
{
messages.Add( string.Format( "The following EntityTypes are unknown and indicate you may be missing a plug-in: <ul><li>{0}</li></ul>", string.Join( "</li><li>", missingTypes ) ) );
return false;
}

using ( var transaction = rockContext.Database.BeginTransaction() )
{
try
Expand Down Expand Up @@ -1773,6 +1783,52 @@ public DataContainer()
RootEntities = new List<Guid>();
}

/// <summary>
/// Check for any missing entity types that would be encountered during an import
/// operation.
/// </summary>
/// <returns>A list of strings that identify the missing entity type class names.</returns>
public List<string> MissingEntityTypes()
{
//
// Ensure we know about all referenced entity types.
//
var missingTypes = new List<string>();

//
// Get all the explicit EntityTypes for entities that are to be imported.
//
var entityTypeStrings = Entities.Select( e => e.EntityType ).ToList();

//
// Check for GUID and EntityType references.
//
var references = Entities.SelectMany( e => e.References );

entityTypeStrings.AddRange( references
.Where( r => r.Type == ReferenceType.Guid )
.Select( r => r.EntityType ) );

entityTypeStrings.AddRange( references
.Where( r => r.Type == ReferenceType.EntityType )
.Select( r => ( string ) r.Data ) );

//
// Just check the unique ones.
//
entityTypeStrings = entityTypeStrings.Distinct().ToList();

foreach ( var entityType in entityTypeStrings )
{
if ( EntityTypeCache.Read( entityType, false, null ) == null )
{
missingTypes.Add( entityType );
}
}

return missingTypes;
}

#endregion
}

Expand Down

0 comments on commit 3b87a7f

Please sign in to comment.