Пример #1
0
        protected override BatchJobExecutionResult OnExecute(CompleteMergeBatchJob batchJob)
        {
            using (new NotificationDisabler())
            {
                var webpage = _session.Get <Webpage>(batchJob.WebpageId);
                if (webpage == null)
                {
                    return(BatchJobExecutionResult.Failure("Could not find the webpage with id " + batchJob.WebpageId));
                }
                var mergeInto = _session.Get <Webpage>(batchJob.MergedIntoId);
                if (mergeInto == null)
                {
                    return(BatchJobExecutionResult.Failure("Could not find the webpage with id " + batchJob.MergedIntoId));
                }

                _session.Transact(session =>
                {
                    ApplyCustomMergeLogic(webpage, mergeInto);

                    var urlSegment = webpage.UrlSegment;
                    session.Delete(webpage);
                    var urlHistory = new UrlHistory
                    {
                        UrlSegment = urlSegment,
                        Webpage    = mergeInto,
                    };
                    mergeInto.Urls.Add(urlHistory);
                    session.Save(urlHistory);
                });


                return(BatchJobExecutionResult.Success());
            }
        }
Пример #2
0
        protected override BatchJobExecutionResult OnExecute(UpdateUrlBatchJob batchJob)
        {
            using (new NotificationDisabler())
            {
                var webpage = _session.Get <Webpage>(batchJob.WebpageId);
                if (webpage == null)
                {
                    return(BatchJobExecutionResult.Failure("Could not find the webpage with id " + batchJob.WebpageId));
                }

                _session.Transact(session =>
                {
                    var urlHistories = webpage.Urls.ToList();
                    foreach (var webpageUrl in urlHistories)
                    {
                        if (!batchJob.NewUrl.Equals(webpageUrl.UrlSegment, StringComparison.InvariantCultureIgnoreCase))
                        {
                            continue;
                        }

                        webpage.Urls.Remove(webpageUrl);
                        session.Delete(webpageUrl);
                    }

                    webpage.UrlSegment = batchJob.NewUrl;
                    session.Update(webpage);
                });

                return(BatchJobExecutionResult.Success());
            }
        }
        protected override BatchJobExecutionResult OnExecute(MoveWebpageBatchJob batchJob)
        {
            using (new NotificationDisabler())
            {
                var webpage = _session.Get <Webpage>(batchJob.WebpageId);
                if (webpage == null)
                {
                    return(BatchJobExecutionResult.Failure("Could not find the webpage with id " + batchJob.WebpageId));
                }

                var parent = batchJob.NewParentId.HasValue ? _session.Get <Webpage>(batchJob.NewParentId) : null;
                if (batchJob.NewParentId.HasValue && parent == null)
                {
                    return(BatchJobExecutionResult.Failure("Could not find the parent webpage with id " + batchJob.NewParentId));
                }

                _session.Transact(session =>
                {
                    webpage.Parent = parent;
                    session.Update(webpage);
                });

                return(BatchJobExecutionResult.Success());
            }
        }
Пример #4
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());
                                    }
        }
 protected override BatchJobExecutionResult OnExecute(RebuildUniversalSearchIndex batchJob)
 {
     try
     {
         _universalSearchIndexManager.ReindexAll();
         return(BatchJobExecutionResult.Success());
     }
     catch (Exception exception)
     {
         CurrentRequestData.ErrorSignal.Raise(exception);
         return(BatchJobExecutionResult.Failure(exception.Message));
     }
 }
Пример #6
0
 protected override BatchJobExecutionResult OnExecute(ImportProductBatchJob batchJob)
 {
     using (new NotificationDisabler())
     {
         try
         {
             _importProductsService.ImportProduct(batchJob.DTO);
             return(BatchJobExecutionResult.Success());
         }
         catch (Exception exception)
         {
             CurrentRequestData.ErrorSignal.Raise(exception);
             return(BatchJobExecutionResult.Failure(exception.Message));
         }
     }
 }
Пример #7
0
        protected override BatchJobExecutionResult OnExecute(MigrateFilesBatchJob batchJob)
        {
            List <Guid> guids = JsonConvert.DeserializeObject <HashSet <Guid> >(batchJob.Data).ToList();

            IList <MediaFile> mediaFiles = _session.QueryOver <MediaFile>().Where(x => x.Guid.IsIn(guids)).List();


            foreach (MediaFile mediaFile in mediaFiles)
            {
                IFileSystem from = MediaFileExtensions.GetFileSystem(mediaFile.FileUrl, _fileSystems);
                IFileSystem to   = CurrentFileSystem;
                if (from.GetType() == to.GetType())
                {
                    continue;
                }

                _session.Transact(session =>
                {
                    // remove resized images (they will be regenerated on the to system)
                    foreach (ResizedImage resizedImage in mediaFile.ResizedImages.ToList())
                    {
                        // check for resized file having same url as the original -
                        // do not delete from disc yet in that case, or else it will cause an error when copying
                        if (resizedImage.Url != mediaFile.FileUrl)
                        {
                            from.Delete(resizedImage.Url);
                        }
                        mediaFile.ResizedImages.Remove(resizedImage);
                        session.Delete(resizedImage);
                    }

                    string existingUrl = mediaFile.FileUrl;
                    using (System.IO.Stream readStream = @from.GetReadStream(existingUrl))
                    {
                        mediaFile.FileUrl = to.SaveFile(readStream, GetNewFilePath(mediaFile),
                                                        mediaFile.ContentType);
                    }
                    from.Delete(existingUrl);

                    session.Update(mediaFile);
                });
            }


            return(BatchJobExecutionResult.Success());
        }
Пример #8
0
 protected override BatchJobExecutionResult OnExecute(RebuildLuceneIndex batchJob)
 {
     _indexService.Reindex(batchJob.IndexName);
     return(BatchJobExecutionResult.Success());
 }