How do I manually add a file to Umbraco Cloud's re...
# help-with-umbraco
c
We're using a builder package for some sites, where the main stylesheet gets generated by publishing a node. The problem is that this file is never committed to the Cloud repo, so when the site is upgraded (by e.g. by Cloud) and there's a new deploy, the stylesheet reverts to an old version of the file (the first one that was committed, I guess?). Is it possible to tap into a process similar to when a doctype is changed, and have Umbraco commit the generated file to the repository?
n
Rather than commiting it, if it's a known doctype. Could you hook into the starting up events/notifications and then look for instances of that doctype and re publish them to re-trigger the style sheet generation?
s
In relation to @Chriztian Steinmeier 's question I'm trying to do something like @Nik suggested. But I'm running into some challenges with the Content cache being empty (
Content Cache is null
). My code looks like this:
Copy code
public class PublishDesigns : INotificationHandler<UmbracoApplicationStartedNotification>
{
    private readonly IContentService _contentService;
    private readonly ILogger<PublishDesigns> _logger;
    private readonly IUmbracoContextAccessor _context;

    public PublishDesigns(IContentService contentService, ILogger<PublishDesigns> logger, IUmbracoContextAccessor context)
    {
        _contentService = contentService ?? throw new ArgumentNullException(nameof(contentService));
        _logger = logger ?? throw new ArgumentNullException(nameof(logger));
        _context = context ?? throw new ArgumentNullException(nameof(context));
    }

    public void Handle(UmbracoApplicationStartedNotification notification)
    {
        if (_context.TryGetUmbracoContext(out IUmbracoContext? context) == false)
        {
            _logger.LogInformation("unable to get content");
        }

        if (context == null || context.Content == null)
        {
            _logger.LogInformation("Content Cache is null");
        }

        IPublishedContent? designFolder = null;
        if (context != null && context.Content != null)
        {
            designFolder = context.Content.GetAtRoot().FirstOrDefault(x => x.ContentType.Alias == "USNStylesFolder");
        }

        if(designFolder != null) {
            IEnumerable<IContent> designs = _contentService.GetPagedChildren(1711, 0, int.MaxValue, out long countDesigns) ?? Enumerable.Empty<IContent>();

            foreach(var design in designs) {
                _contentService.SaveAndPublish(design);
                _logger.LogInformation($"Design({design.Id}) has been published");
            }

        }
    }
}
Any suggestions how to get around this ?
3 Views