Exemplo n.º 1
0
        /// <summary>
        /// This method gets called from a scheduled task command.
        /// You define a scheduled task command by navigating to
        /// /System/Tasks/Commands and inserting a new command
        /// </summary>
        /// <param name="items">Items to publish</param>
        /// <param name="command">Command Info</param>
        /// <param name="schedule">Schedule Item</param>
        public void Run(Item[] items, Tasks.CommandItem command, Tasks.ScheduleItem schedule)
        {
            //DateTime dtPublishDate = DateTime.UtcNow;

            using (new SecurityDisabler())
            {
                try
                {
                    // for each existing target
                    Sitecore.Collections.ChildList publishingTargets = master.GetItem(Constants.PublishingTargetsFolder)?.Children;
                    foreach (Item publishingTarget in publishingTargets)
                    {
                        var targetDatabase = GetTargetDatabase(publishingTarget);
                        if (targetDatabase == null)
                        {
                            Log.Info("Skipping target: Could not find Database target for Publishing target: " + publishingTarget.Name, this);
                            continue;
                        }

                        PublishItems(items, publishingTarget, targetDatabase);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("Error Publishing in Automated Publisher", ex, this);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method gets called from a scheduled task command.
        /// You define a scheduled task command by navigating to
        /// /System/Tasks/Commands and inserting a new command
        /// </summary>
        /// <param name="items">Items to publish</param>
        /// <param name="command">Command Info</param>
        /// <param name="schedule">Schedule Item</param>
        public void Run(Item[] items, Tasks.CommandItem command, Tasks.ScheduleItem schedule)
        {
            DateTime dtPublishDate = DateTime.UtcNow;

            using (new SecurityDisabler())
            {
                try
                {
                    Database master = Sitecore.Configuration.Factory.GetDatabase(Constants.MasterDatabaseName);
                    Sitecore.Globalization.Language[] languages = master.Languages;

                    // for each existing target
                    Item publishingTargetsFolder = master.GetItem(Constants.PublishingTargetsFolder);
                    Sitecore.Collections.ChildList publishingTargets = publishingTargetsFolder.Children;
                    foreach (Item publishingTarget in publishingTargets)
                    {
                        if (publishingTarget != null)
                        {
                            string targetDBName = publishingTarget[Constants.TargetDatabase];
                            if (string.IsNullOrEmpty(targetDBName) == false)
                            {
                                Database targetDb = Sitecore.Configuration.Factory.GetDatabase(targetDBName);
                                if (targetDb != null)
                                {
                                    // for each existing language
                                    foreach (Sitecore.Globalization.Language language in languages)
                                    {
                                        foreach (Item actItem in items)
                                        {
                                            ID   itemToPublishId = actItem.ID;
                                            Item itemToPublish   = master.GetItem(itemToPublishId, language);
                                            bool bPublish        = false;

                                            Sitecore.Data.Fields.MultilistField targets = itemToPublish.Fields[Sitecore.FieldIDs.PublishingTargets];
                                            if (targets != null)
                                            {
                                                Item[] itemToPublishTargets = targets.GetItems();
                                                if (itemToPublishTargets.Length > 0)
                                                {
                                                    foreach (Item itemToPublishTarget in itemToPublishTargets)
                                                    {
                                                        if (string.Equals(itemToPublishTarget.Name, publishingTarget.Name, StringComparison.CurrentCultureIgnoreCase) == true)
                                                        {
                                                            bPublish = true;
                                                            break;
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    bPublish = true;
                                                }
                                            }
                                            else
                                            {
                                                bPublish = true;
                                            }

                                            if (bPublish == true)
                                            {
                                                try
                                                {
                                                    string strMessage = string.Format(System.Globalization.CultureInfo.CurrentCulture, "Item '{0}' Target '{1}' Language '{2}': Automated Publisher Schedule Item '{3}'", itemToPublish.ID.ToString(), publishingTarget.Name, language.Name, schedule.Name);
                                                    Log.Info(strMessage, this);
                                                }
                                                catch
                                                {
                                                    Log.Error(Constants.ErrorFormattingString, this);
                                                }

                                                PublishOptions publishOptions = new PublishOptions(master, targetDb, PublishMode.Full, language, dtPublishDate);
                                                publishOptions.Deep     = true;
                                                publishOptions.RootItem = itemToPublish;

                                                Publisher publisher = new Publisher(publishOptions);
                                                publisher.Publish();
                                            }
                                            else
                                            {
                                                string strMessage = string.Format(System.Globalization.CultureInfo.CurrentCulture, "Item '{0}' Target '{1}' Language '{2}': No publishing targets were selected in Automated Publisher",
                                                                                  itemToPublish.ID.ToString(), publishingTarget.Name, language.Name);
                                                Log.Error(strMessage, this);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    schedule.Remove();
                }
                catch (Exception ex)
                {
                    Log.Error("Error Publishing in Automated Publisher", ex, this);
                }
            }
        }
Exemplo n.º 3
0
 public void Execute(Item[] items, Tasks.CommandItem command, Tasks.ScheduleItem schedule)
 {
     _hashTagManager.ProcessAllHashTags();
 }