/// <summary> /// Clones the object to the DB according to provided settings. /// </summary> public CloneResult CloneObject() { if (InfoToClone != null) { TransferExcludedTypes(); // Check code name if (plcCodeName.Visible) { bool checkCodeName = true; if (customProperties != null) { checkCodeName = customProperties.ValidateCodeName; } if (checkCodeName && !ValidationHelper.IsCodeName(txtCodeName.Text)) { ShowError(GetString("general.invalidcodename")); return(null); } } // Check permissions string targetSiteName = SiteContext.CurrentSiteName; if (plcCloneUnderSite.Visible && siteElem.Visible) { int targetSiteId = siteElem.SiteID; if (targetSiteId > 0) { targetSiteName = SiteInfoProvider.GetSiteName(targetSiteId); } } // Check object permissions (Create & Modify) try { InfoToClone.CheckPermissions(PermissionsEnum.Create, targetSiteName, CurrentUser, true); InfoToClone.CheckPermissions(PermissionsEnum.Modify, targetSiteName, CurrentUser, true); } catch (PermissionCheckException ex) { RedirectToAccessDenied(ex.ModuleName, ex.PermissionFailed); } CloneSettings settings = new CloneSettings(); settings.KeepFieldsTranslated = chkKeepFieldsTranslated.Checked; settings.CloneBase = InfoToClone; settings.CodeName = txtCodeName.Text; settings.DisplayName = txtDisplayName.Text; settings.IncludeBindings = chkBindings.Checked; settings.IncludeOtherBindings = chkBindings.Checked; settings.IncludeChildren = chkChildren.Checked; settings.IncludeMetafiles = chkMetafiles.Checked; settings.IncludeSiteBindings = chkSiteBindings.Checked; if (plcAssignToCurrentSite.Visible) { settings.AssignToSiteID = (chkAssignToCurrentSite.Checked ? SiteContext.CurrentSiteID : 0); } settings.MaxRelativeLevel = ValidationHelper.GetInteger(drpMaxRelativeLevel.SelectedValue, -1); if (plcCloneUnderSite.Visible && siteElem.Visible) { settings.CloneToSiteID = siteElem.SiteID; } else { settings.CloneToSiteID = InfoToClone.Generalized.ObjectSiteID; } if (customProperties != null) { if (customProperties.IsValid(settings)) { Hashtable p = customProperties.CustomParameters; if (p != null) { settings.CustomParameters = p; } settings.ExcludedChildTypes.AddRange(excludedChildren); settings.ExcludedBindingTypes.AddRange(excludedBindings); settings.ExcludedOtherBindingTypes.AddRange(excludedOtherBindings); } else { return(null); } } if (InfoToClone.Parent != null) { settings.ParentID = InfoToClone.Parent.Generalized.ObjectID; } CloneResult result = new CloneResult(); BaseInfo clone = null; if (chkUseTransaction.Checked) { using (var transaction = new CMSTransactionScope()) { clone = InfoToClone.Generalized.InsertAsClone(settings, result); transaction.Commit(); } } else { clone = InfoToClone.Generalized.InsertAsClone(settings, result); } if (customProperties != null) { string script = customProperties.CloseScript; if (!string.IsNullOrEmpty(script)) { mCloseScript = script.Replace("{0}", clone.Generalized.ObjectID.ToString()); } } return(result); } return(null); }
/// <summary> /// Clones the object to the DB according to provided settings. /// </summary> /// public CloneResult CloneObject() { if (InfoToClone == null) { return(null); } TransferExcludedTypes(); // Check code name if (plcCodeName.Visible) { bool checkCodeName = customProperties?.ValidateCodeName ?? true; if (checkCodeName && !ValidationHelper.IsCodeName(txtCodeName.Text)) { ShowError(GetString("general.invalidcodename")); return(null); } } // Check display name length if (plcDisplayName.Visible && (txtDisplayName.Text.Length > mDisplayNameMaxLength)) { ShowError(string.Format(GetString("cloning.displayname.maxlengthexceed"), mDisplayNameMaxLength)); return(null); } // Check permissions string targetSiteName = SiteContext.CurrentSiteName; if (plcCloneUnderSite.Visible && siteElem.Visible && (siteElem.SiteID > 0)) { targetSiteName = SiteInfoProvider.GetSiteName(siteElem.SiteID); } // Check object permissions (Create & Modify) try { InfoToClone.CheckPermissions(PermissionsEnum.Create, targetSiteName, CurrentUser, true); InfoToClone.CheckPermissions(PermissionsEnum.Modify, targetSiteName, CurrentUser, true); } catch (PermissionCheckException ex) { RedirectToAccessDenied(ex.ModuleName, ex.PermissionFailed); } CloneSettings settings = InitializeCloneSettings(); if (settings == null) { return(null); } var result = new CloneResult(); BaseInfo clone; if (chkUseTransaction.Checked) { using (var transaction = new CMSTransactionScope()) { clone = InfoToClone.Generalized.InsertAsClone(settings, result); transaction.Commit(); } } else { clone = InfoToClone.Generalized.InsertAsClone(settings, result); } string script = customProperties?.CloseScript; if (!string.IsNullOrEmpty(script)) { mCloseScript = script.Replace("{0}", clone.Generalized.ObjectID.ToString()); } return(result); }