Skip to content

Instantly share code, notes, and snippets.

Avatar

John Rappel jraps20

View GitHub Profile
@jraps20
jraps20 / PublishUtils.cs
Last active May 2, 2022
Sitecore publishing Utils to quickly queue up a batch of items to a publish queue and publish the queue, as opposed to individual publishes which cause the publish:end event to fire multiple times (read: individual index updates, cache clearing, etc.)
View PublishUtils.cs
public static class PublishUtils
{
public static void CreateAndPublishQueue(Database sourceDatabase, Database[] targetDatabases, Language[] targetLanguages, IEnumerable<ID> itemIds, bool skipEvents = false, bool useSecurityDisabler = true)
{
Assert.IsNotNull(sourceDatabase, "sourceDatabase");
Assert.IsNotNull(targetDatabases, "targetDatabases");
Assert.IsNotNull(targetLanguages, "targetLanguages");
var publishingCandidates = SetPublishingCandidates(sourceDatabase, targetDatabases, targetLanguages, itemIds);
@jraps20
jraps20 / build.yml
Created Aug 12, 2019
Cache NuGet Packages with Cache Task in Azure DevOps YAML
View build.yml
- powershell: | # generates a hash of all packages.config and saves each on a single line on 'hash.txt'
Get-FileHash -Algorithm MD5 -Path (Get-ChildItem packages.config -Recurse) >> hash.txt
Write-Host "Hash File saved to $pwd\hash.txt"
workingDirectory: src
displayName: 'Calculate and save packages.config hash'
- task: CacheBeta@0 # speed up builds by caching packages folder
inputs:
key: nuget|1|$(Agent.OS)|$(Build.SourcesDirectory)\src\hash.txt # hash map generated in previous step
path: $(Build.SourcesDirectory)\src\packages
@jraps20
jraps20 / RemoteDelete.config
Created Jul 3, 2018
Delete Sitecore items from remote databases when delete occurs in master.
View RemoteDelete.config
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<events>
<event name="item:deleting">
<handler type="MyProject.MyNamespace.RemoteDeleteHandler, MyProject" method="OnItemDeleting" />
</event>
</events>
</sitecore>
</configuration>
View Example.cs
var localCopyrightSettingsItem = Context.Items.Get(MultisiteConstants.LocalCopyrightSettingsItem);
View ItemsLookup.cs
namespace MyProject.Pipelines
{
public class ItemsLookup : HttpRequestProcessor
{
public override void Process(HttpRequestArgs args)
{
// Shared Data Folder
Context.Items.SetLazy(MultisiteConstants.SharedDataFolderItem, () =>
Context.Database.GetItem(new ID(MultisiteConstants.SharedDataFolderId))
);
View ItemsContextExtensions.cs
namespace MyProject.Extensions
{
public static class ItemsContextExtensions
{
public static Item Get(this ItemsContext source, string identifier)
{
if (string.IsNullOrWhiteSpace(identifier))
throw new Exception("Must set identifier for getting global property");
var dictionary = source as IDictionary;
View zItemsLookup.xml
<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<httpRequestBegin>
<processor type="MyProject.Pipelines.ItemsLookup, MyProject" resolve="true" patch:after="*[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']" />
</httpRequestBegin>
</pipelines>
</sitecore>
</configuration>
@jraps20
jraps20 / PublishDeployedItemsWithPublishingQueue.cs
Last active Jul 19, 2018
TDS Post Deploy Action to publish items via publishing queue instead of native solution
View PublishDeployedItemsWithPublishingQueue.cs
[Description("Publishes deployed items after deployment using publishing queue.\nPublishing targets are specified in the Parameter as a comma separated list.")]
public class PublishDeployedItemsWithPublishingQueue : IPostDeployAction
{
/// <summary>
/// Borrowed directly from HedgehogDevelopment.SitecoreProject.PackageInstallPostProcessor.BuiltIn.PublishDeployedItems, HedgehogDevelopment.SitecoreProject.PackageInstallPostProcessor
/// </summary>
private static Database[] GetPublishingTargetDatabases(string parameters)
{
if (string.IsNullOrEmpty(parameters))
{
View SiteCronBase.cs
using Quartz;
using Sitecron.SitecronSettings;
public abstract class SiteCronBase : IJob
{
private DateTime _lastLogEntry;
protected abstract void Run(IJobExecutionContext args);
public void Execute(IJobExecutionContext context)
{
View ExampleSiteCronJob.cs
using Quartz;
public class TestJob : SiteCronBase
{
protected override void Run(IJobExecutionContext context)
{
WriteLogLine(context, "Starting SiteCron job");
// core functionality lives here
// obtain databases with Factory.GetDatabase("master"); for example