public void OnAfterDataUpdated(IData data) { var page = (IPage)data; IEnumerable <IPagePlaceholderContent> pagePlaceholderContents; using (new DataScope(DataScopeIdentifier.Administrated)) { pagePlaceholderContents = (from content in DataFacade.GetData <IPagePlaceholderContent>() where content.PageId == page.Id && content.VersionId == page.VersionId select content).ToList(); } if (page.PublicationStatus == GenericPublishProcessController.Published) { using (var transactionScope = TransactionsFacade.CreateNewScope()) { using (new DataScope(DataScopeIdentifier.Public)) { DataFacade.Delete <IPagePlaceholderContent>( f => f.PageId == page.Id && f.VersionId == page.VersionId); } foreach (var pagePlaceholderContent in pagePlaceholderContents) { pagePlaceholderContent.PublicationStatus = page.PublicationStatus; DataFacade.Update(pagePlaceholderContent); } using (new DataScope(DataScopeIdentifier.Administrated)) { var publishSchedule = PublishScheduleHelper.GetPublishSchedule(typeof(IPage), page.Id.ToString(), page.DataSourceId.LocaleScope.Name); if (publishSchedule != null) { DataFacade.Delete(publishSchedule); } } transactionScope.Complete(); } } else { foreach (var pagePlaceholderContent in pagePlaceholderContents) { if (pagePlaceholderContent.PublicationStatus != page.PublicationStatus) { pagePlaceholderContent.PublicationStatus = page.PublicationStatus; DataFacade.Update(pagePlaceholderContent); } } } }
protected override void Execute() { using (new DataScope(DataScopeIdentifier.Administrated, CultureInfo.CreateSpecificCulture(LocaleName))) { var pagePublishSchedule = PublishScheduleHelper.GetPublishSchedule(typeof(IPage), PageId.ToString(), LocaleName); DataFacade.Delete(pagePublishSchedule); // NOTE: publication logic removed } }
public static void HandlePublishUnpublishWorkflows(IData selectedData, string cultureName, DateTime?publishDate, DateTime?unpublishDate, ref WorkflowInstance publishWorkflowInstance, ref WorkflowInstance unpublishWorkflowInstance) { var key = selectedData.GetUniqueKey().ToString(); var existingPublishSchedule = PublishScheduleHelper.GetPublishSchedule(selectedData.DataSourceId.InterfaceType, key, cultureName); if (existingPublishSchedule != null) { WorkflowFacade.AbortWorkflow(existingPublishSchedule.WorkflowInstanceId); DataFacade.Delete(existingPublishSchedule); } if (publishDate != null) { publishWorkflowInstance = WorkflowFacade.CreateNewWorkflow( typeof(DataPublishSchedulerWorkflow), new Dictionary <string, object> { { "Date", publishDate }, { "DataType", selectedData.DataSourceId.InterfaceType.FullName }, { "DataId", selectedData.GetUniqueKey().ToString() }, { "LocaleName", cultureName } } ); PublishScheduleHelper.CreatePublishSchedule(selectedData.DataSourceId.InterfaceType, selectedData.GetUniqueKey().ToString(), cultureName, publishDate.Value, publishWorkflowInstance); } var existingUnpublishSchedule = PublishScheduleHelper.GetUnpublishSchedule(selectedData.DataSourceId.InterfaceType, key, cultureName); if (existingUnpublishSchedule != null) { WorkflowFacade.AbortWorkflow(existingUnpublishSchedule.WorkflowInstanceId); DataFacade.Delete(existingUnpublishSchedule); } if (unpublishDate != null) { unpublishWorkflowInstance = WorkflowFacade.CreateNewWorkflow( typeof(DataUnpublishSchedulerWorkflow), new Dictionary <string, object> { { "Date", unpublishDate }, { "DataType", selectedData.DataSourceId.InterfaceType.FullName }, { "DataId", key }, { "LocaleName", cultureName } } ); PublishScheduleHelper.CreateUnpublishSchedule(selectedData.DataSourceId.InterfaceType, key, cultureName, unpublishDate.Value, unpublishWorkflowInstance); } }
public IEnumerable <Model.RedirectKeyword> GetKeywordRedirects(CultureInfo cultureInfo) { var result = _keywordsCache.ContainsKey(cultureInfo) ? _keywordsCache[cultureInfo] : null; if (result == null) { result = new List <Model.RedirectKeyword>(); using (var connection = new DataConnection(PublicationScope.Unpublished, cultureInfo)) { foreach (var redirectKeyword in connection.Get <RedirectKeyword>()) { var interfaceType = redirectKeyword.DataSourceId.InterfaceType; var stringKey = redirectKeyword.GetUniqueKey().ToString(); var locale = redirectKeyword.DataSourceId.LocaleScope.Name; var existingPublishSchedule = PublishScheduleHelper.GetPublishSchedule(interfaceType, stringKey, locale); var existingUnpublishSchedule = PublishScheduleHelper.GetUnpublishSchedule(interfaceType, stringKey, locale); if (redirectKeyword.PublicationStatus == GenericPublishProcessController.Published) { result.Add(new Model.RedirectKeyword { Keyword = redirectKeyword.Keyword, LandingPage = KeywordFacade.GetPageUrl(redirectKeyword.LandingPage, cultureInfo), PublishDate = existingPublishSchedule?.PublishDate.ToTimeZoneDateTimeString(), UnpublishDate = existingUnpublishSchedule?.UnpublishDate.ToTimeZoneDateTimeString(), }); } else { var publishedredirectKeyword = DataFacade.GetDataFromOtherScope(redirectKeyword, DataScopeIdentifier.Public).FirstOrDefault(); result.Add(new Model.RedirectKeyword { Keyword = publishedredirectKeyword?.Keyword, LandingPage = publishedredirectKeyword != null ? KeywordFacade.GetPageUrl(publishedredirectKeyword.LandingPage, cultureInfo) : null, KeywordUnpublished = redirectKeyword.Keyword, LandingPageUnpublished = KeywordFacade.GetPageUrl(redirectKeyword.LandingPage, cultureInfo), PublishDate = existingPublishSchedule?.PublishDate.ToTimeZoneDateTimeString(), UnpublishDate = existingUnpublishSchedule?.UnpublishDate.ToTimeZoneDateTimeString(), }); } } } _keywordsCache[cultureInfo] = result; } return(result); }
private List <Model.RedirectKeyword> LoadKeywords(CultureInfo cultureInfo) { var result = new List <Model.RedirectKeyword>(); using (var connection = new DataConnection(PublicationScope.Unpublished, cultureInfo)) { foreach (var redirectKeyword in connection.Get <RedirectKeyword>()) { var interfaceType = redirectKeyword.DataSourceId.InterfaceType; var stringKey = redirectKeyword.GetUniqueKey().ToString(); var locale = redirectKeyword.DataSourceId.LocaleScope.Name; var existingPublishSchedule = PublishScheduleHelper.GetPublishSchedule(interfaceType, stringKey, locale); var existingUnpublishSchedule = PublishScheduleHelper.GetUnpublishSchedule(interfaceType, stringKey, locale); Model.RedirectKeyword keyword; if (redirectKeyword.PublicationStatus == GenericPublishProcessController.Published) { keyword = new Model.RedirectKeyword { Keyword = redirectKeyword.Keyword, LandingPage = KeywordFacade.GetPageUrl(redirectKeyword.LandingPage, cultureInfo), PublishDate = existingPublishSchedule?.PublishDate.ToTimeZoneDateTimeString(), UnpublishDate = existingUnpublishSchedule?.UnpublishDate.ToTimeZoneDateTimeString(), HomePage = GetHomePageTitle(redirectKeyword.HomePage.GetValueOrDefault()), HomePageId = redirectKeyword.HomePage.GetValueOrDefault(), }; } else { var publishedredirectKeyword = DataFacade.GetDataFromOtherScope(redirectKeyword, DataScopeIdentifier.Public).FirstOrDefault(); keyword = new Model.RedirectKeyword { Keyword = redirectKeyword.Keyword ?? publishedredirectKeyword?.Keyword, LandingPage = publishedredirectKeyword != null?KeywordFacade.GetPageUrl(publishedredirectKeyword.LandingPage, cultureInfo) : null, LandingPageUnpublished = KeywordFacade.GetPageUrl(redirectKeyword.LandingPage, cultureInfo), PublishDate = existingPublishSchedule?.PublishDate.ToTimeZoneDateTimeString(), UnpublishDate = existingUnpublishSchedule?.UnpublishDate.ToTimeZoneDateTimeString(), HomePage = GetHomePageTitle((redirectKeyword.HomePage ?? publishedredirectKeyword?.HomePage).GetValueOrDefault()), HomePageId = (redirectKeyword.HomePage ?? publishedredirectKeyword?.HomePage).GetValueOrDefault(), }; } result.Add(keyword); } } return(result); }
public static void HandlePublishUnpublishWorkflows(IPage selectedPage, string cultureName, DateTime?publishDate, DateTime?unpublishDate, ref WorkflowInstance publishWorkflowInstance, ref WorkflowInstance unpublishWorkflowInstance) { var existingPublishSchedule = PublishScheduleHelper.GetPublishSchedule(typeof(IPage), selectedPage.Id.ToString(), cultureName); if (existingPublishSchedule != null) { WorkflowFacade.AbortWorkflow(existingPublishSchedule.WorkflowInstanceId); DataFacade.Delete(existingPublishSchedule); } if (publishDate != null) { publishWorkflowInstance = WorkflowFacade.CreateNewWorkflow( typeof(PagePublishSchedulerWorkflow), new Dictionary <string, object> { { "Date", publishDate }, { "PageId", selectedPage.Id }, { "LocaleName", cultureName } }); PublishScheduleHelper.CreatePublishSchedule(typeof(IPage), selectedPage.Id.ToString(), cultureName, publishDate.Value, publishWorkflowInstance); } var existingUnpublishSchedule = PublishScheduleHelper.GetUnpublishSchedule(typeof(IPage), selectedPage.Id.ToString(), cultureName); if (existingUnpublishSchedule != null) { WorkflowFacade.AbortWorkflow(existingUnpublishSchedule.WorkflowInstanceId); DataFacade.Delete(existingUnpublishSchedule); } if (unpublishDate != null) { unpublishWorkflowInstance = WorkflowFacade.CreateNewWorkflow( typeof(PageUnpublishSchedulerWorkflow), new Dictionary <string, object> { { "Date", unpublishDate }, { "PageId", selectedPage.Id }, { "LocaleName", cultureName } }); PublishScheduleHelper.CreateUnpublishSchedule(typeof(IPage), selectedPage.Id.ToString(), cultureName, unpublishDate.Value, unpublishWorkflowInstance); } }
protected override void Execute() { Type type = TypeManager.GetType(DataType); using (new DataScope(DataScopeIdentifier.Administrated, CultureInfo.CreateSpecificCulture(LocaleName))) { DataEntityToken dataEntityToken; using (var transaction = TransactionsFacade.CreateNewScope()) { var publishSchedule = PublishScheduleHelper.GetPublishSchedule(type, DataId, LocaleName); DataFacade.Delete(publishSchedule); var data = (IPublishControlled)DataFacade.TryGetDataByUniqueKey(type, DataId); if (data == null) { Log.LogWarning(LogTitle, $"Failed to find data of type '{type}' by id '{DataId}'."); transaction.Complete(); return; } dataEntityToken = data.GetDataEntityToken(); var transitions = ProcessControllerFacade.GetValidTransitions(data).Keys; if (transitions.Contains(GenericPublishProcessController.Published)) { data.PublicationStatus = GenericPublishProcessController.Published; DataFacade.Update(data); Log.LogVerbose(LogTitle, $"Scheduled publishing of data with label '{data.GetLabel()}' is complete"); } else { Log.LogWarning(LogTitle, $"Scheduled publishing of data with label '{data.GetLabel()}' could not be done because the data is not in a publisheble state"); } transaction.Complete(); } EntityTokenCacheFacade.ClearCache(dataEntityToken); PublishControlledHelper.ReloadDataElementInConsole(dataEntityToken); } }
protected override void Execute() { using (new DataScope(DataScopeIdentifier.Administrated, CultureInfo.CreateSpecificCulture(LocaleName))) { IPage page; using (var transaction = TransactionsFacade.CreateNewScope()) { var pagePublishSchedule = PublishScheduleHelper.GetPublishSchedule(typeof(IPage), PageId.ToString(), LocaleName); DataFacade.Delete(pagePublishSchedule); page = DataFacade.GetData <IPage>(p => p.Id == PageId).FirstOrDefault(); Verify.IsNotNull(page, "The page with the id {0} does not exist", PageId); var transitions = ProcessControllerFacade.GetValidTransitions(page).Keys; if (transitions.Contains(GenericPublishProcessController.Published)) { page.PublicationStatus = GenericPublishProcessController.Published; DataFacade.Update(page); Log.LogVerbose(LogTitle, "Scheduled publishing of page with title '{0}' is complete", page.Title); } else { Log.LogWarning(LogTitle, "Scheduled publishing of page with title '{0}' could not be done because the page is not in a publisheble state", page.Title); } transaction.Complete(); } PublishControlledHelper.ReloadPageElementInConsole(page); } }
/// <exclude /> public Dictionary <string, object> GetBindings(IData dataObject, bool allowMandatoryNonDefaultingProperties) { if (dataObject == null) { throw new ArgumentNullException("dataObject"); } var bindings = new Dictionary <string, object>(); foreach (var fieldDescriptor in _dataTypeDescriptor.Fields) { var propertyInfo = dataObject.GetType().GetProperty(fieldDescriptor.Name); if (propertyInfo.CanRead) { var value = propertyInfo.GetGetMethod().Invoke(dataObject, null); if (value == null && !fieldDescriptor.IsNullable) { if (fieldDescriptor.IsNullable) { // Ignore, null is allowed } else if (fieldDescriptor.InstanceType.IsGenericType && fieldDescriptor.InstanceType.GetGenericTypeDefinition() == typeof(Nullable <>)) { // Ignore, null is allowed } else if (allowMandatoryNonDefaultingProperties) { if (propertyInfo.PropertyType == typeof(string) && fieldDescriptor.ForeignKeyReferenceTypeName == null) //FK fields stay NULL { value = ""; } else { value = GetDefaultValue(propertyInfo.PropertyType); } } else { throw new InvalidOperationException(string.Format("Field '{0}' on type '{1}' is null, does not allow null and does not have a default value", fieldDescriptor.Name, _dataTypeDescriptor.TypeManagerTypeName)); } } bindings.Add(GetBindingName(fieldDescriptor), value); } } if (_showPublicationStatusSelector && _dataTypeDescriptor.SuperInterfaces.Contains(typeof(IPublishControlled))) { bindings[PublicationStatusBindingName] = ((IPublishControlled)dataObject).PublicationStatus; bindings.Add(PublicationStatusOptionsBindingName, GetAvailablePublishingFlowTransitions(EntityToken)); var intefaceType = dataObject.DataSourceId.InterfaceType; var stringKey = dataObject.GetUniqueKey().ToString(); var locale = dataObject.DataSourceId.LocaleScope.Name; var existingPublishSchedule = PublishScheduleHelper.GetPublishSchedule(intefaceType, stringKey, locale); bindings.Add("PublishDate", existingPublishSchedule != null ? existingPublishSchedule.PublishDate : (DateTime?)null); var existingUnpublishSchedule = PublishScheduleHelper.GetUnpublishSchedule(intefaceType, stringKey, locale); bindings.Add("UnpublishDate", existingUnpublishSchedule != null ? existingUnpublishSchedule.UnpublishDate : (DateTime?)null); } return(bindings); }
private void editStateCodeActivity_ExecuteCode(object sender, EventArgs e) { if (!PermissionsFacade.GetPermissionsForCurrentUser(EntityToken).Contains(PermissionType.Publish)) { var formData = WorkflowFacade.GetFormData(InstanceId, true); if (formData.ExcludedEvents == null) { formData.ExcludedEvents = new List <string>(); } formData.ExcludedEvents.Add("SaveAndPublish"); } IPage selectedPage; if (!BindingExist("SelectedPage")) { selectedPage = GetDataItemFromEntityToken <IPage>(); if (selectedPage.PublicationStatus == GenericPublishProcessController.Published) { selectedPage.PublicationStatus = GenericPublishProcessController.Draft; } Bindings.Add("SelectedPage", selectedPage); } else { selectedPage = GetBinding <IPage>("SelectedPage"); } if (!BindingExist("UrlTitleIsRequired")) { var isRootPage = PageManager.GetParentId(selectedPage.Id) == Guid.Empty; Bindings["UrlTitleIsRequired"] = !isRootPage; Bindings["IsRootPage"] = isRootPage; } IFormMarkupProvider markupProvider = new FormDefinitionFileMarkupProvider(@"\Administrative\EditPage.xml"); XDocument formDocument; using (var reader = markupProvider.GetReader()) { formDocument = XDocument.Load(reader); } var bindingsXElement = formDocument.Root.Element(DataTypeDescriptorFormsHelper.CmsNamespace + FormKeyTagNames.Bindings); var layoutXElement = formDocument.Root.Element(DataTypeDescriptorFormsHelper.CmsNamespace + FormKeyTagNames.Layout); var tabPanelsXElement = layoutXElement.Element(DataTypeDescriptorFormsHelper.MainNamespace + "TabPanels"); IEnumerable <ICompositionContainer> compositionContainers = selectedPage.GetAllowedMetaDataContainers().Evaluate(); var compositionTabs = new Dictionary <Guid, XElement>(); foreach (var compositionContainer in compositionContainers) { var element = new XElement(Namespaces.BindingFormsStdUiControls10 + "PlaceHolder"); element.Add(new XAttribute("Label", StringResourceSystemFacade.ParseString(compositionContainer.Label))); compositionTabs.Add(compositionContainer.Id, element); } var clientValidationRules = new Dictionary <string, List <ClientValidationRule> >(); var pageMetaDataDefinitions = selectedPage.GetAllowedMetaDataDefinitions(); foreach (var pageMetaDataDefinition in pageMetaDataDefinitions) { var metaDatTypeId = pageMetaDataDefinition.MetaDataTypeId; var dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(metaDatTypeId); Verify.IsNotNull(dataTypeDescriptor, "Failed to get meta data type by id '{0}'. If data type was purposely removed, in order to fix this exception you should remove IPageMetaDataDefinition records that reference this data type.", metaDatTypeId); var metaDataType = TypeManager.TryGetType(dataTypeDescriptor.TypeManagerTypeName); Verify.IsNotNull(metaDataType, "Failed to get meta data type '{0}', id: {1}. If it has been removed, references from '{2}' have to be removed as well", dataTypeDescriptor.TypeManagerTypeName, metaDatTypeId, typeof(IPageMetaDataDefinition).Name); var helper = CreateDataTypeDescriptorFormsHelper(pageMetaDataDefinition, dataTypeDescriptor); var metaData = selectedPage.GetMetaData(pageMetaDataDefinition.Name, metaDataType); if (metaData == null) { metaData = DataFacade.BuildNew(metaDataType); PageMetaDataFacade.AssignMetaDataSpecificValues(metaData, pageMetaDataDefinition.Name, selectedPage); var localizedData = metaData as ILocalizedControlled; if (localizedData != null) { localizedData.SourceCultureName = UserSettings.ActiveLocaleCultureInfo.Name; } var publishControlled = metaData as IPublishControlled; publishControlled.PublicationStatus = GenericPublishProcessController.Draft; helper.UpdateWithNewBindings(Bindings); helper.ObjectToBindings(metaData, Bindings); } else { helper.UpdateWithBindings(metaData, Bindings); } bindingsXElement.Add(helper.BindingXml.Elements()); compositionTabs[pageMetaDataDefinition.MetaDataContainerId].Add(helper.PanelXml); clientValidationRules.AddDictionary(helper.GetBindingsValidationRules(metaData)); } var previewTabPanel = tabPanelsXElement.Elements().Last(); foreach (var element in compositionTabs.Values) { previewTabPanel.AddBeforeSelf(element); } IDictionary <string, string> transitionNames = new Dictionary <string, string>(); transitionNames.Add(GenericPublishProcessController.Draft, StringResourceSystemFacade.GetString("Composite.Management", "Website.Forms.Administrative.EditPage.DraftTransition")); transitionNames.Add(GenericPublishProcessController.AwaitingApproval, StringResourceSystemFacade.GetString("Composite.Management", "Website.Forms.Administrative.EditPage.AwaitingApprovalTransition")); var username = UserValidationFacade.GetUsername(); var userPermissionDefinitions = PermissionTypeFacade.GetUserPermissionDefinitions(username); var userGroupPermissionDefinitions = PermissionTypeFacade.GetUserGroupPermissionDefinitions(username); var currentPermissionTypes = PermissionTypeFacade.GetCurrentPermissionTypes(UserValidationFacade.GetUserToken(), EntityToken, userPermissionDefinitions, userGroupPermissionDefinitions); foreach (var permissionType in currentPermissionTypes) { if (GenericPublishProcessController.AwaitingPublicationActionPermissionType.Contains(permissionType)) { transitionNames.Add(GenericPublishProcessController.AwaitingPublication, StringResourceSystemFacade.GetString("Composite.Management", "Website.Forms.Administrative.EditPage.AwaitingPublicationTransition")); break; } } var contents = DataFacade.GetData <IPagePlaceholderContent>(f => f.PageId == selectedPage.Id).ToList(); var namedXhtmlFragments = contents.ToDictionary(content => content.PlaceHolderId, content => content.Content ?? ""); UpdateBinding("SelectablePageTypeIds", GetSelectablePageTypes()); UpdateBinding("SelectableTemplateIds", GetSelectablePageTemplates()); UpdateBinding("NamedXhtmlFragments", namedXhtmlFragments); UpdateBinding("StateOptions", transitionNames); var existingPagePublishSchedule = PublishScheduleHelper.GetPublishSchedule(typeof(IPage), selectedPage.Id.ToString(), UserSettings.ActiveLocaleCultureInfo.Name); UpdateBinding("PublishDate", existingPagePublishSchedule?.PublishDate); var existingPageUnpublishSchedule = PublishScheduleHelper.GetUnpublishSchedule(typeof(IPage), selectedPage.Id.ToString(), UserSettings.ActiveLocaleCultureInfo.Name); UpdateBinding("UnpublishDate", existingPageUnpublishSchedule?.UnpublishDate); var formDefinition = formDocument.GetDocumentAsString(); DeliverFormData( selectedPage.Title, StandardUiContainerTypes.Document, formDefinition, Bindings, clientValidationRules ); }