Exemple #1
0
 public void ResetLanguage(String resetToLang)
 {
     if (resetToLang != DataLangRecord.Lang)
     {
         var resetToLangData = CategoryUtils.GetCategoryData(DataRecord.ItemID, resetToLang);
         DataLangRecord.XMLData = resetToLangData.DataLangRecord.XMLData;
         _objCtrl.Update(DataLangRecord);
     }
 }
Exemple #2
0
        public int Validate()
        {
            var errorcount = 0;

            // default any undefined group type as category (I think quickcategory v1.0.0 plugin causes this)
            if (DataRecord.GetXmlProperty("genxml/dropdownlist/ddlgrouptype") == "")
            {
                DataRecord.SetXmlProperty("genxml/dropdownlist/ddlgrouptype", "cat");
                _objCtrl.Update(DataRecord);
            }

            if (GroupType == "cat")
            {
                // the base category ref cannot have language dependant refs, we therefore just use a unique key
                var catref = DataRecord.GetXmlProperty("genxml/textbox/txtcategoryref");
                if (catref == "" || DataRecord.GUIDKey == "")
                {
                    catref = Utils.GetUniqueKey().ToLower();
                    DataRecord.SetXmlProperty("genxml/textbox/txtcategoryref", catref);
                    DataRecord.GUIDKey = catref;
                    errorcount        += 1;
                }

                if (DataRecord.GetXmlProperty("genxml/dropdownlist/ddlparentcatid") != DataRecord.ParentItemId.ToString())
                {
                    DataRecord.SetXmlProperty("genxml/dropdownlist/ddlparentcatid", DataRecord.ParentItemId.ToString());
                }
            }

            DataRecord.ValidateXmlFormat();

            if (DataLangRecord == null)
            {
                // we have no datalang record for this language, so get an existing one and save it.
                var l = _objCtrl.GetList(_portalId, -1, "CATEGORYLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString(""));
                if (l.Count > 0)
                {
                    DataLangRecord        = (NBrightInfo)l[0].Clone();
                    DataLangRecord.ItemID = -1;
                    DataLangRecord.Lang   = _lang;
                    DataLangRecord.ValidateXmlFormat();
                    _objCtrl.Update(DataLangRecord);
                }
            }

            // fix image
            var imgpath       = DataRecord.GetXmlProperty("genxml/hidden/imagepath");
            var imgurl        = DataRecord.GetXmlProperty("genxml/hidden/imageurl");
            var imagefilename = Path.GetFileName(imgpath);

            if (StoreSettings.Current != null) // current setting not valid in Scheduler.
            {
                if (!imgpath.StartsWith(StoreSettings.Current.FolderImagesMapPath))
                {
                    DataRecord.SetXmlProperty("genxml/hidden/imagepath", StoreSettings.Current.FolderImagesMapPath.TrimEnd('\\') + "\\" + imagefilename);
                    errorcount += 1;
                }
                if (imagefilename == "")
                {
                    DataRecord.SetXmlProperty("genxml/hidden/imagepath", "");
                    errorcount += 1;
                }
                if (!imgurl.StartsWith(StoreSettings.Current.FolderImages))
                {
                    DataRecord.SetXmlProperty("genxml/hidden/imageurl", StoreSettings.Current.FolderImages.TrimEnd('/') + "/" + imagefilename);
                    errorcount += 1;
                }
            }
            if (imagefilename == "")
            {
                DataRecord.SetXmlProperty("genxml/hidden/imageurl", "");
                errorcount += 1;
            }

            // check guidkey is correct
            if (DataRecord.GUIDKey != CategoryRef)
            {
                DataRecord.GUIDKey = CategoryRef;
                errorcount        += 1;
            }

            if (errorcount > 0)
            {
                _objCtrl.Update(DataRecord);                 // update if we find a error
            }
            // fix langauge records
            foreach (var lang in DnnUtils.GetCultureCodeList(_portalId))
            {
                var l = _objCtrl.GetList(_portalId, -1, "CATEGORYLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'");
                if (l.Count == 0 && DataLangRecord != null)
                {
                    var nbi = (NBrightInfo)DataLangRecord.Clone();
                    nbi.ItemID = -1;
                    nbi.Lang   = lang;
                    _objCtrl.Update(nbi);
                    errorcount += 1;
                }
                if (l.Count > 1)
                {
                    // we have more records than shoudl exists, remove any old ones.
                    var l2 = _objCtrl.GetList(_portalId, -1, "CATEGORYLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'", "order by Modifieddate desc");
                    var lp = 1;
                    foreach (var i in l2)
                    {
                        if (lp >= 2)
                        {
                            _objCtrl.Delete(i.ItemID);
                        }
                        lp += 1;
                    }
                }
            }

            // Build langauge refs
            if (GroupType == "cat")
            {
                var updaterequired = CategoryUtils.ValidateLangaugeRef(_portalId, CategoryId);
                if (updaterequired)
                {
                    // the catref has been updated, so reload the datarecord
                    DataLangRecord = _objCtrl.GetDataLang(CategoryId, _lang);
                }
            }

            // fix groups with mismatching ddlgrouptype
            if (GroupType != "cat")
            {
                var grp = _objCtrl.Get(DataRecord.ParentItemId, "GROUP");
                if (grp != null)
                {
                    if (grp.GUIDKey != GroupType)
                    {
                        DataRecord.SetXmlProperty("genxml/dropdownlist/ddlgrouptype", grp.GUIDKey);
                        _objCtrl.Update(DataRecord);
                        errorcount += 1;
                    }
                }
            }

            // update shared product if flagged
            // possible call from scheduler, no storesetting in that case.
            if ((StoreSettings.Current != null) && StoreSettings.Current.GetBool(StoreSettingKeys.sharecategories) && DataRecord.PortalId >= 0)
            {
                DataRecord.PortalId = -1;
                _objCtrl.Update(DataRecord);
                if (DataLangRecord != null)
                {
                    DataLangRecord.PortalId = -1;
                    _objCtrl.Update(DataLangRecord);
                }
            }


            return(errorcount);
        }
Exemple #3
0
        public int Validate()
        {
            var errorcount = 0;

            // default any undefined group type as category (I think quickcategory v1.0.0 plugin causes this)
            if (DataRecord.GetXmlProperty("genxml/dropdownlist/ddlgrouptype") == "")
            {
                DataRecord.SetXmlProperty("genxml/dropdownlist/ddlgrouptype", "cat");
                _objCtrl.Update(DataRecord);
            }

            if (GroupType == "cat")
            {
                // the base category ref cannot have language dependant refs, we therefore just use a unique key
                var catref = DataRecord.GetXmlProperty("genxml/textbox/txtcategoryref");
                if (catref == "" || DataRecord.GUIDKey == "")
                {
                    catref = Utils.GetUniqueKey().ToLower();
                    DataRecord.SetXmlProperty("genxml/textbox/txtcategoryref", catref);
                    DataRecord.GUIDKey = catref;
                    errorcount        += 1;
                }

                if (DataRecord.GetXmlProperty("genxml/dropdownlist/ddlparentcatid") != DataRecord.ParentItemId.ToString())
                {
                    DataRecord.SetXmlProperty("genxml/dropdownlist/ddlparentcatid", DataRecord.ParentItemId.ToString());
                }
            }

            DataRecord.ValidateXmlFormat();

            // fix image
            var imgpath       = DataRecord.GetXmlProperty("genxml/hidden/imagepath");
            var imgurl        = DataRecord.GetXmlProperty("genxml/hidden/imageurl");
            var imagefilename = Path.GetFileName(imgpath);

            if (StoreSettings.Current != null) // current setting not valid in Scheduler.
            {
                if (!imgpath.StartsWith(StoreSettings.Current.FolderImagesMapPath))
                {
                    DataRecord.SetXmlProperty("genxml/hidden/imagepath", StoreSettings.Current.FolderImagesMapPath.TrimEnd('\\') + "\\" + imagefilename);
                    errorcount += 1;
                }
                if (imagefilename == "")
                {
                    DataRecord.SetXmlProperty("genxml/hidden/imagepath", "");
                    errorcount += 1;
                }
                if (!imgurl.StartsWith(StoreSettings.Current.FolderImages))
                {
                    DataRecord.SetXmlProperty("genxml/hidden/imageurl", StoreSettings.Current.FolderImages.TrimEnd('/') + "/" + imagefilename);
                    errorcount += 1;
                }
            }
            if (imagefilename == "")
            {
                DataRecord.SetXmlProperty("genxml/hidden/imageurl", "");
                errorcount += 1;
            }

            // check guidkey is correct
            if (DataRecord.GUIDKey != CategoryRef)
            {
                DataRecord.GUIDKey = CategoryRef;
                errorcount        += 1;
            }

            if (errorcount > 0)
            {
                _objCtrl.Update(DataRecord);                 // update if we find a error
            }
            // Build langauge refs
            if (GroupType == "cat")
            {
                var updaterequired = CategoryUtils.ValidateLangaugeRef(_portalId, CategoryId);
                if (updaterequired)
                {
                    // the catref has been updated, so reload the datarecord
                    DataLangRecord = _objCtrl.GetDataLang(CategoryId, _lang);
                }
            }

            // fix groups with mismatching ddlgrouptype
            if (GroupType != "cat")
            {
                var grp = _objCtrl.Get(DataRecord.ParentItemId, "GROUP");
                if (grp != null && grp.TypeCode == "GROUP")
                {
                    if (grp.GUIDKey != GroupType)
                    {
                        DataRecord.SetXmlProperty("genxml/dropdownlist/ddlgrouptype", grp.GUIDKey);
                        _objCtrl.Update(DataRecord);
                        errorcount += 1;
                    }
                }
            }

            // update shared product if flagged
            // possible call from scheduler, no storesetting in that case.
            if ((StoreSettings.Current != null) && StoreSettings.Current.GetBool(StoreSettingKeys.sharecategories) && DataRecord.PortalId >= 0)
            {
                DataRecord.PortalId = -1;
                _objCtrl.Update(DataRecord);
                if (DataLangRecord != null)
                {
                    DataLangRecord.PortalId = -1;
                    _objCtrl.Update(DataLangRecord);
                }
            }


            return(errorcount);
        }