/// <summary> /// Copies any HtmlContent in the original page tree over to the corresponding blocks on the copied page tree. /// </summary> /// <param name="blockGuidDictionary">The dictionary containing the original block guids and the corresponding copied block guids.</param> /// <param name="rockContext">The rock context.</param> /// <param name="currentPersonAliasId">The current person alias identifier.</param> private void CloneHtmlContent(Dictionary <Guid, Guid> blockGuidDictionary, RockContext rockContext, int?currentPersonAliasId = null) { var htmlContentService = new HtmlContentService(rockContext); var blockService = new BlockService(rockContext); Dictionary <Guid, int> blockIntDictionary = blockService.Queryable() .Where(p => blockGuidDictionary.Keys.Contains(p.Guid) || blockGuidDictionary.Values.Contains(p.Guid)) .ToDictionary(p => p.Guid, p => p.Id); var htmlContents = htmlContentService.Queryable().Where(a => blockIntDictionary.Values.Contains(a.BlockId)) .ToList(); foreach (var htmlContent in htmlContents) { var newHtmlContent = htmlContent.Clone(false); newHtmlContent.CreatedByPersonAlias = null; newHtmlContent.CreatedByPersonAliasId = currentPersonAliasId; newHtmlContent.CreatedDateTime = RockDateTime.Now; newHtmlContent.ModifiedByPersonAlias = null; newHtmlContent.ModifiedByPersonAliasId = currentPersonAliasId; newHtmlContent.ModifiedDateTime = RockDateTime.Now; newHtmlContent.Id = 0; newHtmlContent.Guid = Guid.NewGuid(); newHtmlContent.BlockId = blockIntDictionary[blockGuidDictionary[blockIntDictionary.Where(d => d.Value == htmlContent.BlockId).FirstOrDefault().Key]]; htmlContentService.Add(newHtmlContent); } rockContext.SaveChanges(); }
/// <summary> /// Copies any auths for the original pages and blocks over to the copied pages and blocks. /// </summary> /// <param name="pageGuidDictionary">The dictionary containing the original page guids and the corresponding copied page guids.</param> /// <param name="blockGuidDictionary">The dictionary containing the original block guids and the corresponding copied block guids.</param> /// <param name="rockContext">The rock context.</param> /// <param name="currentPersonAliasId">The current person alias identifier.</param> private void GeneratePageBlockAuths(Dictionary <Guid, Guid> pageGuidDictionary, Dictionary <Guid, Guid> blockGuidDictionary, RockContext rockContext, int?currentPersonAliasId = null) { var authService = new AuthService(rockContext); var pageService = new PageService(rockContext); var blockService = new BlockService(rockContext); var pageGuid = Rock.SystemGuid.EntityType.PAGE.AsGuid(); var blockGuid = Rock.SystemGuid.EntityType.BLOCK.AsGuid(); Dictionary <Guid, int> pageIntDictionary = pageService.Queryable() .Where(p => pageGuidDictionary.Keys.Contains(p.Guid) || pageGuidDictionary.Values.Contains(p.Guid)) .ToDictionary(p => p.Guid, p => p.Id); Dictionary <Guid, int> blockIntDictionary = blockService.Queryable() .Where(p => blockGuidDictionary.Keys.Contains(p.Guid) || blockGuidDictionary.Values.Contains(p.Guid)) .ToDictionary(p => p.Guid, p => p.Id); var pageAuths = authService.Queryable().Where(a => a.EntityType.Guid == pageGuid && pageIntDictionary.Values.Contains(a.EntityId.Value)) .ToList(); var blockAuths = authService.Queryable().Where(a => a.EntityType.Guid == blockGuid && blockIntDictionary.Values.Contains(a.EntityId.Value)) .ToList(); foreach (var pageAuth in pageAuths) { var newPageAuth = pageAuth.Clone(false); newPageAuth.CreatedByPersonAlias = null; newPageAuth.CreatedByPersonAliasId = currentPersonAliasId; newPageAuth.CreatedDateTime = RockDateTime.Now; newPageAuth.ModifiedByPersonAlias = null; newPageAuth.ModifiedByPersonAliasId = currentPersonAliasId; newPageAuth.ModifiedDateTime = RockDateTime.Now; newPageAuth.Id = 0; newPageAuth.Guid = Guid.NewGuid(); newPageAuth.EntityId = pageIntDictionary[pageGuidDictionary[pageIntDictionary.Where(d => d.Value == pageAuth.EntityId.Value).FirstOrDefault().Key]]; authService.Add(newPageAuth); } foreach (var blockAuth in blockAuths) { var newBlockAuth = blockAuth.Clone(false); newBlockAuth.CreatedByPersonAlias = null; newBlockAuth.CreatedByPersonAliasId = currentPersonAliasId; newBlockAuth.CreatedDateTime = RockDateTime.Now; newBlockAuth.ModifiedByPersonAlias = null; newBlockAuth.ModifiedByPersonAliasId = currentPersonAliasId; newBlockAuth.ModifiedDateTime = RockDateTime.Now; newBlockAuth.Id = 0; newBlockAuth.Guid = Guid.NewGuid(); newBlockAuth.EntityId = blockIntDictionary[blockGuidDictionary[blockIntDictionary.Where(d => d.Value == blockAuth.EntityId.Value).FirstOrDefault().Key]]; authService.Add(newBlockAuth); } rockContext.SaveChanges(); }
/// <summary> /// Deletes the specified item. Will try to determine current person /// alias from HttpContext. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> public override bool Delete(BlockType item) { // block has a cascading delete on BlockType, but lets delete it manually so that the BlockCache gets updated correctly var blockService = new BlockService(this.Context as RockContext); var blocks = blockService.Queryable().Where(a => a.BlockTypeId == item.Id).ToList(); foreach (var block in blocks) { blockService.Delete(block); } return(base.Delete(item)); }
/// <summary> /// This method takes the attribute values of the original blocks, and creates copies of them that point to the copied blocks. /// In addition, any block attribute value pointing to a page in the original page tree is now updated to point to the /// corresponding page in the copied page tree. /// </summary> /// <param name="pageGuidDictionary">The dictionary containing the original page guids and the corresponding copied page guids.</param> /// <param name="blockGuidDictionary">The dictionary containing the original block guids and the corresponding copied block guids.</param> /// <param name="rockContext">The rock context.</param> /// <param name="currentPersonAliasId">The current person alias identifier.</param> private void GenerateBlockAttributeValues(Dictionary <Guid, Guid> pageGuidDictionary, Dictionary <Guid, Guid> blockGuidDictionary, RockContext rockContext, int?currentPersonAliasId = null) { var attributeValueService = new AttributeValueService(rockContext); var pageService = new PageService(rockContext); var blockService = new BlockService(rockContext); var pageGuid = Rock.SystemGuid.EntityType.PAGE.AsGuid(); var blockGuid = Rock.SystemGuid.EntityType.BLOCK.AsGuid(); Dictionary <Guid, int> blockIntDictionary = blockService.Queryable() .Where(p => blockGuidDictionary.Keys.Contains(p.Guid) || blockGuidDictionary.Values.Contains(p.Guid)) .ToDictionary(p => p.Guid, p => p.Id); var attributeValues = attributeValueService.Queryable().Where(a => a.Attribute.EntityType.Guid == blockGuid && blockIntDictionary.Values.Contains(a.EntityId.Value)) .ToList(); foreach (var attributeValue in attributeValues) { var attribute = AttributeCache.Get(attributeValue.AttributeId); var fieldType = attribute?.FieldType.Field as Field.FieldType; var currentValue = attributeValue; var newAttributeValue = attributeValue.Clone(false); newAttributeValue.CreatedByPersonAlias = null; newAttributeValue.CreatedByPersonAliasId = currentPersonAliasId; newAttributeValue.CreatedDateTime = RockDateTime.Now; newAttributeValue.ModifiedByPersonAlias = null; newAttributeValue.ModifiedByPersonAliasId = currentPersonAliasId; newAttributeValue.ModifiedDateTime = RockDateTime.Now; newAttributeValue.Id = 0; newAttributeValue.Guid = Guid.NewGuid(); newAttributeValue.EntityId = blockIntDictionary[blockGuidDictionary[blockIntDictionary.Where(d => d.Value == attributeValue.EntityId.Value).FirstOrDefault().Key]]; if (fieldType != null && currentValue != null && currentValue.Value != null) { newAttributeValue.Value = fieldType.GetCopyValue(currentValue.Value, rockContext); } if (attributeValue.Attribute.FieldType.Guid == Rock.SystemGuid.FieldType.PAGE_REFERENCE.AsGuid()) { if (pageGuidDictionary.ContainsKey(attributeValue.Value.AsGuid())) { newAttributeValue.Value = pageGuidDictionary[attributeValue.Value.AsGuid()].ToString(); } } attributeValueService.Add(newAttributeValue); } rockContext.SaveChanges(); }
/// <summary> /// Copies any auths for the original pages and blocks over to the copied pages and blocks. /// </summary> /// <param name="pageGuidDictionary">The dictionary containing the original page guids and the corresponding copied page guids.</param> /// <param name="blockGuidDictionary">The dictionary containing the original block guids and the corresponding copied block guids.</param> /// <param name="rockContext">The rock context.</param> /// <param name="currentPersonAliasId">The current person alias identifier.</param> private void GeneratePageBlockAuths( Dictionary<Guid, Guid> pageGuidDictionary, Dictionary<Guid, Guid> blockGuidDictionary, RockContext rockContext, int? currentPersonAliasId = null ) { var authService = new AuthService( rockContext ); var pageService = new PageService( rockContext ); var blockService = new BlockService( rockContext ); var pageGuid = Rock.SystemGuid.EntityType.PAGE.AsGuid(); var blockGuid = Rock.SystemGuid.EntityType.BLOCK.AsGuid(); Dictionary<Guid, int> pageIntDictionary = pageService.Queryable() .Where( p => pageGuidDictionary.Keys.Contains( p.Guid ) || pageGuidDictionary.Values.Contains( p.Guid ) ) .ToDictionary( p => p.Guid, p => p.Id ); Dictionary<Guid, int> blockIntDictionary = blockService.Queryable() .Where( p => blockGuidDictionary.Keys.Contains( p.Guid ) || blockGuidDictionary.Values.Contains( p.Guid ) ) .ToDictionary( p => p.Guid, p => p.Id ); var pageAuths = authService.Queryable().Where( a => a.EntityType.Guid == pageGuid && pageIntDictionary.Values.Contains( a.EntityId.Value ) ) .ToList(); var blockAuths = authService.Queryable().Where( a => a.EntityType.Guid == blockGuid && blockIntDictionary.Values.Contains( a.EntityId.Value ) ) .ToList(); foreach ( var pageAuth in pageAuths ) { var newPageAuth = pageAuth.Clone( false ); newPageAuth.CreatedByPersonAlias = null; newPageAuth.CreatedByPersonAliasId = currentPersonAliasId; newPageAuth.CreatedDateTime = RockDateTime.Now; newPageAuth.ModifiedByPersonAlias = null; newPageAuth.ModifiedByPersonAliasId = currentPersonAliasId; newPageAuth.ModifiedDateTime = RockDateTime.Now; newPageAuth.Id = 0; newPageAuth.Guid = Guid.NewGuid(); newPageAuth.EntityId = pageIntDictionary[pageGuidDictionary[pageIntDictionary.Where( d => d.Value == pageAuth.EntityId.Value ).FirstOrDefault().Key]]; authService.Add( newPageAuth ); } foreach ( var blockAuth in blockAuths ) { var newBlockAuth = blockAuth.Clone( false ); newBlockAuth.CreatedByPersonAlias = null; newBlockAuth.CreatedByPersonAliasId = currentPersonAliasId; newBlockAuth.CreatedDateTime = RockDateTime.Now; newBlockAuth.ModifiedByPersonAlias = null; newBlockAuth.ModifiedByPersonAliasId = currentPersonAliasId; newBlockAuth.ModifiedDateTime = RockDateTime.Now; newBlockAuth.Id = 0; newBlockAuth.Guid = Guid.NewGuid(); newBlockAuth.EntityId = blockIntDictionary[blockGuidDictionary[blockIntDictionary.Where( d => d.Value == blockAuth.EntityId.Value ).FirstOrDefault().Key]]; authService.Add( newBlockAuth ); } rockContext.SaveChanges(); }
/// <summary> /// This method takes the attribute values of the original blocks, and creates copies of them that point to the copied blocks. /// In addition, any block attribute value pointing to a page in the original page tree is now updated to point to the /// corresponding page in the copied page tree. /// </summary> /// <param name="pageGuidDictionary">The dictionary containing the original page guids and the corresponding copied page guids.</param> /// <param name="blockGuidDictionary">The dictionary containing the original block guids and the corresponding copied block guids.</param> /// <param name="rockContext">The rock context.</param> /// <param name="currentPersonAliasId">The current person alias identifier.</param> private void GenerateBlockAttributeValues( Dictionary<Guid, Guid> pageGuidDictionary, Dictionary<Guid, Guid> blockGuidDictionary, RockContext rockContext, int? currentPersonAliasId = null ) { var attributeValueService = new AttributeValueService( rockContext ); var pageService = new PageService( rockContext ); var blockService = new BlockService( rockContext ); var pageGuid = Rock.SystemGuid.EntityType.PAGE.AsGuid(); var blockGuid = Rock.SystemGuid.EntityType.BLOCK.AsGuid(); Dictionary<Guid, int> blockIntDictionary = blockService.Queryable() .Where( p => blockGuidDictionary.Keys.Contains( p.Guid ) || blockGuidDictionary.Values.Contains( p.Guid ) ) .ToDictionary( p => p.Guid, p => p.Id ); var attributeValues = attributeValueService.Queryable().Where( a => a.Attribute.EntityType.Guid == blockGuid && blockIntDictionary.Values.Contains( a.EntityId.Value ) ) .ToList(); foreach ( var attributeValue in attributeValues ) { var newAttributeValue = attributeValue.Clone( false ); newAttributeValue.CreatedByPersonAlias = null; newAttributeValue.CreatedByPersonAliasId = currentPersonAliasId; newAttributeValue.CreatedDateTime = RockDateTime.Now; newAttributeValue.ModifiedByPersonAlias = null; newAttributeValue.ModifiedByPersonAliasId = currentPersonAliasId; newAttributeValue.ModifiedDateTime = RockDateTime.Now; newAttributeValue.Id = 0; newAttributeValue.Guid = Guid.NewGuid(); newAttributeValue.EntityId = blockIntDictionary[blockGuidDictionary[blockIntDictionary.Where( d => d.Value == attributeValue.EntityId.Value ).FirstOrDefault().Key]]; if ( attributeValue.Attribute.FieldType.Guid == Rock.SystemGuid.FieldType.PAGE_REFERENCE.AsGuid() ) { if ( pageGuidDictionary.ContainsKey( attributeValue.Value.AsGuid() ) ) { newAttributeValue.Value = pageGuidDictionary[attributeValue.Value.AsGuid()].ToString(); } } attributeValueService.Add( newAttributeValue ); } rockContext.SaveChanges(); }
/// <summary> /// Copies any HtmlContent in the original page tree over to the corresponding blocks on the copied page tree. /// </summary> /// <param name="blockGuidDictionary">The dictionary containing the original block guids and the corresponding copied block guids.</param> /// <param name="rockContext">The rock context.</param> /// <param name="currentPersonAliasId">The current person alias identifier.</param> private void CloneHtmlContent( Dictionary<Guid, Guid> blockGuidDictionary, RockContext rockContext, int? currentPersonAliasId = null ) { var htmlContentService = new HtmlContentService( rockContext ); var blockService = new BlockService( rockContext ); Dictionary<Guid, int> blockIntDictionary = blockService.Queryable() .Where( p => blockGuidDictionary.Keys.Contains( p.Guid ) || blockGuidDictionary.Values.Contains( p.Guid ) ) .ToDictionary( p => p.Guid, p => p.Id ); var htmlContents = htmlContentService.Queryable().Where( a => blockIntDictionary.Values.Contains( a.BlockId ) ) .ToList(); foreach ( var htmlContent in htmlContents ) { var newHtmlContent = htmlContent.Clone( false ); newHtmlContent.CreatedByPersonAlias = null; newHtmlContent.CreatedByPersonAliasId = currentPersonAliasId; newHtmlContent.CreatedDateTime = RockDateTime.Now; newHtmlContent.ModifiedByPersonAlias = null; newHtmlContent.ModifiedByPersonAliasId = currentPersonAliasId; newHtmlContent.ModifiedDateTime = RockDateTime.Now; newHtmlContent.Id = 0; newHtmlContent.Guid = Guid.NewGuid(); newHtmlContent.BlockId = blockIntDictionary[blockGuidDictionary[blockIntDictionary.Where( d => d.Value == htmlContent.BlockId ).FirstOrDefault().Key]]; htmlContentService.Add( newHtmlContent ); } rockContext.SaveChanges(); }