private SCItem ConvertSubmitButton(SCItem form, SCItem pageItem) { pageItem = CheckItemNotNullForAnalysis(pageItem); var buttonMetadata = _metadataProvider.GetItemMetadataByTemplateName("Button"); SCItem buttonItem; if (!_destMasterRepository.ItemHasChildrenOfTemplate(buttonMetadata.destTemplateId, pageItem)) { var buttonItemId = ConvertSubmitFields(form, pageItem.ID); buttonItem = _destMasterRepository.GetSitecoreItem(buttonItemId); WriteDescendentItems(buttonMetadata, buttonItem); } else { buttonItem = _destMasterRepository.GetSitecoreDescendantsItems(buttonMetadata.destTemplateId, pageItem.ID).FirstOrDefault(); } // Delete pre-existing submit actions if (buttonItem != null) { var submitActionDefinitionMetadata = _metadataProvider.GetItemMetadataByTemplateName("SubmitActionDefinition"); var submitActions = _destMasterRepository.GetSitecoreDescendantsItems(submitActionDefinitionMetadata.destTemplateId, buttonItem.ID); foreach (var submitAction in submitActions) { _destMasterRepository.DeleteSitecoreItem(submitAction); } } return(buttonItem); }
public void MigrateData() { try { Console.WriteLine(" Started forms data migration..."); Console.WriteLine(); var convertedForms = _destMasterRepository.GetSitecoreDescendantsItems( _metadataProvider.GetItemMetadataByTemplateName("Form").destTemplateId, _appSettings.itemReferences["destFormFolderId"]).Select(form => form.ID) .Where(formId => _sourceMasterRepository.GetSitecoreItemName(formId) != null).ToList(); // Filter forms to select only included forms in appSettings "includeOnlyFormIds" parameter if (_appSettings.includeOnlyFormIds != null && _appSettings.includeOnlyFormIds.Any()) { convertedForms = convertedForms.Where(form => _appSettings.includeOnlyFormIds.Contains(form)).ToList(); } int formsCounter = 0; ProgressBar.DrawTextProgressBar(formsCounter, convertedForms.Count, "forms data migrated"); foreach (Guid convertedFormId in convertedForms) { MigrateFormData(convertedFormId); formsCounter++; ProgressBar.DrawTextProgressBar(formsCounter, convertedForms.Count, "forms data migrated"); } Console.WriteLine(); Console.WriteLine(); Console.WriteLine(" Finished forms data migration."); Console.WriteLine(); } catch (Exception ex) { _logger.Log(new LogEntry(LoggingEventType.Error, "Failed to migrate forms data.", ex)); throw; } }