Thursday, October 27, 2022

Sitecore - Docker installation prerequisites

 1. Make sure virtualization is enabled in the task manager, it is required for Hyper-V installation. 



2. Make sure you have the following windows features installed


3. Download the latest version of Docker for Windows 

https://desktop.docker.com/win/main/amd64/Docker%20Desktop%20Installer.exe


4. Start Docker for Windows and switch to Windows Containers and the docker service is started.



5. On success, you should see docker engine has started



6. Network Requirement:

Before you deploy the Sitecore containers you must ensure that the following required TCP ports are

available:

Required Port
Role
Description
443TraefikHTTPS Proxy
8079TraefikTraefik dashboard
8984SolrSolr API and dashboard
14330SQLSQL Server

Import records from CSV file and create items in Sitecore using PowerShell script

 How to import data from CSV and create the items in Sitecore?

This PowerShell script will help you to migrate the data from the CSV file to Sitecore.

Also, it helps to organize the items in the Year/Month/Week folders.


$defaultProps = @{

    "Title" = "Data Import Wizard"

    "Icon" = "/XXX.png"

    "ShowHints" = $true

}


$uploadDirectory = Join-Path -Path $SitecoreDataFolder -ChildPath "temp"

$importFilePath = Receive-File -Overwrite -Title $defaultProps.Title -Description "Choose a valid CSV file to import." -Icon $defaultProps.Icon -Path $uploadDirectory -OkButtonName "Next"

$importData = Import-CSV $importFilePath

$importedArticlesFolder = "/sitecore/content/*folder name*"

$AuthorPath = "master:/sitecore/content/*Author path*"

$ArticleFolderTempl="/sitecore/templates/*folder template*"


$templateItem = Get-Item -Path "master:" -ID "{template id}" -ErrorAction SilentlyContinue


foreach ($row in $importData) {

    $itemName = $row.name

    $newItemName = [Sitecore.Data.Items.ItemUtil]::ProposeValidItemName($itemName.Replace(" ","-"))

    $itemPath = "$($importedArticlesFolder)/$($newItemName)"

    $publishedon=$row.publishedon;

    <#

    $date =$publishedon.Split("-")

    $year= $date[0] # extract year.

    $month= $date[1]  #extract month

    #>

    $startTime = Get-Date $publishedon

    $year=$startTime.Year  #extract year

    $month = (Get-Culture).DateTimeFormat.GetMonthName($startTime.month) #extract month

    $week=[Math]::Floor($($startTime.Day / 7))+1; #extract week


  $yearFolderPath = "$($importedArticlesFolder)/$($year)"

$monthFolderPath = "$($yearFolderPath)/$($month)"

$weekFolderPath = "$($monthFolderPath)/$($week)"

$currentItemYear = Get-Item -Path $yearFolderPath -ErrorAction SilentlyContinue #Get the sitecore Item

$currentItemMonth = Get-Item -Path $monthFolderPath -ErrorAction SilentlyContinue #Get the sitecore Item

$currentItemWeek = Get-Item -Path $weekFolderPath -ErrorAction SilentlyContinue #Get the sitecore Item

if($currentItemYear -eq  $null)

{

    # create Year folder in content tree

     $itemYear = New-Item -Path $yearFolderPath -ItemType $ArticleFolderTempl        

}

if($currentItemMonth -eq  $null)

{

    # create month folder within year folder in content tree

     $itemMonth = New-Item -Path $monthFolderPath -ItemType $ArticleFolderTempl 

}

if($currentItemWeek -eq  $null)

{

    # create month folder within month folder in content tree

     $itemMonth = New-Item -Path $weekFolderPath -ItemType $ArticleFolderTempl 

}

<#  $item = New-Item -Path $itemPath -ItemType $templateItem.ID #>

$newItemPath="$($weekFolderPath)/$($newItemName)"

$item = New-Item -Path $newItemPath -ItemType $templateItem.ID  

    

    if ($item) {

        $item.Editing.BeginEdit()

        $authorName= $row.author

        if($authorName)

        {

            #TBD- write seperate funtion to update multilist field in item

          $authorlist=$authorName.Split(",");

          $authorGuids="";

          for($i=0 ; $i -lt $authorlist.Length; $i++) { 

             $authorName=$authorlist[$i] ;

             $authorItem=Get-Item -Path $AuthorPath/$authorName -ErrorAction SilentlyContinue

           if (![string]::IsNullOrEmpty($authorGuids)) {

                  $authorGuids+="|"

        }

            $authorGuids+= $authorItem.ID.ToString();      

        }

        $item["Authors"]=$authorGuids;

        }

        

        $item["Title"]= $itemName;

        $publishDate = ([sitecore.dateutil]::ToIsoDate($publishedon))

       # $item["Authors"] = $authorItem.ID;

        $item["BannerDate"]= $publishDate;

        $item["ShortDescription"]= $itemName; 

        $item["Content"] = $row.content

        $item.Editing.EndEdit() | Out-Null

        Write-Host "$($item.Paths.FullPath) is created" -ForegroundColor Green

    }

    else {

        Write-Host "Couldn't find: $($itemPath)"  -ForegroundColor Red

    }

}

Write-Host "Data Import is done." -ForegroundColor Green

<#

$allItem = Get-ChildItem -Path $AuthorPath -Recurse | where-object 

{$_.Fields["First Name"].Value -eq "Alastair"}

Write-Host "$allItem" 

#>


function SplitArray($str,$separator){

   $Array =$str.Split($separator)

    return $Array;

}


Function UpdateMultilist($item, $path, $fieldName){

$item.Editing.BeginEdit() 

# $allItems = Get-ChildItem -Path '/sitecore/content/ListManagerTask' -Recurse


 $authorItem=Get-Item -Path $AuthorPath/$authorName -ErrorAction SilentlyContinue

$allItems = Get-ChildItem -Path $path -Recurse


foreach($multilistItem in $allItems) { 

    if (![string]::IsNullOrEmpty($item[$templateField.Authors])) {

        $item[$templateField.Authors] += "|";

    }

    $item[$templateField.Authors] += $multilistItem.ID.ToString()


$item.Editing.EndEdit() | Out-Null

    

}


Monday, October 10, 2022

Upload .exe files in Sitecore Content Hub

Upload .exe files in Sitecore Content Hub:

 

By default Sitecore content hub won't support .exe file type.

The supported asset media types in Sitecore DAM - https://docs.stylelabs.com/contenthub/4.2.x/content/user-documentation/manage-digital-assets/asset-types/asset-types.html


Follow the steps to allow/upload the .exe files in Content Hub:


1. Go to Manage -> Pages -> Create -> select 'Creation' component from right pane


2. Select the 'Upload files' option and remove .exe from the Allowed extensions field:



3. Go to create page and try to upload .exe file.

How to Create a Public Link Using the Sitecore Content Hub REST API

Creating a public link using the Sitecore Content Hub REST API is a straightforward process that enables you to share content externally whi...