Last active
August 8, 2019 14:31
-
-
Save phaniav/1d36a507dda8407c960639a49978ffd5 to your computer and use it in GitHub Desktop.
WebService file to deploy and publish Sitecore items during release process. should be deleted at the end of release. - https://jeffdarchuk.com/2019/03/12/remotely-triggering-sitecore-operations-in-azure/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web.Services; | |
using Sitecore.Jobs; | |
[WebService(Namespace = "http://tempuri.org/")] | |
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] | |
[System.ComponentModel.ToolboxItem(false)] | |
public class PublishManager : System.Web.Services.WebService | |
{ | |
[WebMethod(Description = "Publishes all content")] | |
public bool PublishAll(string token) | |
{ | |
if (string.IsNullOrEmpty(token)) | |
return false; | |
if (token != "[TOKEN]") | |
return false; | |
var db = Sitecore.Configuration.Factory.GetDatabase("master"); | |
var item = db.GetRootItem(); | |
var publishingTargets = Sitecore.Publishing.PublishManager.GetPublishingTargets(item.Database); | |
foreach (var publishingTarget in publishingTargets) | |
{ | |
var targetDatabaseName = publishingTarget["Target database"]; | |
if (string.IsNullOrEmpty(targetDatabaseName)) | |
continue; | |
var targetDatabase = Sitecore.Configuration.Factory.GetDatabase(targetDatabaseName); | |
if (targetDatabase == null) | |
continue; | |
var publishOptions = new Sitecore.Publishing.PublishOptions( | |
item.Database, | |
targetDatabase, | |
Sitecore.Publishing.PublishMode.Smart, | |
item.Language, | |
System.DateTime.Now); | |
var publisher = new Sitecore.Publishing.Publisher(publishOptions); | |
publisher.Options.RootItem = item; | |
publisher.Options.Deep = true; | |
publisher.PublishAsync(); | |
} | |
return true; | |
} | |
[WebMethod(Description = "Checks publish status")] | |
public string[] PublishStatus() | |
{ | |
return JobManager.GetJobs().Where(x => !x.IsDone && x.Name.StartsWith("Publish")).Select(x => | |
x.Status.Processed + " -> " + x.Name).ToArray(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment