I wanted to share some insights on creating a custom publishing target in Sitecore (refer to Screenshot 3), specifically focusing on the creation of a custom publishing target database and related configurations such as patch and connection string.
Creating a custom database publishing target in Sitecore involves several steps, including creating a new database, setting up a publishing target, and configuring Sitecore to recognize and use this new target. Here is a step-by-step guide:
STEPs:
Step 1: Add Publishing Target in Sitecore
- Open Sitecore Content Editor.
- Navigate to
/sitecore/system/Publishing targets
. - Create a new Publishing Target:
- Right-click on
Publishing targets
. - Select
Insert -> Publishing target
. - Enter the name p
review
for your publishing target. - Configure the Publishing Target:
- Select the new
Preview
publishing target item. - In the
Data
section, set theTarget database
field topreview
.
Screenhot 1:
Step 2: Create Database by Copying Web Database
- Open SQL Server Management Studio (SSMS).
- Copy the Web Database:
- Right-click on the
Web
database. - Select
Tasks -> Copy Database...
. - Follow the wizard to create a new database. In my case I named it with sitecoredb_Preview
Step 3: Add New Connection String
- Open the
ConnectionStrings.config
file in your Sitecore instance (usually located in theApp_Config
folder). - Add the connection string for the new database (Copy connection string of web database and rename a value of name attribute as "preview" and update database and credentials ).
Example:<connectionStrings> <add name="preview" connectionString="Data Source=(local);Initial Catalog=sitecoredb_Preview;User ID=sa;Password=SQLSERVER_PASSWORD" /> </connectionStrings>
Step 4: Add Patch Config in Include Folder
- Create a new patch file in the
App_Config\Include
folder. - Name the patch file
ZZZ.
sitecoredb_Preview.config
. - Add the following XML content to the patch file to include the new database and update the value of attribute name and id of each as preview (three places). In the XML code given below we have alrady added value as preview:<?xml version="1.0" encoding="utf-8" ?><configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"><sitecore><eventing defaultProvider="sitecore"><eventQueueProvider><eventQueue name="preview" 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><store name="preview" patch:after="store[@name='web']" prefix="web_secondary" 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><!-- web_secondary --><database id="preview" 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 type="Sitecore.Data.DataProviders.CompositeDataProvider, Sitecore.Kernel"><param desc="readOnlyDataProviders" hint="list"><protobufItems type="Sitecore.Data.DataProviders.ReadOnly.Protobuf.ProtobufDataProvider, Sitecore.Kernel"><filePaths hint="list"><filePath>$(dataFolder)/items/$(id)</filePath><modulesFilePath>/sitecore modules/items/$(id)</modulesFilePath></filePaths></protobufItems></param><param desc="headProvider"><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></param></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><BlobStorage hint="raw:AddBlobStorage"><providers default="classic"><provider name="classic" type="Sitecore.Data.Blobs.ClassicSqlBlobProvider, Sitecore.Kernel"><param desc="databaseName">$(id)</param></provider></providers></BlobStorage></database></databases></sitecore></configuration>
Step 5: Copy Web and Rename as preview
- Navigate to the
App_Data\items
folder in your Sitecore instance. - Copy the w
eb
folder and rename the copied folder to preview
. - Inside preview folder rename the file from items.web.dat to items.preview.dat
Screenshot 2:
Step 6: Restart IIS/Application Pool
Final Steps: Test and Verify
- Open Sitecore Content Editor.
- Publish content to the new
Preview
publishing target to ensure everything is configured correctly: - Select an item to publish.
- Click
Publish -> Publish
Item. - Choose the p
review
publishing target and complete the publishing process.
Screenshot 3:
- Verify the Published Content:
- Check the new sitecoredb_Preview database in SQL Server or from Desktop in Sitecore to ensure the content is being published correctly.
- Access the content on your site through the configured target URL (if applicable).
By following these detailed steps, you should have a custom database publishing target set up and working in Sitecore.
No comments