/// <inheritdoc /> public void Update(IWebPartField field) { var formInfo = new FormInfo(field.WebPart.WebPartProperties); var fieldInfo = formInfo.GetFormField(field.Name); fieldInfo.AllowEmpty = field.AllowEmpty; fieldInfo.Caption = field.Caption; fieldInfo.DataType = field.DataType; fieldInfo.DefaultValue = field.DefaultValue; fieldInfo.Size = field.Size; formInfo.UpdateFormField(field.Name, fieldInfo); field.WebPart.WebPartProperties = formInfo.GetXmlDefinition(); this.SaveFormUpdates(field.WebPart); }
public static void Update60() { EventLogProvider evp = new EventLogProvider(); evp.LogEvent("I", DateTime.Now, "Upgrade to 6.0", "Upgrade - Start"); DataClassInfo dci = null; #region "CMS.UserSettings" try { dci = DataClassInfoProvider.GetDataClass("cms.usersettings"); if (dci != null) { FormInfo fi = new FormInfo(dci.ClassFormDefinition); if (fi != null) { FormFieldInfo ffi = new FormFieldInfo(); ffi.Name = "UserAuthenticationGUID"; ffi.DataType = FormFieldDataTypeEnum.GUID; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "UserBounces"; ffi.DataType = FormFieldDataTypeEnum.Integer; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.TextBoxControl; ffi.Visible = false; ffi.Caption = "UserBounces"; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "UserLinkedInID"; ffi.DataType = FormFieldDataTypeEnum.Text; ffi.Size = 100; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "UserLogActivities"; ffi.DataType = FormFieldDataTypeEnum.Boolean; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "UserPasswordRequestHash"; ffi.DataType = FormFieldDataTypeEnum.Text; ffi.Size = 100; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); dci.ClassFormDefinition = fi.GetXmlDefinition(); TableManager tm = new TableManager(dci.ClassConnectionString); dci.ClassXmlSchema = tm.GetXmlSchema("CMS_UserSettings"); DataClassInfoProvider.SetDataClass(dci); // Generate queries SqlGenerator.GenerateDefaultQueries(dci, true, false); tm.RefreshCustomViews("CMS_UserSettings"); } } } catch (Exception ex) { evp.LogEvent("CMS.UserSettings - Upgrade", "Upgrade", ex); } #endregion #region "Ecommerce - Customer" try { dci = DataClassInfoProvider.GetDataClass("ecommerce.customer"); if (dci != null) { FormInfo fi = new FormInfo(dci.ClassFormDefinition); if (fi != null) { FormFieldInfo ffi = new FormFieldInfo(); ffi.Name = "CustomerSiteID"; ffi.DataType = FormFieldDataTypeEnum.Integer; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.TextBoxControl; ffi.Visible = false; fi.AddFormField(ffi); TableManager tm = new TableManager(dci.ClassConnectionString); dci.ClassFormDefinition = fi.GetXmlDefinition(); dci.ClassXmlSchema = tm.GetXmlSchema("COM_Customer"); DataClassInfoProvider.SetDataClass(dci); // Generate queries SqlGenerator.GenerateDefaultQueries(dci, true, false); tm.RefreshCustomViews("COM_Customer"); } } } catch (Exception ex) { evp.LogEvent("Ecommerce.Customer - Upgrade", "Upgrade", ex); } #endregion #region "Ecommerce - Order" try { dci = DataClassInfoProvider.GetDataClass("ecommerce.order"); if (dci != null) { FormInfo fi = new FormInfo(dci.ClassFormDefinition); if (fi != null) { FormFieldInfo ffi = new FormFieldInfo(); ffi.Name = "OrderCulture"; ffi.DataType = FormFieldDataTypeEnum.Text; ffi.Size = 10; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "OrderIsPaid"; ffi.DataType = FormFieldDataTypeEnum.Boolean; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "OrderTotalPriceInMainCurrency"; ffi.DataType = FormFieldDataTypeEnum.Decimal; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = fi.GetFormField("OrderStatusID"); if (ffi != null) { ffi.AllowEmpty = true; fi.UpdateFormField("OrderStatusID", ffi); } ffi = fi.GetFormField("OrderShippingAddressID"); if (ffi != null) { ffi.AllowEmpty = true; fi.UpdateFormField("OrderShippingAddressID", ffi); } dci.ClassFormDefinition = fi.GetXmlDefinition(); TableManager tm = new TableManager(dci.ClassConnectionString); dci.ClassXmlSchema = tm.GetXmlSchema("COM_Order"); DataClassInfoProvider.SetDataClass(dci); // Generate queries SqlGenerator.GenerateDefaultQueries(dci, true, false); tm.RefreshCustomViews("COM_Order"); } } } catch (Exception ex) { evp.LogEvent("Ecommerce.Order - Upgrade", "Upgrade", ex); } #endregion #region "Ecommerce - OrderItem" try { dci = DataClassInfoProvider.GetDataClass("ecommerce.orderitem"); if (dci != null) { FormInfo fi = new FormInfo(dci.ClassFormDefinition); if (fi != null) { FormFieldInfo ffi = new FormFieldInfo(); ffi.Name = "OrderItemBundleGUID"; ffi.DataType = FormFieldDataTypeEnum.GUID; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "OrderItemIsPrivate"; ffi.DataType = FormFieldDataTypeEnum.Boolean; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "OrderItemPrice"; ffi.DataType = FormFieldDataTypeEnum.Decimal; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "OrderItemSendNotification"; ffi.DataType = FormFieldDataTypeEnum.Boolean; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "OrderItemSKU"; ffi.DataType = FormFieldDataTypeEnum.LongText; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "OrderItemText"; ffi.DataType = FormFieldDataTypeEnum.LongText; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "OrderItemTotalPriceInMainCurrency"; ffi.DataType = FormFieldDataTypeEnum.Decimal; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "OrderItemValidTo"; ffi.DataType = FormFieldDataTypeEnum.DateTime; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); dci.ClassFormDefinition = fi.GetXmlDefinition(); TableManager tm = new TableManager(dci.ClassConnectionString); dci.ClassXmlSchema = tm.GetXmlSchema("COM_OrderItem"); DataClassInfoProvider.SetDataClass(dci); // Generate queries SqlGenerator.GenerateDefaultQueries(dci, true, false); tm.RefreshCustomViews("COM_OrderItem"); } } } catch (Exception ex) { evp.LogEvent("Ecommerce.OrderItem - Upgrade", "Upgrade", ex); } #endregion #region "Ecommerce - Shopping cart item" try { dci = DataClassInfoProvider.GetDataClass("ecommerce.shoppingcartitem"); if (dci != null) { FormInfo fi = new FormInfo(dci.ClassFormDefinition); if (fi != null) { FormFieldInfo ffi = new FormFieldInfo(); ffi.Name = "CartItemBundleGUID"; ffi.DataType = FormFieldDataTypeEnum.GUID; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "CartItemIsPrivate"; ffi.DataType = FormFieldDataTypeEnum.Boolean; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "CartItemPrice"; ffi.DataType = FormFieldDataTypeEnum.Decimal; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "CartItemText"; ffi.DataType = FormFieldDataTypeEnum.LongText; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "CartItemValidTo"; ffi.DataType = FormFieldDataTypeEnum.DateTime; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = fi.GetFormField("CartItemGuid"); if (ffi != null) { ffi.AllowEmpty = true; fi.UpdateFormField("CartItemGuid", ffi); } dci.ClassFormDefinition = fi.GetXmlDefinition(); TableManager tm = new TableManager(dci.ClassConnectionString); dci.ClassXmlSchema = tm.GetXmlSchema("COM_ShoppingCartSKU"); DataClassInfoProvider.SetDataClass(dci); // Generate queries SqlGenerator.GenerateDefaultQueries(dci, true, false); tm.RefreshCustomViews("COM_ShoppingCartSKU"); } } } catch (Exception ex) { evp.LogEvent("Ecommerce.ShoppingCartItem - Upgrade", "Upgrade", ex); } #endregion #region "Ecommerce - SKU" try { dci = DataClassInfoProvider.GetDataClass("ecommerce.sku"); if (dci != null) { FormInfo fi = new FormInfo(dci.ClassFormDefinition); if (fi != null) { FormFieldInfo ffi = new FormFieldInfo(); ffi.Name = "SKUBundleInventoryType"; ffi.DataType = FormFieldDataTypeEnum.Text; ffi.Size = 50; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "SKUConversionName"; ffi.DataType = FormFieldDataTypeEnum.Text; ffi.Size = 100; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "SKUConversionValue"; ffi.DataType = FormFieldDataTypeEnum.Text; ffi.Size = 200; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "SKUMaxDownloads"; ffi.DataType = FormFieldDataTypeEnum.Integer; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "SKUMaxItemsInOrder"; ffi.DataType = FormFieldDataTypeEnum.Integer; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "SKUMaxPrice"; ffi.DataType = FormFieldDataTypeEnum.Decimal; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "SKUMembershipGUID"; ffi.DataType = FormFieldDataTypeEnum.GUID; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "SKUMinPrice"; ffi.DataType = FormFieldDataTypeEnum.Decimal; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "SKUNeedsShipping"; ffi.DataType = FormFieldDataTypeEnum.Boolean; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "SKUPrivateDonation"; ffi.DataType = FormFieldDataTypeEnum.Boolean; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "SKUProductType"; ffi.DataType = FormFieldDataTypeEnum.Text; ffi.Size = 50; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "SKUSiteID"; ffi.DataType = FormFieldDataTypeEnum.Integer; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "SKUValidFor"; ffi.DataType = FormFieldDataTypeEnum.Integer; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "SKUValidity"; ffi.DataType = FormFieldDataTypeEnum.Text; ffi.Size = 50; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = new FormFieldInfo(); ffi.Name = "SKUValidUntil"; ffi.DataType = FormFieldDataTypeEnum.DateTime; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); ffi = fi.GetFormField("SKUDepartmentID"); if (ffi != null) { ffi.AllowEmpty = true; fi.UpdateFormField("SKUDepartmentID", ffi); } dci.ClassFormDefinition = fi.GetXmlDefinition(); TableManager tm = new TableManager(dci.ClassConnectionString); dci.ClassXmlSchema = tm.GetXmlSchema("COM_SKU"); DataClassInfoProvider.SetDataClass(dci); // Generate queries SqlGenerator.GenerateDefaultQueries(dci, true, false); tm.RefreshCustomViews("COM_SKU"); } } } catch (Exception ex) { evp.LogEvent("Ecommerce.SKU - Upgrade", "Upgrade", ex); } #endregion #region "Community - Group" try { dci = DataClassInfoProvider.GetDataClass("Community.Group"); if (dci != null) { FormInfo fi = new FormInfo(dci.ClassFormDefinition); if (fi != null) { FormFieldInfo ffi = new FormFieldInfo(); ffi.Name = "GroupLogActivity"; ffi.DataType = FormFieldDataTypeEnum.Boolean; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.CheckBoxControl; ffi.Visible = true; ffi.DefaultValue = "true"; ffi.Caption = "GroupLogActivity"; fi.AddFormField(ffi); dci.ClassFormDefinition = fi.GetXmlDefinition(); TableManager tm = new TableManager(dci.ClassConnectionString); dci.ClassXmlSchema = tm.GetXmlSchema("Community_Group"); DataClassInfoProvider.SetDataClass(dci); // Generate queries SqlGenerator.GenerateDefaultQueries(dci, true, false); tm.RefreshCustomViews("Community_Group"); } } } catch (Exception ex) { evp.LogEvent("Community.Group - Upgrade", "Upgrade", ex); } #endregion #region "Newsletter - Subscriber" try { dci = DataClassInfoProvider.GetDataClass("newsletter.subscriber"); if (dci != null) { FormInfo fi = new FormInfo(dci.ClassFormDefinition); if (fi != null) { FormFieldInfo ffi = new FormFieldInfo(); ffi.Name = "SubscriberBounces"; ffi.DataType = FormFieldDataTypeEnum.Boolean; ffi.AllowEmpty = true; ffi.PublicField = false; ffi.System = true; ffi.FieldType = FormFieldControlTypeEnum.LabelControl; ffi.Visible = false; fi.AddFormField(ffi); dci.ClassFormDefinition = fi.GetXmlDefinition(); TableManager tm = new TableManager(dci.ClassConnectionString); dci.ClassXmlSchema = tm.GetXmlSchema("Newsletter_Subscriber"); DataClassInfoProvider.SetDataClass(dci); // Generate queries SqlGenerator.GenerateDefaultQueries(dci, true, false); tm.RefreshCustomViews("Newsletter_Subscriber"); } } } catch (Exception ex) { evp.LogEvent("Newsletter.Subscriber - Upgrade", "Upgrade", ex); } #endregion #region "CMS.Document" try { dci = DataClassInfoProvider.GetDataClass("cms.document"); if (dci != null) { SearchSettings ss = dci.ClassSearchSettingsInfos; SearchSettingsInfo ssi = ss.GetSettingsInfo("42f446ee-9818-4596-8124-54a38f64aa05"); if (ssi != null) { ssi.Searchable = true; ss.SetSettingsInfo(ssi); } DataClassInfoProvider.SetDataClass(dci); } } catch (Exception ex) { evp.LogEvent("CMS.Document - Upgrade", "Upgrade", ex); } #endregion // Set the path to the upgrade package mUpgradePackagePath = HttpContext.Current.Server.MapPath("~/CMSSiteUtils/Import/upgrade_55R2_60.zip"); mWebsitePath = HttpContext.Current.Server.MapPath("~/"); TableManager dtm = new TableManager(null); // Update all views dtm.RefreshDocumentViews(); // Set data version ObjectHelper.SetSettingsKeyValue("CMSDataVersion", "6.0"); // Clear hashtables CMSObjectHelper.ClearHashtables(); // Clear the cache CacheHelper.ClearCache(null, true); // Drop the routes CMSMvcHandler.DropAllRoutes(); // Init the Mimetype helper (required for the Import) MimeTypeHelper.LoadMimeTypes(); CMSThread thread = new CMSThread(Upgrade60Import); thread.Start(); }
/// <summary> /// Loads the web part form. /// </summary> protected void LoadForm() { // Load settings if (!string.IsNullOrEmpty(Request.Form[hdnIsNewWebPart.UniqueID])) { IsNewWebPart = ValidationHelper.GetBoolean(Request.Form[hdnIsNewWebPart.UniqueID], false); } if (!string.IsNullOrEmpty(Request.Form[hdnInstanceGUID.UniqueID])) { InstanceGUID = ValidationHelper.GetGuid(Request.Form[hdnInstanceGUID.UniqueID], Guid.Empty); } // Indicates whether the new variant should be chosen when closing this dialog selectNewVariant = IsNewVariant; // Try to find the web part variant in the database and set its VariantID if (IsNewVariant) { Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable; if (properties != null) { // Get the variant code name from the WindowHelper string variantName = ValidationHelper.GetString(properties["codename"], string.Empty); // Check if the variant exists in the database int variantIdFromDB = 0; if (VariantMode == VariantModeEnum.MVT) { variantIdFromDB = ModuleCommands.OnlineMarketingGetMVTVariantId(PageTemplateId, variantName); } else if (VariantMode == VariantModeEnum.ContentPersonalization) { variantIdFromDB = ModuleCommands.OnlineMarketingGetContentPersonalizationVariantId(PageTemplateId, variantName); } // Set the variant id from the database if (variantIdFromDB > 0) { VariantID = variantIdFromDB; IsNewVariant = false; } } } if (!String.IsNullOrEmpty(WebpartId)) { // Get the page info pi = CMSWebPartPropertiesPage.GetPageInfo(AliasPath, PageTemplateId, CultureCode); if (pi != null) { // Get template pti = pi.UsedPageTemplateInfo; // Get template instance templateInstance = pti.TemplateInstance; if (!IsNewWebPart) { // Standard zone webPartInstance = templateInstance.GetWebPart(InstanceGUID, WebpartId); // If the web part not found, try to find it among the MVT/CP variants if (webPartInstance == null) { // MVT/CP variant templateInstance.LoadVariants(false, VariantModeEnum.None); webPartInstance = templateInstance.GetWebPart(InstanceGUID, true); // Set the VariantMode according to the selected web part/zone variant if ((webPartInstance != null) && (webPartInstance.ParentZone != null)) { VariantMode = (webPartInstance.VariantMode != VariantModeEnum.None) ? webPartInstance.VariantMode : webPartInstance.ParentZone.VariantMode; } else { VariantMode = VariantModeEnum.None; } } else { // Ensure that the ZoneVarianID is not set when the web part was found in a regular zone ZoneVariantID = 0; } if ((VariantID > 0) && (webPartInstance != null) && (webPartInstance.PartInstanceVariants != null)) { // Check OnlineMarketing permissions. if (CheckPermissions("Read")) { webPartInstance = webPartInstance.FindVariant(VariantID); } else { // Not authorized for OnlineMarketing - Manage. RedirectToInformation(String.Format(GetString("general.permissionresource"), "Read", (VariantMode == VariantModeEnum.ContentPersonalization) ? "CMS.ContentPersonalization" : "CMS.MVTest")); } } if (webPartInstance == null) { CMSPage.EditedObject = null; return; } } // Keep xml version if (webPartInstance != null) { xmlVersion = webPartInstance.XMLVersion; } // Get the form info FormInfo fi = GetWebPartFormInfo(); // Get the form definition if (fi != null) { form.AllowMacroEditing = ((WebPartTypeEnum)wpi.WebPartType != WebPartTypeEnum.Wireframe); // Get data row with required columns DataRow dr = fi.GetDataRow(true, wpi.WebPartDefaultValues); if (IsNewWebPart || (xmlVersion > 0)) { fi.LoadDefaultValues(dr); // Load overridden system values fi.LoadDefaultValues(dr, wpi.WebPartDefaultValues); } if (IsNewWebPart) { // Set control ID FormFieldInfo ffi = fi.GetFormField("WebPartControlID"); if (ffi != null) { ffi.DefaultValue = WebPartZoneInstance.GetUniqueWebPartId(wpi.WebPartName, templateInstance); fi.UpdateFormField("WebPartControlID", ffi); } } // Load values from existing web part LoadDataRowFromWebPart(dr, webPartInstance, fi); // Set a unique WebPartControlID for the new variant if (IsNewVariant) { // Set control ID dr["WebPartControlID"] = WebPartZoneInstance.GetUniqueWebPartId(wpi.WebPartName, templateInstance); } // Init the form InitForm(form, dr, fi); AddExportLink(); } else { CMSPage.EditedObject = null; } } } }
/// <summary> /// Init event handler. /// </summary> protected override void OnInit(EventArgs e) { base.OnInit(e); // Load settings if (!string.IsNullOrEmpty(Request.Form[hdnIsNewWebPart.UniqueID])) { IsNewWebPart = ValidationHelper.GetBoolean(Request.Form[hdnIsNewWebPart.UniqueID], false); } if (!string.IsNullOrEmpty(Request.Form[hdnInstanceGUID.UniqueID])) { InstanceGUID = ValidationHelper.GetGuid(Request.Form[hdnInstanceGUID.UniqueID], Guid.Empty); } // Try to find the web part variant in the database and set its VariantID if (IsNewVariant) { Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable; if (properties != null) { // Get the variant code name from the WindowHelper string variantName = ValidationHelper.GetString(properties["codename"], string.Empty); // Check if the variant exists in the database int variantIdFromDB = 0; if (VariantMode == VariantModeEnum.MVT) { variantIdFromDB = ModuleCommands.OnlineMarketingGetMVTVariantId(PageTemplateId, variantName); } else if (VariantMode == VariantModeEnum.ContentPersonalization) { variantIdFromDB = ModuleCommands.OnlineMarketingGetContentPersonalizationVariantId(PageTemplateId, variantName); } // Set the variant id from the database if (variantIdFromDB > 0) { VariantID = variantIdFromDB; IsNewVariant = false; } } } if (!String.IsNullOrEmpty(WebpartId)) { // Get the page info pi = CMSWebPartPropertiesPage.GetPageInfo(this.AliasPath, this.PageTemplateId); if (pi != null) { // Get template pti = pi.PageTemplateInfo; // Get template instance templateInstance = pti.TemplateInstance; // Parent webpart WebPartInfo parentWpi = null; //Before FormInfo FormInfo beforeFI = null; //After FormInfo FormInfo afterFI = null; // Webpart form info FormInfo fi = null; if (!IsNewWebPart) { // Standard zone webPartInstance = pti.GetWebPart(InstanceGUID, WebpartId); // If the web part not found, try to find it among the MVT/CP variants if (webPartInstance == null) { // MVT/CP variant templateInstance.LoadVariants(false, VariantModeEnum.None); webPartInstance = templateInstance.GetWebPart(InstanceGUID, true); // Set the VariantMode according to the selected web part/zone variant if ((webPartInstance != null) && (webPartInstance.ParentZone != null)) { VariantMode = (webPartInstance.VariantMode != VariantModeEnum.None) ? webPartInstance.VariantMode : webPartInstance.ParentZone.VariantMode; } else { VariantMode = VariantModeEnum.None; } } else { // Ensure that the ZoneVarianID is not set when the web part was found in a regural zone. ZoneVariantID = 0; } if ((VariantID > 0) && (webPartInstance != null) && (webPartInstance.PartInstanceVariants != null)) { // Check OnlineMarketing permissions. if (CheckPermissions("Read")) { webPartInstance = webPartInstance.FindVariant(VariantID); } else { // Not authorised for OnlineMarketing - Manage. RedirectToInformation(String.Format(GetString("general.permissionresource"), "Read", (VariantMode == VariantModeEnum.ContentPersonalization) ? "CMS.ContentPersonalization" : "CMS.MVTest")); } } if (webPartInstance == null) { lblInfo.Text = GetString("WebPartProperties.WebPartNotFound"); pnlFormArea.Visible = false; return; } wpi = WebPartInfoProvider.GetWebPartInfo(webPartInstance.WebPartType); form.Mode = FormModeEnum.Update; } // Webpart instance hasn't created yet else { wpi = WebPartInfoProvider.GetWebPartInfo(ValidationHelper.GetInteger(WebpartId, 0)); form.Mode = FormModeEnum.Insert; } // Load parent if (wpi != null) { if (wpi.WebPartParentID > 0) { parentWpi = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); } } // Get the form definition string wpProperties = "<form></form>"; if (wpi != null) { wpProperties = wpi.WebPartProperties; // Use parent webpart if is defined if (parentWpi != null) { wpProperties = parentWpi.WebPartProperties; } // Get before FormInfo if (BeforeFormDefinition == null) { beforeFI = PortalHelper.GetPositionFormInfo((WebPartTypeEnum)wpi.WebPartType, PropertiesPosition.Before); } else { beforeFI = new FormInfo(BeforeFormDefinition); } // Get after FormInfo if (AfterFormDefinition == null) { afterFI = PortalHelper.GetPositionFormInfo((WebPartTypeEnum)wpi.WebPartType, PropertiesPosition.After); } else { afterFI = new FormInfo(AfterFormDefinition); } } // Add 'General' category at the beginning if no one is specified if (!string.IsNullOrEmpty(wpProperties) && (!wpProperties.StartsWith("<form><category", StringComparison.InvariantCultureIgnoreCase))) { wpProperties = wpProperties.Insert(6, "<category name=\"" + GetString("general.general") + "\" />"); } // Get merged web part FormInfo fi = FormHelper.GetWebPartFormInfo(wpi.WebPartName, wpProperties, beforeFI, afterFI, true); // Get datarow with required columns DataRow dr = fi.GetDataRow(); if (IsNewWebPart) { // Load default properties values fi.LoadDefaultValues(dr); // Load overriden system values fi.LoadDefaultValues(dr, wpi.WebPartDefaultValues); // Set control ID FormFieldInfo ffi = fi.GetFormField("WebPartControlID"); if (ffi != null) { ffi.DefaultValue = WebPartZoneInstance.GetUniqueWebPartId(wpi.WebPartName, templateInstance); fi.UpdateFormField("WebPartControlID", ffi); } } // Load values from existing webpart LoadDataRowFromWebPart(dr, webPartInstance); // Set a unique WebPartControlID for athe new variant if (IsNewVariant) { // Set control ID dr["WebPartControlID"] = WebPartZoneInstance.GetUniqueWebPartId(wpi.WebPartName, templateInstance); } // Init the form InitForm(form, dr, fi); AddExportLink(); } } }