Showing posts with label Publish Item. Show all posts
Showing posts with label Publish Item. Show all posts

Wednesday, 17 April 2019

Add Publishing Targets in Sitecore 9.1


You are usually adding new publishing targets in Sitecore because of different geographic regions or databases in different data centers where you are hosting these web databases.

For a long time, for Sitecore 8, the process for creating a new publishing target was more or less the same. You have created a new entry in ConnectionStrings.config, added new <database> entry in web.config and added new definition item in master database under “/sitecore/system/Publishing targets” node.


In Sitecore 9 process has been slightly changed. You are not changing web.config anymore but Sitecore.config and 2 additional steps are now involved for adding a new publishing target. These two more steps are adding <eventQueue> and </PropertyStoreProvider> elements in Sitecore.config.

In my example below, I will use “Pub” as the name of the publishing target database. I will use “QA” as the name of the publishing target. In my example below, I will use “Pub” as the name of the publishing target database. I will use “QA” as the name of publishing target.

Steps to add new publishing target in Sitecore 9:Steps to add new publishing target in Sitecore 9:

  1. Create new target database in ConnectionStrings.config where you want content to be published:

    <add name="Pub" connectionString="Data Source=.\;Initial Catalog=webdbname;User ID=pubuser;Password=Password" />
  2. Add new entry in master database under “/sitecore/system/Publishing targets” node.



  3. Create a patch file under C:\inetpub\wwwroot\instancename\App_Config\Include\Project\ or any other folder based on your setup. I have named my patch config file “PublishingTargets.config” and this is it’s content (you can just copy it and change web_secondary based on name of your secondary web database specified in ConnectionStrings.config):



<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
     <sitecore>
         <eventing defaultProvider="sitecore">
            <eventQueueProvider defaultEventQueue="core">
                <eventQueue name="Pub" patch:after="eventQueue[@name='web']" type="Sitecore.Data.Eventing.$(database)EventQueue, Sitecore.Kernel">
                     <param ref="dataApis/dataApi[@name='$(database)']" param1="$(name)" />
                     <param hint="" ref="PropertyStoreProvider/store[@name='$(name)']" />
                </eventQueue>
            </eventQueueProvider>
         </eventing>
         <PropertyStoreProvider defaultStore="core">
             <store name="Pub" patch:after="store[@name='web']" prefix="Pub" getValueWithoutPrefix="true" singleInstance="true" type="Sitecore.Data.Properties.$(database)PropertyStore, Sitecore.Kernel">
                  <param ref="dataApis/dataApi[@name='$(database)']" param1="$(name)" />
                  <param resolve="true" type="Sitecore.Abstractions.BaseEventManager, Sitecore.Kernel" />
                  <param resolve="true" type="Sitecore.Abstractions.BaseCacheManager, Sitecore.Kernel" />
             </store>
         </PropertyStoreProvider>
         <databases>
         <!-- Pub -->
             <database id="Pub" patch:after="database[@id='web']" singleInstance="true" type="Sitecore.Data.DefaultDatabase, Sitecore.Kernel">
                 <param desc="name">$(id)</param>
                 <icon>Images/database_web.png</icon>
                 <securityEnabled>true</securityEnabled>
                 <dataProviders hint="list:AddDataProvider">
                     <dataProvider ref="dataProviders/main" param1="$(id)">
                         <disableGroup>publishing</disableGroup>
                         <prefetch hint="raw:AddPrefetch">
                              <sc.include file="/App_Config/Prefetch/Common.config" />
                              <sc.include file="/App_Config/Prefetch/Webdb.config" />
                         </prefetch>
                     </dataProvider>
                 </dataProviders>
                <PropertyStore ref="PropertyStoreProvider/store[@name='$(id)']" />
                    <remoteEvents.EventQueue>
                        <obj ref="eventing/eventQueueProvider/eventQueue[@name='$(id)']" />
                    </remoteEvents.EventQueue>
                    <archives hint="raw:AddArchive">
                        <archive name="archive" />
                        <archive name="recyclebin" />
                    </archives>
                    <cacheSizes hint="setting">
                         <data>100MB</data>
                         <items>50MB</items>
                         <paths>2500KB</paths>
                         <itempaths>50MB</itempaths>
                         <standardValues>2500KB</standardValues>
                    </cacheSizes>
              </database>
         </databases>
     </sitecore>
</configuration>


After applying these changes, you can see now pretty new publishing target in publishing dialogue in Sitecore 9:






Thursday, 31 January 2019

Check SiteCore Items Publish or Not using GutterRender






What is Gutter in Sitecore?

Gutter also is known as a quick action bar, can be seen when you right click on the left bar of the content tree.

Sitecore provides default gutters to know the
  • Item buckets
  • Cloned Items
  • Personalizations
  • Multivariant Tests
  • My Locked Items
  • Locked items
  • Workflow state
  • Broken links
  • Missing Version
  • Publishing Warnings
  • Validation Rules
  • Presentation overridden

In addition to these default Gutters, we can create custom Sitecore Gutters.


Steps to Create Custom Sitecore Gutter

  1. Create a class which inherits the GutterRenderer.
  2. Override the GutterIconDescriptor method in the GutterRenderer class, to set the appropriate icons to the gutter.
  3. Switch to core database in Sitecore interface.
  4. Create Custom Gutter using the /Sitecore/templates/Sitecore Client/Content editor/Gutter Renderer.
  5. Populate the Header and Type fields of the Gutter, Header field should contain the name you want to give to the Gutter, Type field should contain the fully qualified class name, the dll which contains the class.


  6. Right click on the left side of the Content tree and select your Gutter. see below screen 


  7. The Gutter now indicates the publication status of your items


CUSTOM SITECORE GUTTER TO INDICATE PUBLISH STATUS

Never Published:
Check whether the item is present in the web database if not implies the item has never been published.

Published:
Compare the revision fields of the item in master and web databases, if found same implies that the latest revision has been published to the web.

Published to at least one target:
Check whether the item is present in any one target database if found implies the item has been published in at least on the target database.


Code & Implementation


namespace testforsitecore.Models


{

    public class PublicationStatus : GutterRenderer
    {
        private readonly ID publishingTargetsFolderId = new ID("{D9E44555-02A6-407A-B4FC-96B9026CAADD}");
        private readonly ID targetDatabaseFieldId = new ID("{39ECFD90-55D2-49D8-B513-99D15573DE41}");

        protected override GutterIconDescriptor GetIconDescriptor(Item item)
        {
            bool existsInAll = true;
            bool existsInOne = false;

            // Find the publishing targets item folder
            Item publishingTargetsFolder = Context.ContentDatabase.GetItem(publishingTargetsFolderId);

            if (publishingTargetsFolder == null)
            {
                return null;
            }

            // Retrieve the publishing targets database names
            List<string> publishingTargetsDatabases = publishingTargetsFolder.GetChildren()
              .Select(x => x[targetDatabaseFieldId])
              .ToList();

            // Check for item existance in publishing targets
            publishingTargetsDatabases.ForEach(delegate (string databaseName)
            {
                if (Database.GetDatabase(databaseName).GetItem(item.ID) != null)
                {
                    existsInOne = true;
                }
                else
                {
                    existsInAll = false;
                }
            });

            // Return descriptor with tooltip and icon
            string tooltip = Translate.Text("This item has not yet been published");
            string icon = "People/16x16/flag_red.png";

            if (existsInAll)
            {
                tooltip = Translate.Text("This item has been published to all targets");
                icon = "People/16x16/flag_green.png";
            }
            else if (existsInOne)
            {
                tooltip = Translate.Text("This item has been published to at least one target");
                icon = "People/16x16/flag_yellow.png";
            }

            return new GutterIconDescriptor()
            {
                Icon = icon,
                Tooltip = tooltip,
                //Click = string.Format("item:publish(id={0})", item.ID), // For Click on publish staus icon publish Item dialog box open
                Click = String.Format("item:load(ID={0})", item.ID)  // For Click on publish staus icon which Item is load
            };
        }
    }
  }

Conclusion:

Sitecore Gutters can be very useful since they visually indicate the state of an item which reduces the extra effort for developers. The above implementation of Sitecore Gutter to indicate the Publish Status of an item comes handy when there is no workflow configured for the items.


Wednesday, 30 January 2019

How to hide the "publish subitems" option in the publish dialog box.


When publishing the item given two option "Publish subitem" or "publish related items". When checkbox checked these option then publish item of the subitems or related items are published. If you want to hide these options then follow the below steps.

Hide the Publish SubItem option in the publish dialog box.





Steps:

  1. Copy Publish.xml file from "sitecore\shell\Applications\Dialogs\Publish" folder to "sitecore\shell\override" folder, so that you don’t mess up original file in case if you want to revert back your changes, just delete the newly copied file of "sitecore\shell\override" folder.
  2. Find XML code for control in Publish.xml file, something similar to below:

    <Border ID="PublishChildrenPane">
                  <br /><Checkbox ID="PublishChildren" Header="Publish subitems"/>
                   <br />
                   <Checkbox ID="PublishRelatedItems" Header="Publish related items"/>
     </Border>
  3. Add Visible = "False" attribute to border control like below: e.g.

              <Border ID="PublishChildrenPane" Visible = "False">
                         <br /><Checkbox ID="PublishChildren" Header="Publish subitems"/>
                          <br />
                           <Checkbox ID="PublishRelatedItems" Header="Publish related items"/>
              </Border>
  4. For default checked or unchecked you can add attribute IsChecked = "True" to the checkbox

    <Border ID="PublishChildrenPane" Visible = "False">
     <br />
    <Checkbox ID="PublishChildren" Header="Publish subitems" IsChecked = "True"/
       <br />
    <Checkbox ID="PublishRelatedItems" Header="Publish related items"/>
    </Border>
  5. Now you see the dilog box like this. No have to option to checked  "publish subitems"  or  "Publish related items".






Tuesday, 18 December 2018

Adding publish item to the contextual menu of Sitecore

Publish Operations and Messages.

This picture shows how each menu item is related to the corresponding message.



Customizing the Context Menu.

Switch to the Core Database and go to the "/Sitecore/content/Applications/Content Editor/Context Menues/Default" folder and create a new Menu item  (Template Path : /Sitecore/templates/System/Menus/Menu item). You can re-order existing menu items to your liking. For your new menu item, choose a display name (in my case, its "Publish Menu"), an icon and finally the message (in my case, I've used item: publish(id=$Target)). See the below image.



Now, to avoid disappointments, in the scenario where a user may think that they can publish, to later found out they can’t, we have to apply security:
  • A select item which is created right now (Ex: Publish menu)
  • Click on Security navigation Bar.
  • Click on the Assign inside security section and its open a popup.
  • Add role "Sitecore client Publishing" and "Sitecore client Users".
  • Click ok button.

All you now have to do is to switch back to the master base and view the result. Simple !!! :) You should get something like this:


Sitecore Publishing Service 7.0 Installation Guide

  About the Publishing Service module The Publishing Service module is an optional replacement for the existing Sitecore publishing methods....