Skip to content

Commit

Permalink
added sitecoreSiteName for correct URL generation
Browse files Browse the repository at this point in the history
  • Loading branch information
diger74 committed Apr 5, 2024
1 parent 6eb2ee0 commit 4e70364
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ Follow the steps below to install the Universal Migration Toolkit for Sitecore:
<tr>
<td>UMT.ExportMediaAsUrls.ServerUrl</td>
<td>This setting allows overriding the hostname for generated media URLs when using the option <code>UMT.ExportMediaAsUrls</code>. Leave it empty to use the current Sitecore instance settings.</td>
<td>The default value is <code>empty</code></td>
<td>The default value is <code>https://legacysite/</code></td>
</tr>
<tr>
<td>UMT.ExportMediaAsUrls.SiteName</td>
<td>This setting specifies the Sitecore site name for generating media URLs when using the option <code>UMT.ExportMediaAsUrls</code>.</td>
<td>The default value is <code>LegacySite</code></td>
</tr>
<tr>
<td>UMT.MaxFilePathLength</td>
Expand All @@ -141,7 +146,7 @@ Follow the steps below to install the Universal Migration Toolkit for Sitecore:
<tr>
<td>UMT.MediaLocationForJson</td>
<td>Relative or absolute folder path that will be used for files in the generated JSON when <code>UMT.ExportMediaAsUrls</code> is set to <code>false</code>. Leave it empty to use the automatically generated absolute path of exported files.</td>
<td>The default value is <code>.\Files</code></td>
<td>The default value is <code>..\Import\Files</code></td>
</tr>
<tr>
<td>UMT.RichTextMediaLinkFormat</td>
Expand All @@ -162,7 +167,7 @@ Follow the steps below to install the Universal Migration Toolkit for Sitecore:
<tr>
<td rowspan="9"><code>&lt;umt&gt;</code></td>
<td><code>&lt;channelMapping&gt;</code></td>
<td>List of channels that will be available for selection when running an export. Each channel has a list of attributes corresponding to <a href="https://docs.xperience.io/xp/developers-and-admins/configuration/website-channel-management" target="_blank">channel fields in Xperience by Kentico</a>. If a channel does not exist, it will be created automatically when importing data into Xperience by Kentico. Channel ID and website ID are defined in the config so that subsequent exports and imports refer to the same channels within Xperience by Kentico.</td>
<td>List of channels that will be available for selection when running an export. Each channel has a list of attributes corresponding to <a href="https://docs.xperience.io/xp/developers-and-admins/configuration/website-channel-management" target="_blank">channel fields in Xperience by Kentico</a>. If a channel does not exist, it will be created automatically when importing data into Xperience by Kentico. Channel ID and website ID are defined in the config so that subsequent exports and imports refer to the same channels within Xperience by Kentico. The attribute <code>sitecoreSiteName</code> is required for correct generation of relative page URLs.</td>
<td>You must have at least one channel as it will be used for linking content types and content items to it.</td>
</tr>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion UMT.Sitecore/App_Config/Include/UMT/UMT.Sitecore.config
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<channels hint="raw:AddChannel">
<channel name="umt_website" displayName="UMT website" channelType="0" id="543b20a9-d5ae-434e-bf0d-368a2779343d"
websiteId="48960b59-37eb-4a0c-afdc-fc4c301e44c3" domain="localhost:50972" homePage="" language="be94cd89-054c-4e29-94ed-e786d1095e42"
defaultCookieLevel="1000" storeFormerUrls="false" />
defaultCookieLevel="1000" storeFormerUrls="false" sitecoreSiteName="LegacySite" />
</channels>
</channelMapping>
<languageMapping type="UMT.Sitecore.Configuration.LanguageMapping, UMT.Sitecore">
Expand Down
3 changes: 3 additions & 0 deletions UMT.Sitecore/Configuration/ChannelMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public void AddChannel(XmlNode node)
var name = XmlUtil.GetAttribute("name", node);
var displayName = XmlUtil.GetAttribute("displayName", node);
int.TryParse(XmlUtil.GetAttribute("channelType", node), out int channelType);
var sitecoreSiteName = XmlUtil.GetAttribute("sitecoreSiteName", node);
Guid.TryParse(XmlUtil.GetAttribute("websiteId", node), out var websiteId);
var domain = XmlUtil.GetAttribute("domain", node);
var homePage = XmlUtil.GetAttribute("homePage", node);
Expand All @@ -33,6 +34,7 @@ public void AddChannel(XmlNode node)
Name = name,
DisplayName = displayName,
ChannelType = channelType,
SitecoreSiteName = sitecoreSiteName,
WebsiteId = websiteId,
Domain = domain,
HomePage = homePage,
Expand All @@ -51,6 +53,7 @@ public class ChannelMap
public string Name { get; set; }
public Guid Id { get; set; }
public int ChannelType { get; set; }
public string SitecoreSiteName { get; set; }

//properties required for WebsiteChannel model
public Guid WebsiteId { get; set; }
Expand Down
10 changes: 9 additions & 1 deletion UMT.Sitecore/Pipelines/ExtractContent/SaveItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,15 @@ protected virtual TargetItem MapToTargetItem(Item item, string contentPath, int

if (!isContentHubItem && item.HasPresentationDetails())
{
var url = LinkManager.GetItemUrl(item, new UrlOptions { AlwaysIncludeServerUrl = false, Language = language }).TrimStart('/');
var siteContext = Factory.GetSite(channel.SitecoreSiteName);
var url = LinkManager.GetItemUrl(item,
new UrlOptions
{
AlwaysIncludeServerUrl = false,
Language = language,
Site = siteContext
})
.TrimStart('/');
if (duplicateIndex > 0)
{
url = $"{url}{duplicateIndex}";
Expand Down

0 comments on commit 4e70364

Please sign in to comment.