-
-
Save anonymous/6414475100ad107d66eb to your computer and use it in GitHub Desktop.
Failing csharp Umbraco Contour Workflow document for publishing document.
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; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using umbraco.BusinessLogic; | |
using umbraco.cms.businesslogic.web; | |
using umbraco.cms.businesslogic.propertytype; | |
using umbraco.cms.businesslogic.property; | |
using Umbraco.Forms.Data; | |
using Umbraco.Forms.Core; | |
using Umbraco.Forms.Core.Enums; | |
namespace AttackMonkey.Contour.WorkFlows | |
{ | |
public class PublishFormAsPage : WorkflowType | |
{ | |
public PublishFormAsPage() | |
{ | |
this.Id = new Guid("139c868c-9bfc-41ae-85ff-cc22af63abfc"); | |
this.Name = "Save as umbraco document - parent page from form"; | |
this.Description = "Saves the form values as an umbraco document node with a specific type, with the parent page being selected from the form itself, rather than being a fixed node."; | |
} | |
[Umbraco.Forms.Core.Attributes.Setting("Document Type", description = "Map document type", control = "Umbraco.Forms.Core.FieldSetting.DocumentMapper")] | |
public string Fields { get; set; } | |
[Umbraco.Forms.Core.Attributes.Setting("Publish", description = "Publish document instantly", control = "Umbraco.Forms.Core.FieldSetting.Checkbox")] | |
public string Publish { get; set; } | |
[Umbraco.Forms.Core.Attributes.Setting("Field containing node id", description = "The field in the form that contains the node id of the page to save to", control = "Umbraco.Forms.Core.FieldSetting.FieldPicker")] | |
public string RootNode { get; set; } | |
public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e) | |
{ | |
Dictionary<string, string> mappings = new Dictionary<string, string>(); | |
int dtId = 0; | |
int root = -1; | |
//old code to get node id | |
//int.TryParse(RootNode, out root); | |
//new code, using the field mapping from the settings, gets the value of the field specified as containing the page id | |
if (record.RecordFields.ContainsKey(new Guid(RootNode))) | |
{ | |
int.TryParse(record.RecordFields[new Guid(RootNode)].ValuesAsString(), out root); | |
} | |
if (root == 0) | |
root = -1; | |
string nameMapping = "NodeName"; | |
string[] array = Fields.Trim().Split('|'); | |
foreach (string s in array) | |
{ | |
string[] a = s.Trim().Split(','); | |
if (a.Count() == 1 && s.Trim().Length >= 4) | |
{ | |
if (dtId == 0) | |
int.TryParse(s.Trim(), out dtId); | |
} | |
else if (a.Count() == 3) | |
{ | |
string mapping = ""; | |
if (!string.IsNullOrEmpty(a[2])) | |
mapping = record.RecordFields[new Guid(a[2])].ValuesAsString(); | |
else if (!string.IsNullOrEmpty(a[1])) | |
mapping = Umbraco.Forms.Core.Services.WorkflowService.parseAttribute(e.Context, record, a[1]); | |
if ((!string.IsNullOrEmpty(mapping))) | |
{ | |
if (a[0] == "__nodeName") | |
nameMapping = mapping; | |
else | |
{ | |
mappings.Add(a[0], mapping); | |
LogHelper.Debug(a[0] + " " + mapping); | |
} | |
} | |
} | |
} | |
DocumentType dt = new DocumentType(dtId); | |
if (dt != null) | |
{ | |
////ensure that the question used in the url isn't stupidly long by limiting the name mapping to the first sentence | |
//if (nameMapping.Contains(".")) | |
//{ | |
// nameMapping = nameMapping.Substring(0, nameMapping.IndexOf(".")); | |
//} | |
Document d = new Document(root); | |
foreach (Property p in d.getProperties) | |
{ | |
try | |
{ | |
if (mappings.ContainsKey(p.PropertyType.Alias)) | |
{ | |
p.Value = mappings[p.PropertyType.Alias]; | |
} | |
} | |
catch (Exception ex) | |
{ | |
LogHelper.Debug(ex.ToString()); | |
} | |
} | |
//d.Save(); | |
/*if (Publish == true.ToString()) | |
{ | |
d.Publish(User.GetUser(0)); | |
umbraco.library.PublishSingleNode(d.Id); | |
}*/ | |
d.Save(); | |
d.Publish(d.User); | |
umbraco.library.UpdateDocumentCache(d.Id); | |
} | |
return WorkflowExecutionStatus.Completed; | |
} | |
public override List<Exception> ValidateSettings() | |
{ | |
return new List<Exception>(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment