This project is read-only.
2
Vote

Datatype Prevalues Not Saving

description

Each time uSiteBuilder is published datatype prevalues are always recreated, causing properties to lose their selected values.

Currently the code is doing the following in DataTypeManager.cs :
if (prevalues.Any())
                {
                    var settingsStorage = new DataEditorSettingsStorage();
                    
                    // updating all settings to those defined in datatype class
                    // If you've exported, all settings will be defined here anyway?
                    settingsStorage.ClearSettings(dtd.Id);
                    settingsStorage.InsertSettings(dtd.Id, prevalues.Select(pre => new Setting<string, string> { Key = pre.Alias, Value = pre.Value }).ToList());
                }
I Have added a small check to see if the values already exist before inserting:
    if (prevalues.Any())
                {
                    var settingsStorage = new DataEditorSettingsStorage();
                    
                    List<Setting<string, string>> settings = settingsStorage.GetSettings(dtd.Id);

                    //only insert settings if they don't already exist
                    foreach (Setting<string, string> setting in settings)
                    {
                        if (!prevalues.Any(p => p.Alias == setting.Key && p.Value == setting.Value))
                        {
                            settingsStorage.InsertSetting(dtd.Id,setting.Key,setting.Value,0);
                        }
                    }
                }

comments

readingdancer wrote Aug 28, 2013 at 10:26 AM

I am currently working on a new release and have added this change, I will update the status as soon as I have committed all my changes.

ProNotion wrote Sep 2, 2013 at 8:18 AM

Thanks Chris, sorry for the delayed reply I only just saw the notification!

dascoba wrote Jan 27, 2014 at 7:35 AM

This completely screwed me over. I built a multinode tree picker wrapper and an embedded content wrapper. The datatypeprevalues for the allowed doctypes in the first, are dyamically built based on base class and a list of documenttype names is set to limit the picker. If I add a new doctype, the list is changed on the next build... the changes above somehow caused my database to have millions of copies of the same prevalue and brought my app down hard. If I revert back then the dropdowns will be overwrittern, hencing loosing the values... the prevalue table is poorly designed.. the alias should not be allowed to be empty because now there is now way to determine 2 values apart... this would solve the problem because we could check against that datatypenodeid and alias.. but since so many aliases are blank and can be duplicated,, the column is useless.

dascoba wrote Jan 27, 2014 at 8:32 AM

I figured out the problem. It's list line:
__
settingsStorage.InsertSetting(dtd.Id,setting.Key,setting.Value,0);__

You should be inserting the prevalue value, not the setting value.
You have to clear out all prevalues if ANY of the values change because the datatype nodeid is the only identifier since aliases can be duplicated.

I changed the code to this:
            var settings = settingsStorage.GetSettings(dtd.Id);

            //only insert settings if they don't already exist
            foreach (var setting in settings.Where(s =>
            {
                // remove bad chars so we have a solid string compare
                var sValue = System.Text.RegularExpressions.Regex.Replace(s.Value, @"[^a-zA-Z 0-9'.@]", string.Empty).Trim();
                var values = (
                    from p in prevalues
                    let pValue = System.Text.RegularExpressions.Regex.Replace(p.Value, @"[^a-zA-Z 0-9'.@]", string.Empty).Trim()
                    where pValue.Equals(sValue, StringComparison.OrdinalIgnoreCase) && p.Alias.Equals(s.Key, StringComparison.OrdinalIgnoreCase)
                    select p);

                var valueExists = values.Any();
                return !valueExists;
            }))
            {
                // If any of the prevalues have changed or don't exists, then we clear all the settings and re-add
                settingsStorage.ClearSettings(dtd.Id);
                settingsStorage.InsertSettings(dtd.Id, prevalues.Select(pre => new Setting<string, string> { Key = pre.Alias, Value = pre.Value }).ToList());
            }