コード例 #1
0
        public override string GetLinkText(string linkId)
        {
            string textToReturn = string.Empty;

            ArticleItem item = SearchService.GetArticleByNumber(linkId);

            if (item == null)
            {
                return(string.Empty);
            }

            textToReturn += "\"" + item._Name + "\" ";

            using (var db = new SitecoreService(Constants.MasterDb))
            {
                var  articleItem     = db.GetItem <Item>(item._Id);
                var  publicationItem = ArticleExtension.GetAncestorItemBasedOnTemplateID(articleItem);
                Guid publicationGuid = publicationItem.ID.Guid;
                var  publication     = db.GetItem <ISite_Root>(publicationGuid);
                textToReturn += "\"" + publication?.Publication_Name + "\" ";
            }

            // Not sure that we have an issue anymore
            //var issue = item.GetIssue();
            //textToReturn += issue.FormattedDate;

            return(textToReturn);
        }
コード例 #2
0
        public MediaItem SaveWordDocIntoMediaLibrary(ArticleItem article, string fileName, string docName, string extension)
        {
            var  item            = _sitecoreMasterService.GetItem <Item>(article._Id);
            var  publicationItem = ArticleExtension.GetAncestorItemBasedOnTemplateID(item);
            Guid publicationGuid = publicationItem.ID.Guid;
            var  articleDate     = article.Planned_Publish_Date > DateTime.MinValue ? article.Planned_Publish_Date : article.Created_Date;
            var  itemFolder      = GetMediaFolder(publicationGuid, articleDate);
            var  path            = itemFolder._Path;

            return(CreateMediaLibraryItemFromFile(fileName, docName, extension, path));
        }
コード例 #3
0
        private string GetFilenamePrefix(ArticleItem article)
        {
            using (var db = new SitecoreService(Constants.MasterDb))
            {
                var  articleItem     = db.GetItem <Item>(article._Id);
                var  publicationItem = ArticleExtension.GetAncestorItemBasedOnTemplateID(articleItem);
                Guid publicationGuid = publicationItem.ID.Guid;

                string publicationName;
                publicationName = Constants.PublicationPrefixDictionary.TryGetValue(publicationGuid, out publicationName)
                                        ? publicationName
                                        : Constants.ScripPublicationName;

                return($"{publicationName}_{article.Article_Number}");
            }
        }
コード例 #4
0
        public ArticlePreviewInfo GetPreviewInfo(ArticleItem article)
        {
            var  item            = _sitecoreMasterService.GetItem <Item>(article._Id);
            var  publicationItem = ArticleExtension.GetAncestorItemBasedOnTemplateID(item);
            Guid publicationGuid = publicationItem.ID.Guid;

            return(new ArticlePreviewInfo
            {
                Title = HttpUtility.HtmlDecode(article.Title),
                Publication = _sitecoreMasterService.GetItem <IGlassBase>(publicationGuid)._Name,
                Authors = article.Authors.Select(r => (((IStaff_Item)r).Last_Name + "," + ((IStaff_Item)r).First_Name)).ToList(),
                ArticleNumber = article.Article_Number,
                Date = article.Actual_Publish_Date,
                PreviewUrl = "http://" + WebUtil.GetHostName() + "/?sc_itemid={" + article._Id + "}&sc_mode=preview&sc_lang=en",
                Guid = article._Id
            });
        }
コード例 #5
0
        protected void MoveArticleIfNecessary(ArticleItem article, ArticleStruct articleStruct)
        {
            var item = _sitecoreMasterService.GetItem <Item>(article._Id);

            using (new SecurityDisabler())
            {
                var publicationItem = ArticleExtension.GetAncestorItemBasedOnTemplateID(item);
                if (publicationItem != null)
                {
                    var publication = publicationItem.ID.Guid;
                    var newParent   = _articleUtil.GenerateDailyFolder(publication, articleStruct.WebPublicationDate);
                    if (newParent != null)
                    {
                        _sitecoreMasterService.Move(article, newParent);
                    }
                    //TODO - Verify if this feautre needs to be there or not.
                    //_wordDocToMediaLibrary.MoveWordDocIfNecessary(article, articleStruct, oldIssueID);
                }
            }
        }
コード例 #6
0
        public ArticleStruct GetArticleStruct(ArticleItem articleItem)
        {
            var  article         = _sitecoreMasterService.GetItem <ArticleItem>(articleItem._Id);
            var  item            = _sitecoreMasterService.GetItem <Item>(article._Id);
            var  publicationItem = ArticleExtension.GetAncestorItemBasedOnTemplateID(item);
            Guid publicationGuid = publicationItem.ID.Guid;

            var articleStruct = new ArticleStruct
            {
                ArticleGuid   = articleItem._Id,
                Title         = articleItem.Title,
                ArticleNumber = articleItem.Article_Number,
                Publication   = publicationGuid
            };

            if (articleItem.Content_Type != null)
            {
                articleStruct.Label = articleItem.Content_Type._Id;
            }

            if (articleItem.Media_Type != null)
            {
                articleStruct.MediaType = articleItem.Media_Type._Id;
            }
            articleStruct.WebPublicationDate   = articleItem.Planned_Publish_Date;
            articleStruct.PrintPublicationDate = articleItem.Actual_Publish_Date;
            articleStruct.Embargoed            = articleItem.Embargoed;
            var authors = articleItem.Authors.Select(r => ((IStaff_Item)r)).ToList();

            articleStruct.Authors = authors.Select(r => new StaffStruct {
                ID = r._Id, Name = r.Last_Name + ", " + r.First_Name,
            }).ToList();
            articleStruct.NotesToEditorial = articleItem.Editorial_Notes;

            articleStruct.RelatedArticlesInfo = articleItem.Related_Articles.Select(a => GetPreviewInfo(_sitecoreMasterService.GetItem <IArticle>(a._Id))).ToList();

            articleStruct.ArticleWorkflowState = GetWorkFlowState(articleItem._Id);


            articleStruct.FeaturedImageSource  = articleItem.Featured_Image_Source;
            articleStruct.FeaturedImageCaption = articleItem.Featured_Image_Caption;
            if (articleItem.Featured_Image_16_9 != null)
            {
                articleStruct.FeaturedImage = articleItem.Featured_Image_16_9.MediaId;
            }

            articleStruct.Taxonomoy = articleItem.Taxonomies.Select(r => new TaxonomyStruct()
            {
                Name = r._Name, ID = r._Id, Section = r._Parent._Name
            }).ToList();

            articleStruct.ReferencedArticlesInfo = articleItem.Referenced_Articles.Select(a => GetPreviewInfo((IArticle)a)).ToList();

            if (articleItem.Word_Document != null)
            {
                var wordDocURL = articleItem.Word_Document.Url;
                wordDocURL = wordDocURL.Replace("-", " ");
                var wordDoc = _sitecoreMasterService.GetItem <Item>(wordDocURL);

                if (wordDoc != null)
                {
                    articleStruct.WordDocVersionNumber  = wordDoc.Version.Number;
                    articleStruct.WordDocLastUpdateDate = wordDoc.Statistics.Updated.ToString();
                    articleStruct.WordDocLastUpdatedBy  = wordDoc.Statistics.UpdatedBy;
                }
            }

            try
            {
                //ISitecoreService service = new SitecoreContentContext();
                //var webItem = service.GetItem<Item>(articleItem._Id);
                //articleStruct.IsPublished = webItem != null;
                articleStruct.IsPublished = articleItem.Actual_Publish_Date != DateTime.MinValue && article.Actual_Publish_Date < DateTime.Now;
            }
            catch (Exception ex)
            {
                articleStruct.IsPublished = false;
            }

            return(articleStruct);
        }
コード例 #7
0
        /// <summary>
        /// Saves all the data about a changed article
        /// </summary>
        /// <param name="article">The existing article to update</param>
        /// <param name="articleStruct">The new data to be saved to the article</param>
        /// <param name="saveDocumentSpecificData"></param>
        /// <param name="addVersion">Should a new version be added</param>
        /// <param name="shouldNotify">Should notifications be sent for this update</param>
        /// <returns>The updated Sitecore item representing the article</returns>
        /// <remarks>This method could stand to be refactored into smaller chunks.</remarks>
        private ArticleItem SaveArticleDetails(ArticleItem article, ArticleStruct articleStruct, bool saveDocumentSpecificData, bool addVersion, bool shouldNotify = true)
        {
            var articleItem = _sitecoreMasterService.GetItem <Item>(article._Id);
            var publication = ArticleExtension.GetAncestorItemBasedOnTemplateID(articleItem);

            articleStruct.Publication = publication.ID.Guid;
            //IIPP-243 - Moving the location of the article if needed
            if (!article.IsPublished && article.Planned_Publish_Date != articleStruct.WebPublicationDate)
            {
                MoveArticleIfNecessary(article, articleStruct);
            }
            string userID   = articleItem.Locking.GetOwner();
            bool   loggedIn = false;

            if (!IsNullOrEmpty(userID))
            {
                loggedIn = Sitecore.Context.User.IsAuthenticated;
            }

            var newVersion = article;
            var info       = new WorkflowInfo(Guid.Empty.ToString(), Guid.Empty.ToString());

            try
            {
                Item updatedVersion;

                if (addVersion)
                {
                    using (new EditContext(articleItem))
                    {
                        ItemState itemState = articleItem.State;
                        if (itemState != null)
                        {
                            WorkflowState workflowState = itemState.GetWorkflowState();
                            if (workflowState != null)
                            {
                                IWorkflow workflow = itemState.GetWorkflow();

                                string state = workflowState.StateID;
                                if (workflow != null && state != null)
                                {
                                    info = new WorkflowInfo(workflow.WorkflowID, state);
                                    //					// remove the old version from workflow and prevent from being published
                                    //					// Note: to remove an item from workflow requires using the fields, rather than the SetWorkflowInfo
                                    //					//  method, because the SetWorkflowInfo method does not allow empty strings
                                    articleItem.Fields[Sitecore.FieldIDs.WorkflowState].Value = null;
                                    articleItem.Fields[Sitecore.FieldIDs.HideVersion].Value   = "1";
                                }
                            }
                        }
                        //newVersion = article.InnerItem.Versions.AddVersion();
                        updatedVersion = articleItem.Versions.AddVersion();
                        newVersion     = _sitecoreMasterService.GetItem <ArticleItem>(updatedVersion.ID.ToString());
                    }
                }
                else
                {
                    newVersion = article;
                }
            }
            catch (Exception ex)
            {
                var ax = new ApplicationException("Workflow: Error with versioning/workflow while saving article [" + article.Article_Number + "]!", ex);
                throw ax;
            }

            try
            {
                var newVersionItem = _sitecoreMasterService.GetItem <Item>(newVersion._Id);
                using (new EditContext(newVersionItem))
                {
                    SaveArticleFields(newVersion, article, articleStruct, saveDocumentSpecificData);
                    if (saveDocumentSpecificData)
                    {
                        RenameArticleItem(newVersion, articleStruct);
                    }


                    if (info.StateID != Guid.Empty.ToString() && info.WorkflowID != Guid.Empty.ToString())
                    {
                        // Doing this twice is intentional: when we do it once, the workflow field gets set to the empty string.
                        //  I don't know why, but it does. Doing this twice sets it properly. Doing it not at all causes the
                        //  workflow field to be set to the empty string when leaving the edit context.

                        newVersionItem.Database.DataManager.SetWorkflowInfo(newVersionItem, info);
                        newVersionItem.Database.DataManager.SetWorkflowInfo(newVersionItem, info);

                        if (articleStruct.CommandID != Guid.Empty)
                        {
                            //newVersion.NotificationTransientField.ShouldSend.Checked = true;
                            _articleUtil.ExecuteCommandAndGetWorkflowState(newVersionItem, articleStruct.CommandID.ToString());

                            if (shouldNotify)
                            {
                                _emailUtil.SendNotification(articleStruct, info);
                            }
                        }
                    }
                }

                if (loggedIn)
                {
                    _sitecoreMasterService.GetItem <Item>(newVersion._Id).Locking.Lock();
                }
            }

            catch (Exception ex)
            {
                var ax = new ApplicationException("Workflow: Error with saving details while saving article [" + article.Article_Number + "]!", ex);
                throw ax;
            }

            //  Notifying the Editors when stories are edited after pushlished
            if (articleStruct.IsPublished)
            {
                // Setting the workflow to "Edit After Publish".
                try
                {
                    var newVersionItem = _sitecoreMasterService.GetItem <Item>(newVersion._Id);
                    newVersionItem.Locking.Unlock();

                    using (new EditContext(newVersionItem))
                    {
                        newVersionItem[FieldIDs.WorkflowState] = _siteWorkflow.GetEditAfterPublishState(newVersionItem)._Id.ToString();// Constants.EditAfterPublishWorkflowCommand;
                    }

                    if (loggedIn)
                    {
                        _sitecoreMasterService.GetItem <Item>(newVersion._Id).Locking.Lock();
                    }
                }
                catch (Exception ex)
                {
                    var ax =
                        new ApplicationException(
                            "Workflow: Error with changing the workflow to Edit After Publish [" + article.Article_Number + "]!", ex);
                    throw ax;
                }

                try
                {
                    _emailUtil.EditAfterPublishSendNotification(articleStruct);
                }
                catch (Exception ex)
                {
                    Sitecore.Diagnostics.Log.Error("SitecoreSaverUtil.SaveArticleDetails EditAfterPublishSendNotification(): " + ex.ToString(), this);
                }
            }
            return(newVersion);
        }