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, 8 January 2019

How to Manage Desktop Shortcuts in Sitecore CMS

Creating a Shortcut

To create a shortcut, right-click on the desktop and select “Create Shortcut”.
In the “Link” section that opens, click the “Browse” button.
This will open the “Insert Item”.
Select the desired item in the content tree and click the “Insert” button to return to the “Link” section.
Be sure to give the shortcut a name (HomeData), and custom icon to make it recognizable.
When finished, click “OK” to create the new shortcut.

Editing a Shortcut

To edit an existing shortcut, right click on the shortcut and select “Properties”.
This will reopen the “Link” modal.
Make any necessary changes to the shortcut and click “OK” when finished.
For Example, name: HomeContent.

Deleting a Shortcut

To delete an existing shortcut, right click on the shortcut and select “Remove Shortcut”.

A confirmation dialogue will appear. Click “OK” to delete the shortcut.

Desktop image change.

Scenario 1: 
Right-click on the desktop and select "Properties".
Select Background which is you want and clicks on the "Apply" button.
Scenario 2 :
Go to control panel and click on "Change desktop background" in  "MY SETTINGS" section.
Select Background which is you want and clicks on the "Apply" button.




Saturday, 22 December 2018

Redirecting HTTP to HTTPS on IIS


It can be beneficial for security and SEO reasons to secure an entire website, rather than pages were there are login forms and other private data. The myths around performance hits have been debunked, and the main potential downside is around third-party ad networks (and many sites don't display ads like this anyway).

To achieve redirection from non-secure to secure URLs on an IIS website, the URL Rewrite Module will need to be installed on the server. Then the following XML will need to be added into the web.config (site root) inside the system.web server section.

<rewrite>
    <rules>
      <rule name="HTTP to HTTPS redirect" stopProcessing="true">
        <match url="(.*)" />
        <conditions>
          <add input="{HTTPS}" pattern="off" ignoreCase="true" />
        </conditions>
        <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
      </rule>
    </rules>
</rewrite>

Sitecore Event Queue – How to clean it


STEP 1: CLEAN OUT EVENT QUEUE, HISTORY TABLE, PUBLISH QUEUE

The following SQL statement will clean out the history table, publish queue and event queue, leaving only 12 hours of history and publish data and 4 hours of events. Replace YOURDATABASE with the name of your database:

/****** History ******/
delete FROM [YOURDATABASE_Core].[dbo].[History] where Created < DATEADD(HOUR, -12, GETDATE())
delete FROM [YOURDATABASE_Master].[dbo].[History] where Created < DATEADD(HOUR, -12, GETDATE())
delete FROM [YOURDATABASE_Web].[dbo].[History] where Created < DATEADD(HOUR, -12, GETDATE())
  
/****** Publishqueue ******/
delete FROM [YOURDATABASE_Core].[dbo].[PublishQueue] where Date < DATEADD(HOUR, -12, GETDATE());    
delete FROM [YOURDATABASE_Master].[dbo].[PublishQueue] where Date < DATEADD(HOUR, -12, GETDATE());
delete FROM [YOURDATABASE_Web].[dbo].[PublishQueue] where Date < DATEADD(HOUR, -12, GETDATE());
     
/****** EventQueue ******/
delete FROM [YOURDATABASE_Master].[dbo].[EventQueue] where [Created] < DATEADD(HOUR, -4, GETDATE())
delete FROM [YOURDATABASE_Core].[dbo].[EventQueue] where [Created] < DATEADD(HOUR, -4, GETDATE())
delete FROM [YOURDATABASE_Web].[dbo].[EventQueue] where [Created] < DATEADD(HOUR, -4, GETDATE())


STEP 2: CONFIGURE THE SYSTEM TO CLEAN THE TABLES MORE OFTEN

With the system stabilized, we need to take more care of the table sizes.

HISTORY TABLE:

Sitecore is already configured to clean the tables so they only contain 12 hours of data. 
12 hours of data is usually what any SQL server will handle, and you will have up to 10.000 rows in the table.

<Engines.HistoryEngine.Storage>
  <obj type="Sitecore.Data.$(database).$(database)HistoryStorage, Sitecore.Kernel">
    <param connectionStringName="$(id)" />
    <EntryLifeTime>00.12:00:00</EntryLifeTime>
  </obj>
</Engines.HistoryEngine.Storage>


PUBLISH QUEUE:

Sitecore keeps 30 days of publishing queue. If you insert and update items often, you should lower this number. For each item change (including any change that the system does) is stored here.

<agent type="Sitecore.Tasks.CleanupPublishQueue, Sitecore.Kernel" method="Run" interval="04:00:00">
  <DaysToKeep>2</DaysToKeep>
</agent>


EVENT QUEUE:

The event queue is the most important table to keep small. In a distributed environment, each server will read the contents of the table every 5 seconds, using a time stamp stored in the If you can keep the number of rows below 7.000, most SQL server should be able to handle that amount of data. Even smaller numbers are preferred as well. Properties table as key. Any row before the timestamp will not be read.

You, therefore, need enough history to cater that a server will be offline for a while, but at the same time so little contents that any read and write will be amazingly fast.


Before Sitecore 8.1, Sitecore would only allow you to clean events older that 1 day. This is way too much, especially if you publish often. The new IntervalToKeep will allow you to determine the hours to keep as well:

<agent type="Sitecore.Tasks.CleanupEventQueue, Sitecore.Kernel" method="Run" interval="04:00:00">
  <IntervalToKeep>04:00:00</IntervalToKeep>
  <DaysToKeep>1</DaysToKeep>
</agent>


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:


Sunday, 9 December 2018

IIS Restart Using Command Prompt



To restart IIS using the IISReset command-line utility

  • From the Start menu, click Run.
  • In the Open box, type cmd, and click OK.
  • At the command prompt, type

    iisreset /noforce and press ENTER.


  • IIS attempts to stop all services before restarting. The IISReset command-line utility waits up to one minute for all services to stop. If the services cannot be stopped within one minute, all IIS services are terminated, and IIS restarts.

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....