From a730825a5ae24ccf4b935a0caf4dc660bbe3296e Mon Sep 17 00:00:00 2001 From: Luis Majano Date: Wed, 31 Jul 2024 14:19:26 -0400 Subject: [PATCH] CONTENTBOX-1511 #resolve Global HTML Saving a new version each time, rather than overwriting --- .../models/system/SettingService.cfc | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/modules/contentbox/models/system/SettingService.cfc b/modules/contentbox/models/system/SettingService.cfc index a69139204..e5f88b4ef 100755 --- a/modules/contentbox/models/system/SettingService.cfc +++ b/modules/contentbox/models/system/SettingService.cfc @@ -517,6 +517,9 @@ component /** * Try to find a setting object by site and name * + * @site The site object, this can be null + * @name The name of the setting + * * @return The setting object or null */ function findSiteSetting( required site, required name ){ @@ -603,7 +606,6 @@ component */ SettingService function bulkSave( struct memento, site ){ var settings = isNull( arguments.site ) ? getAllSettings() : getAllSiteSettings( arguments.site.getSlug() ); - var siteId = arguments.site ?: javacast( "null", 0 ); var newSettings = []; arguments.memento @@ -613,10 +615,13 @@ component } ) // Build out array of settings to save .each( function( key, value ){ - var thisSetting = findWhere( { - name : key, - site : !isNull( siteId ) ? siteId : javacast( "null", "" ) - } ); + var thisSetting = ""; + // Find the setting globally or by site, depending on the context + if( isNull( site ) ){ + thisSetting = findWhere( { name : key } ); + } else { + thisSetting = findSiteSetting( site, key ); + } // Maybe it's a new setting :) if ( isNull( thisSetting ) ) { @@ -626,8 +631,8 @@ component thisSetting.setValue( toString( value ) ); // Site mapping - if ( !isNull( siteId ) ) { - thisSetting.setSite( siteId ); + if ( !isNull( site ) ) { + thisSetting.setSite( site ); } newSettings.append( thisSetting );