Ejemplo n.º 1
0
 public IEnumerable <string> GetErrors(DocumentImportDTO item, IList <DocumentImportDTO> allItems)
 {
     if (string.IsNullOrWhiteSpace(item.DocumentType) || DocumentMetadataHelper.GetTypeByName(item.DocumentType) == null)
     {
         yield return("Document Type is not valid MrCMS type.");
     }
 }
Ejemplo n.º 2
0
        public IEnumerable <SelectListItem> GetValidParents(Webpage webpage)
        {
            List <DocumentMetadata> validParentTypes = DocumentMetadataHelper.GetValidParentTypes(webpage);

            List <string> validParentTypeNames =
                validParentTypes.Select(documentMetadata => documentMetadata.Type.FullName).ToList();
            IList <Webpage> potentialParents =
                _session.QueryOver <Webpage>()
                .Where(page => page.DocumentType.IsIn(validParentTypeNames))
                .Cacheable().List <Webpage>();

            List <SelectListItem> result = potentialParents.Distinct()
                                           .Where(page => !page.ActivePages.Contains(webpage))
                                           .OrderBy(x => x.Name)
                                           .BuildSelectItemList(page => string.Format("{0} ({1})", page.Name, page.GetMetadata().Name),
                                                                page => page.Id.ToString(),
                                                                webpage1 => webpage.Parent != null && webpage.ParentId == webpage1.Id, emptyItem: null);

            if (!webpage.GetMetadata().RequiresParent)
            {
                result.Insert(0, SelectListItemHelper.EmptyItem("Root"));
            }

            return(result);
        }
Ejemplo n.º 3
0
        protected override BatchJobExecutionResult OnExecute(ImportDocumentBatchJob batchJob)
        {
            using (EventContext.Instance.Disable <IOnTransientNotificationPublished>())
                using (EventContext.Instance.Disable <IOnPersistentNotificationPublished>())
                    using (EventContext.Instance.Disable <UpdateIndicesListener>())
                        using (EventContext.Instance.Disable <UpdateUniversalSearch>())
                            using (EventContext.Instance.Disable <WebpageUpdatedNotification>())
                                using (EventContext.Instance.Disable <DocumentAddedNotification>())
                                    using (EventContext.Instance.Disable <MediaCategoryUpdatedNotification>())
                                    {
                                        var documentImportDto = batchJob.DocumentImportDto;
                                        var webpage           =
                                            GetWebpageByUrl(documentImportDto.UrlSegment);

                                        var isNew = webpage == null;
                                        if (isNew)
                                        {
                                            webpage = (Webpage)
                                                      Activator.CreateInstance(DocumentMetadataHelper.GetTypeByName(documentImportDto.DocumentType));
                                        }

                                        if (!String.IsNullOrEmpty(documentImportDto.ParentUrl))
                                        {
                                            var parent = GetWebpageByUrl(documentImportDto.ParentUrl);
                                            webpage.Parent = parent;
                                        }
                                        if (documentImportDto.UrlSegment != null)
                                        {
                                            webpage.UrlSegment = documentImportDto.UrlSegment;
                                        }
                                        webpage.Name               = documentImportDto.Name;
                                        webpage.BodyContent        = documentImportDto.BodyContent;
                                        webpage.MetaTitle          = documentImportDto.MetaTitle;
                                        webpage.MetaDescription    = documentImportDto.MetaDescription;
                                        webpage.MetaKeywords       = documentImportDto.MetaKeywords;
                                        webpage.RevealInNavigation = documentImportDto.RevealInNavigation;
                                        webpage.RequiresSSL        = documentImportDto.RequireSSL;
                                        webpage.DisplayOrder       = documentImportDto.DisplayOrder;
                                        webpage.PublishOn          = documentImportDto.PublishDate;

                                        _updateTagsService.SetTags(documentImportDto, webpage);
                                        _updateUrlHistoryService.SetUrlHistory(documentImportDto, webpage);

                                        _session.Transact(session =>
                                        {
                                            if (isNew)
                                            {
                                                session.Save(webpage);
                                            }
                                            else
                                            {
                                                session.Update(webpage);
                                            }
                                        });

                                        return(BatchJobExecutionResult.Success());
                                    }
        }
Ejemplo n.º 4
0
        private IOrderedEnumerable <Webpage> GetValidParentWebpages(Webpage webpage)
        {
            List <DocumentMetadata> validParentTypes = DocumentMetadataHelper.GetValidParentTypes(webpage);

            List <string> validParentTypeNames =
                validParentTypes.Select(documentMetadata => documentMetadata.Type.FullName).ToList();
            IList <Webpage> potentialParents =
                _webpageRepository.Query()
                .Where(page => validParentTypeNames.Contains(page.DocumentType))
                .ToList();

            var webpages = potentialParents.Distinct()
                           .Where(page => !page.ActivePages.Contains(webpage))
                           .OrderBy(x => x.Name);

            return(webpages);
        }