diff --git a/Sdl.Web.Tridion.Templates/Common/TemplateBase.cs b/Sdl.Web.Tridion.Templates/Common/TemplateBase.cs index 9e0dc4d..7cfcdca 100644 --- a/Sdl.Web.Tridion.Templates/Common/TemplateBase.cs +++ b/Sdl.Web.Tridion.Templates/Common/TemplateBase.cs @@ -31,6 +31,7 @@ public abstract class TemplateBase : ITemplate "]*>", RegexOptions.Compiled); private TemplatingLogger _logger; + private InternalLogger _internalLogger; private Session _session; private Engine _engine; private Package _package; @@ -74,7 +75,17 @@ protected Package Package /// protected Publication Publication { - get { return _publication ?? (_publication = GetPublication()); } + get + { + if (_publication == null) + { + InternalLogger.Debug("Getting publication..."); + _publication = GetPublication(); + InternalLogger.Debug($" Found publication id='{_publication.Id}', title='{Publication.Title}', webDavUrl='{Publication.WebDavUrl}'"); + } + + return _publication; + } set { // Allows dependency injection for unit test purposes. @@ -87,7 +98,26 @@ protected Publication Publication /// protected Session Session { - get { return _session ?? (_session = Engine.GetSession()); } + get + { + if (_session == null) + { + InternalLogger.Debug("Getting session from Engine.."); + _session = Engine.GetSession(); + + if (_session == null) + { + InternalLogger.Debug(" strange, session was null!"); + } + else + { + InternalLogger.Debug("Session details:"); + InternalLogger.Debug($" webDavUrl prefix : {_session.WebDavUrlPrefix}"); + } + } + + return _session; + } set { // Allows dependency injection for unit test purposes. @@ -100,6 +130,10 @@ protected Session Session /// protected TemplatingLogger Logger => _logger ?? (_logger = TemplatingLogger.GetLogger(GetType())); + protected InternalLogger InternalLogger => _internalLogger ?? + (_internalLogger = + new InternalLogger(TemplatingLogger.GetLogger(GetType()))); + /// /// Attempts to return value of a parameter /// diff --git a/Sdl.Web.Tridion.Templates/Log.cs b/Sdl.Web.Tridion.Templates/Log.cs new file mode 100644 index 0000000..8585007 --- /dev/null +++ b/Sdl.Web.Tridion.Templates/Log.cs @@ -0,0 +1,42 @@ +using System; +using System.IO; +using Tridion.ContentManager.Templating; + +namespace Sdl.Web.Tridion +{ + public class InternalLogger + { + private readonly TemplatingLogger _log; + private readonly string _logFile = null; + + public InternalLogger(TemplatingLogger log) + { + _log = log; + try + { + _logFile = Environment.GetEnvironmentVariable("DXA_LOGGING"); + } + catch + { + // invalid so ignore + } + } + + public void Debug(string msg) + { + try + { + _log?.Debug(msg); + if (string.IsNullOrEmpty(_logFile)) return; + using (var sw = File.AppendText(_logFile)) + { + sw.WriteLine(msg); + } + } + catch + { + // ignore + } + } + } +} diff --git a/Sdl.Web.Tridion.Templates/Sdl.Web.Tridion.Templates.csproj b/Sdl.Web.Tridion.Templates/Sdl.Web.Tridion.Templates.csproj index fdaaa2d..9cd4271 100644 --- a/Sdl.Web.Tridion.Templates/Sdl.Web.Tridion.Templates.csproj +++ b/Sdl.Web.Tridion.Templates/Sdl.Web.Tridion.Templates.csproj @@ -1,6 +1,5 @@  - Debug AnyCPU @@ -95,6 +94,7 @@ + diff --git a/Sdl.Web.Tridion.Templates/Templates/PublishMappings.cs b/Sdl.Web.Tridion.Templates/Templates/PublishMappings.cs index b0d0a76..031e5ea 100644 --- a/Sdl.Web.Tridion.Templates/Templates/PublishMappings.cs +++ b/Sdl.Web.Tridion.Templates/Templates/PublishMappings.cs @@ -61,6 +61,7 @@ public class PublishMappings : TemplateBase public PublishMappings() { + InternalLogger.Debug("PublishMappings TBB constructed"); foreach (KeyValuePair ns in _namespaces) { _namespaceManager.AddNamespace(ns.Key, ns.Value); @@ -69,6 +70,7 @@ public PublishMappings() public override void Transform(Engine engine, Package package) { + InternalLogger.Debug("Transform called"); Initialize(engine, package); package.TryGetParameter("retrofitMode", out _retrofitMode, Logger); @@ -88,6 +90,7 @@ public override void Transform(Engine engine, Package package) AddBootstrapJsonBinary(binaries, inputComponent, mappingsStructureGroup, "mapping"); OutputSummary("Publish Mappings", binaries.Select(b => b?.Url)); + InternalLogger.Debug("Transform completed"); } private Binary PublishSemanticVocabularies(StructureGroup structureGroup, Component relatedComponent) @@ -271,6 +274,7 @@ private Binary PublishXpmRegionConfiguration(StructureGroup structureGroup, Comp private Binary PublishPageIncludes(StructureGroup structureGroup, Component relatedComponent) { + InternalLogger.Debug($"PublishPageIncludes(structureGroup='{structureGroup.Title}, {structureGroup.Id}', relatedComponent='{relatedComponent.Title}, {relatedComponent.Id}')"); IDictionary pageIncludes = new Dictionary(); RepositoryItemsFilter pageTemplatesFilter = new RepositoryItemsFilter(Session) @@ -278,11 +282,20 @@ private Binary PublishPageIncludes(StructureGroup structureGroup, Component rela ItemTypes = new[] { ItemType.PageTemplate }, Recursive = true }; - + InternalLogger.Debug("Getting all page templates from publication..."); IEnumerable pageTemplates = Publication.GetItems(pageTemplatesFilter).Cast(); + InternalLogger.Debug($"Found {pageTemplates.Count()} page templates... Checking page template metadata if it exists..."); foreach (PageTemplate pt in pageTemplates.Where(pt => pt.MetadataSchema != null && pt.Metadata != null)) { + InternalLogger.Debug($" page template '{pt.Title}' with id '{pt.Id}' contains metadata with metadata schema '{pt.MetadataSchema.Title}', id = '{pt.MetadataSchema.Id}'..."); ItemFields ptMetadataFields = new ItemFields(pt.Metadata, pt.MetadataSchema); + + InternalLogger.Debug($"Looking for metadata field values with fieldname 'includes'.."); + var includeFields = ptMetadataFields.GetTextValues("includes"); + foreach (var includeField in includeFields) + { + InternalLogger.Debug($"Found include with value = {includeField} !"); + } string[] includes = ptMetadataFields.GetTextValues("includes").Select(id => GetPublishPath(id)).ToArray(); pageIncludes.Add(pt.Id.ItemId.ToString(), includes); } @@ -292,17 +305,30 @@ private Binary PublishPageIncludes(StructureGroup structureGroup, Component rela private string GetPublishPath(string pageId) { - string result; - if (TcmUri.IsValid(pageId) || pageId.StartsWith("/webdav/")) + try { - Page page = (Page)Session.GetObject(pageId); - result = page.PublishLocationUrl.Substring(1); + InternalLogger.Debug($"GetPublishPath(pageId = {pageId}) called"); + string result; + if (TcmUri.IsValid(pageId) || pageId.StartsWith("/webdav/", StringComparison.InvariantCultureIgnoreCase)) + { + InternalLogger.Debug(" PageId is a valid tcm uri or begins with /webdav/ -- attempting to get page object from session"); + Page page = (Page) Session.GetObject(pageId); + result = page.PublishLocationUrl.Substring(1); + InternalLogger.Debug($" Page object from session = {result}"); + } + else + { + InternalLogger.Debug($" Using pageId '{pageId}'"); + result = pageId; + } + return result; } - else + catch { - result = pageId; + InternalLogger.Debug($" Using pageId '{pageId}'"); } - return result; + + return pageId; } private SemanticSchemaData GetSemanticSchema(Schema schema) diff --git a/cms/content/sites9/all-publications/Binaries/2-70-2048.tbbasm b/cms/content/sites9/all-publications/Binaries/2-70-2048.tbbasm index 96b3ea3..e1da875 100644 Binary files a/cms/content/sites9/all-publications/Binaries/2-70-2048.tbbasm and b/cms/content/sites9/all-publications/Binaries/2-70-2048.tbbasm differ diff --git a/cms/content/sites9/all-publications/Binaries/2-80-2048.tbbasm b/cms/content/sites9/all-publications/Binaries/2-80-2048.tbbasm index 005f3a1..d39e851 100644 Binary files a/cms/content/sites9/all-publications/Binaries/2-80-2048.tbbasm and b/cms/content/sites9/all-publications/Binaries/2-80-2048.tbbasm differ diff --git a/cms/content/sites9/framework-only/Binaries/2-70-2048.tbbasm b/cms/content/sites9/framework-only/Binaries/2-70-2048.tbbasm index 96b3ea3..e1da875 100644 Binary files a/cms/content/sites9/framework-only/Binaries/2-70-2048.tbbasm and b/cms/content/sites9/framework-only/Binaries/2-70-2048.tbbasm differ diff --git a/cms/content/sites9/framework-only/Binaries/2-80-2048.tbbasm b/cms/content/sites9/framework-only/Binaries/2-80-2048.tbbasm index 005f3a1..d39e851 100644 Binary files a/cms/content/sites9/framework-only/Binaries/2-80-2048.tbbasm and b/cms/content/sites9/framework-only/Binaries/2-80-2048.tbbasm differ diff --git a/cms/content/sites9/master-only/Binaries/2-70-2048.tbbasm b/cms/content/sites9/master-only/Binaries/2-70-2048.tbbasm index 96b3ea3..e1da875 100644 Binary files a/cms/content/sites9/master-only/Binaries/2-70-2048.tbbasm and b/cms/content/sites9/master-only/Binaries/2-70-2048.tbbasm differ diff --git a/cms/content/sites9/master-only/Binaries/2-80-2048.tbbasm b/cms/content/sites9/master-only/Binaries/2-80-2048.tbbasm index 005f3a1..d39e851 100644 Binary files a/cms/content/sites9/master-only/Binaries/2-80-2048.tbbasm and b/cms/content/sites9/master-only/Binaries/2-80-2048.tbbasm differ