Skip to content

Commit f4e0d34

Browse files
committed
CONTENTBOX-1540 Resolve - Fix mutation of content versions caused by activeContentVersions property - even though it was marked as non-insert, non-update
1 parent 7ea5b86 commit f4e0d34

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

box.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name":"ContentBox Tester Site",
3-
"version":"6.1.0",
3+
"version":"6.1.1",
44
"author":"Ortus Solutions <info@ortussolutions.com>",
55
"shortDescription":"A tester site for developing the ContentBox Modular CMS",
66
"type":"cms",

modules/contentbox/models/content/BaseContent.cfc

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -320,17 +320,7 @@ component
320320

321321
property
322322
name ="activeContentVersions"
323-
singularName="activeContentVersion"
324-
fieldtype ="one-to-many"
325-
type ="array"
326-
lazy ="extra"
327-
where ="isActive = 1"
328-
batchsize ="2"
329-
cfc ="contentbox.models.content.ContentVersion"
330-
orderby ="version desc"
331-
fkcolumn ="FK_contentID"
332-
insert =false
333-
update =false;
323+
persistent = "false";
334324

335325
// M20 -> Parent Page loaded as a proxy
336326
property
@@ -811,13 +801,6 @@ component
811801
){
812802
// lock it for new content creation to avoid version overlaps
813803
lock name="contentbox.addNewContentVersion.#getSlug()#" type="exclusive" timeout="10" throwOnTimeout=true {
814-
// get a new version object with our incoming content + relationships
815-
var oNewVersion = variables.contentVersionService.new( {
816-
content : arguments.content,
817-
changelog : arguments.changelog,
818-
author : arguments.author,
819-
relatedContent : this
820-
} );
821804

822805
// Do we already have an active version?
823806
if ( hasActiveContent() ) {
@@ -826,9 +809,17 @@ component
826809
maxContentVersionChecks();
827810
}
828811
// deactive the curent version, we do it after in case the content versions check kick off a transaction
829-
getActiveContent().setIsActive( false );
812+
getContentVersions().filter( ( version ) => version.getIsActive() ).each( ( version ) => version.setIsActive( false ) );
830813
}
831814

815+
// get a new version object with our incoming content + relationships
816+
var oNewVersion = variables.contentVersionService.new( {
817+
content : arguments.content,
818+
changelog : arguments.changelog,
819+
author : arguments.author,
820+
relatedContent : this
821+
} );
822+
832823
// Get the latest content version, to increase the new version number, collection is ordered by 'version' descending
833824
if ( hasContentVersion() ) {
834825
oNewVersion.setVersion( variables.contentVersions[ 1 ].getVersion() + 1 );
@@ -844,7 +835,7 @@ component
844835
// Update our active content versions, even though they are not persisted
845836
param variables.activeContentVersions = [];
846837
variables.activeContentVersions.clear();
847-
addActiveContentVersion( oNewVersion );
838+
variables.activeContentVersions.append( oNewVersion );
848839
}
849840
return this;
850841
}
@@ -1146,7 +1137,7 @@ component
11461137
// If we don't have any versions, send back a new one
11471138
if ( variables.keyExists( "activeContent" ) && !isSimpleValue( variables.activeContent ) ) {
11481139
return arguments.asString ? variables.activeContent.getContent() : variables.activeContent;
1149-
} else if ( !isLoaded() || !hasActiveContentVersion() ) {
1140+
} else if ( !isLoaded() ) {
11501141
return arguments.asString ? "" : variables.contentVersionService.new();
11511142
} else if ( arguments.asString ) {
11521143
var activeContentStruct = contentVersionService
@@ -1160,10 +1151,15 @@ component
11601151
.first();
11611152
return activeContentStruct[ "content" ];
11621153
} else {
1163-
return getContentVersions().filter( ( version ) => version.getIsActive() ).first();
1154+
var activeVersions = getContentVersions().filter( ( version ) => version.getIsActive() );
1155+
return activeVersions.len() ? activeVersions.first() : variables.contentVersionService.new();
11641156
}
11651157
}
11661158

1159+
function hasActiveContentVersion(){
1160+
return ( isLoaded() && hasContentVersion() && getActiveContent().getIsActive() );
1161+
}
1162+
11671163
/**
11681164
* Set the active content version manually, usually great for previews
11691165
*

0 commit comments

Comments
 (0)