/// <summary> /// Rollbacks a document to a previous version, this will create a new version of the document and copy /// all of the old documents data. /// </summary> /// <param Name="u">The usercontext under which the action are performed</param> /// <param Name="VersionId">The unique Id of the version to roll back to</param> public void RollBack(Guid VersionId, User u) { Guid newVersion = createNewVersion(); Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteNonQuery(_ConnString, CommandType.Text, "insert into cmsDocument (nodeId, published, documentUser, versionId, Text, TemplateId) values (" + Id + ", 0, " + u.Id + ", '" + newVersion + "', N'" + Umbraco.SqlHelper.SafeString(Text) + "', " + _template + ")"); // Get new version Document dNew = new Document(Id, newVersion); // Old version Document dOld = new Document(Id, VersionId); // Revert title dNew.Text = dOld.Text; // Revert all properties foreach (Property p in dOld.getProperties) { try { dNew.getProperty(p.PropertyType).Value = p.Value; } catch { // property doesn't exists } } }
public void Copy(int CopyTo, User u, bool RelateToOrignal) { // Make the new document Document NewDoc = MakeNew(Text, new DocumentType(ContentType.Id), u, CopyTo); // update template NewDoc.Template = Template; // Copy the properties of the current document foreach (Property p in getProperties) { NewDoc.getProperty(p.PropertyType.Alias).Value = p.Value; } // Relate? if (RelateToOrignal) { Relation.MakeNew(Id, NewDoc.Id, RelationType.GetByAlias("relateDocumentOnCopy"), ""); // Add to audit trail Log.Add(LogTypes.Copy, u, NewDoc.Id, "Copied and related from " + Text + " (id: " + Id.ToString() + ")"); } // Copy the children foreach (Document c in Children) { c.Copy(NewDoc.Id, u, RelateToOrignal); } }
/// <summary> /// Imports (create) a document from a xmlrepresentation of a document, used by the packager /// </summary> /// <param Name="ParentId">The id to import to</param> /// <param Name="Creator">Creator f the new document</param> /// <param Name="Source">Xmlsource</param> public static void Import(int ParentId, User Creator, XmlElement Source) { Document d = MakeNew( Source.GetAttribute("nodeName"), DocumentType.GetByAlias(Source.GetAttribute("nodeTypeAlias")), Creator, ParentId); d.CreateDateTime = DateTime.Parse(Source.GetAttribute("createDate")); // Properties foreach (XmlElement n in Source.SelectNodes("data")) { d.getProperty(n.GetAttribute("alias")).Value = XmlHelper.GetNodeValue(n); } // Subpages foreach (XmlElement n in Source.SelectNodes("node")) { Import(d.Id, Creator, n); } }
/// <summary> /// Rollbacks a document to a previous version, this will create a new version of the document and copy /// all of the old documents data. /// </summary> /// <param Name="u">The usercontext under which the action are performed</param> /// <param Name="VersionId">The unique Id of the version to roll back to</param> public void RollBack(Guid VersionId, User u) { Guid newVersion = createNewVersion(); Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteNonQuery(_ConnString, CommandType.Text, "insert into cmsDocument (nodeId, published, documentUser, versionId, Text, TemplateId) values (" + Id + ", 0, " + u.Id + ", '" + newVersion + "', N'" + Umbraco.SqlHelper.SafeString(Text) + "', " + _template + ")"); // Get new version Document dNew = new Document(Id, newVersion); // Old version Document dOld = new Document(Id, VersionId); // Revert title dNew.Text = dOld.Text; // Revert all properties foreach (Property p in dOld.getProperties) try { dNew.getProperty(p.PropertyType).Value = p.Value; } catch { // property doesn't exists } }