@@ -2009,15 +2009,15 @@ private bool PublishBranch_PublishCultures(IContent content, HashSet<string> cul
2009
2009
&& _propertyValidationService . Value . IsPropertyDataValid ( content , out _ , _cultureImpactFactory . ImpactInvariant ( ) ) ;
2010
2010
}
2011
2011
2012
- // utility 'ShouldPublish' func used by SaveAndPublishBranch
2013
- private static HashSet < string > ? PublishBranch_ShouldPublish ( ref HashSet < string > ? cultures , string c , bool published , bool edited , bool isRoot , bool force )
2012
+ // utility 'ShouldPublish' func used by PublishBranch
2013
+ private static HashSet < string > ? PublishBranch_ShouldPublish ( ref HashSet < string > ? cultures , string c , bool published , bool edited , bool isRoot , PublishBranchFilter publishBranchFilter )
2014
2014
{
2015
2015
// if published, republish
2016
2016
if ( published )
2017
2017
{
2018
2018
cultures ??= new HashSet < string > ( ) ; // empty means 'already published'
2019
2019
2020
- if ( edited )
2020
+ if ( edited || publishBranchFilter . HasFlag ( PublishBranchFilter . ForceRepublish ) )
2021
2021
{
2022
2022
cultures . Add ( c ) ; // <culture> means 'republish this culture'
2023
2023
}
@@ -2026,7 +2026,7 @@ private bool PublishBranch_PublishCultures(IContent content, HashSet<string> cul
2026
2026
}
2027
2027
2028
2028
// if not published, publish if force/root else do nothing
2029
- if ( ! force && ! isRoot )
2029
+ if ( ! publishBranchFilter . HasFlag ( PublishBranchFilter . IncludeUnpublished ) && ! isRoot )
2030
2030
{
2031
2031
return cultures ; // null means 'nothing to do'
2032
2032
}
@@ -2054,16 +2054,18 @@ public IEnumerable<PublishResult> SaveAndPublishBranch(IContent content, bool fo
2054
2054
var isRoot = c . Id == content . Id ;
2055
2055
HashSet < string > ? culturesToPublish = null ;
2056
2056
2057
+ PublishBranchFilter publishBranchFilter = force ? PublishBranchFilter . IncludeUnpublished : PublishBranchFilter . Default ;
2058
+
2057
2059
// invariant content type
2058
2060
if ( ! c . ContentType . VariesByCulture ( ) )
2059
2061
{
2060
- return PublishBranch_ShouldPublish ( ref culturesToPublish , "*" , c . Published , c . Edited , isRoot , force ) ;
2062
+ return PublishBranch_ShouldPublish ( ref culturesToPublish , "*" , c . Published , c . Edited , isRoot , publishBranchFilter ) ;
2061
2063
}
2062
2064
2063
2065
// variant content type, specific culture
2064
2066
if ( culture != "*" )
2065
2067
{
2066
- return PublishBranch_ShouldPublish ( ref culturesToPublish , culture , c . IsCulturePublished ( culture ) , c . IsCultureEdited ( culture ) , isRoot , force ) ;
2068
+ return PublishBranch_ShouldPublish ( ref culturesToPublish , culture , c . IsCulturePublished ( culture ) , c . IsCultureEdited ( culture ) , isRoot , publishBranchFilter ) ;
2067
2069
}
2068
2070
2069
2071
// variant content type, all cultures
@@ -2073,7 +2075,7 @@ public IEnumerable<PublishResult> SaveAndPublishBranch(IContent content, bool fo
2073
2075
// others will have to 'republish this culture'
2074
2076
foreach ( var x in c . AvailableCultures )
2075
2077
{
2076
- PublishBranch_ShouldPublish ( ref culturesToPublish , x , c . IsCulturePublished ( x ) , c . IsCultureEdited ( x ) , isRoot , force ) ;
2078
+ PublishBranch_ShouldPublish ( ref culturesToPublish , x , c . IsCulturePublished ( x ) , c . IsCultureEdited ( x ) , isRoot , publishBranchFilter ) ;
2077
2079
}
2078
2080
2079
2081
return culturesToPublish ;
@@ -2085,23 +2087,31 @@ public IEnumerable<PublishResult> SaveAndPublishBranch(IContent content, bool fo
2085
2087
: null ; // null means 'nothing to do'
2086
2088
}
2087
2089
2088
- return PublishBranch ( content , force , ShouldPublish , PublishBranch_PublishCultures , userId ) ;
2090
+ return PublishBranch ( content , ShouldPublish , PublishBranch_PublishCultures , userId ) ;
2089
2091
}
2090
2092
2091
2093
[ Obsolete ( $ "This method no longer saves content, only publishes it. Please use { nameof ( PublishBranch ) } instead. Will be removed in V16") ]
2092
2094
public IEnumerable < PublishResult > SaveAndPublishBranch ( IContent content , bool force , string [ ] cultures , int userId = Constants . Security . SuperUserId )
2093
- => PublishBranch ( content , force , cultures , userId ) ;
2095
+ => PublishBranch ( content , force ? PublishBranchFilter . IncludeUnpublished : PublishBranchFilter . Default , cultures , userId ) ;
2094
2096
2095
2097
/// <inheritdoc />
2098
+ [ Obsolete ( "This method is not longer used as the 'force' parameter has been split into publishing unpublished and force re-published. Please use the overload containing parameters for those options instead. Will be removed in V16" ) ]
2096
2099
public IEnumerable < PublishResult > PublishBranch ( IContent content , bool force , string [ ] cultures , int userId = Constants . Security . SuperUserId )
2100
+ => PublishBranch ( content , force ? PublishBranchFilter . IncludeUnpublished : PublishBranchFilter . Default , cultures , userId ) ;
2101
+
2102
+ /// <inheritdoc />
2103
+ public IEnumerable < PublishResult > PublishBranch ( IContent content , PublishBranchFilter publishBranchFilter , string [ ] cultures , int userId = Constants . Security . SuperUserId )
2097
2104
{
2098
2105
// note: EditedValue and PublishedValue are objects here, so it is important to .Equals()
2099
2106
// and not to == them, else we would be comparing references, and that is a bad thing
2100
- cultures ??= Array . Empty < string > ( ) ;
2101
2107
2102
- if ( content . ContentType . VariesByCulture ( ) is false && cultures . Length == 0 )
2108
+ cultures = EnsureCultures ( content , cultures ) ;
2109
+
2110
+ string ? defaultCulture ;
2111
+ using ( ICoreScope scope = ScopeProvider . CreateCoreScope ( ) )
2103
2112
{
2104
- cultures = new [ ] { "*" } ;
2113
+ defaultCulture = _languageRepository . GetDefaultIsoCode ( ) ;
2114
+ scope . Complete ( ) ;
2105
2115
}
2106
2116
2107
2117
// determines cultures to be published
@@ -2114,34 +2124,50 @@ public IEnumerable<PublishResult> PublishBranch(IContent content, bool force, st
2114
2124
// invariant content type
2115
2125
if ( ! c . ContentType . VariesByCulture ( ) )
2116
2126
{
2117
- return PublishBranch_ShouldPublish ( ref culturesToPublish , "*" , c . Published , c . Edited , isRoot , force ) ;
2127
+ return PublishBranch_ShouldPublish ( ref culturesToPublish , "*" , c . Published , c . Edited , isRoot , publishBranchFilter ) ;
2118
2128
}
2119
2129
2120
2130
// variant content type, specific cultures
2121
2131
if ( c . Published )
2122
2132
{
2123
2133
// then some (and maybe all) cultures will be 'already published' (unless forcing),
2124
2134
// others will have to 'republish this culture'
2125
- foreach ( var x in cultures )
2135
+ foreach ( var culture in cultures )
2126
2136
{
2127
- PublishBranch_ShouldPublish ( ref culturesToPublish , x , c . IsCulturePublished ( x ) , c . IsCultureEdited ( x ) , isRoot , force ) ;
2137
+ // We could be publishing a parent invariant page, with descendents that are variant.
2138
+ // So convert the invariant request to a request for the default culture.
2139
+ var specificCulture = culture == "*" ? defaultCulture : culture ;
2140
+
2141
+ PublishBranch_ShouldPublish ( ref culturesToPublish , specificCulture , c . IsCulturePublished ( specificCulture ) , c . IsCultureEdited ( specificCulture ) , isRoot , publishBranchFilter ) ;
2128
2142
}
2129
2143
2130
2144
return culturesToPublish ;
2131
2145
}
2132
2146
2133
- // if not published, publish if force /root else do nothing
2134
- return force || isRoot
2147
+ // if not published, publish if forcing unpublished /root else do nothing
2148
+ return publishBranchFilter . HasFlag ( PublishBranchFilter . IncludeUnpublished ) || isRoot
2135
2149
? new HashSet < string > ( cultures ) // means 'publish specified cultures'
2136
2150
: null ; // null means 'nothing to do'
2137
2151
}
2138
2152
2139
- return PublishBranch ( content , force , ShouldPublish , PublishBranch_PublishCultures , userId ) ;
2153
+ return PublishBranch ( content , ShouldPublish , PublishBranch_PublishCultures , userId ) ;
2140
2154
}
2141
2155
2156
+ private static string [ ] EnsureCultures ( IContent content , string [ ] cultures )
2157
+ {
2158
+ // Ensure consistent indication of "all cultures" for variant content.
2159
+ if ( content . ContentType . VariesByCulture ( ) is false && ProvidedCulturesIndicatePublishAll ( cultures ) )
2160
+ {
2161
+ cultures = [ "*" ] ;
2162
+ }
2163
+
2164
+ return cultures ;
2165
+ }
2166
+
2167
+ private static bool ProvidedCulturesIndicatePublishAll ( string [ ] cultures ) => cultures . Length == 0 || ( cultures . Length == 1 && cultures [ 0 ] == "invariant" ) ;
2168
+
2142
2169
internal IEnumerable < PublishResult > PublishBranch (
2143
2170
IContent document ,
2144
- bool force ,
2145
2171
Func < IContent , HashSet < string > ? > shouldPublish ,
2146
2172
Func < IContent , HashSet < string > , IReadOnlyCollection < ILanguage > , bool > publishCultures ,
2147
2173
int userId = Constants . Security . SuperUserId )
@@ -3116,7 +3142,7 @@ internal IEnumerable<IContent> GetPublishedDescendantsLocked(IContent content)
3116
3142
{
3117
3143
var pathMatch = content . Path + "," ;
3118
3144
IQuery < IContent > query = Query < IContent > ( )
3119
- . Where ( x => x . Id != content . Id && x . Path . StartsWith ( pathMatch ) /*&& x .Trashed == false*/ ) ;
3145
+ . Where ( x => x . Id != content . Id && x . Path . StartsWith ( pathMatch ) /*&& culture .Trashed == false*/ ) ;
3120
3146
IEnumerable < IContent > contents = _documentRepository . Get ( query ) ;
3121
3147
3122
3148
// beware! contents contains all published version below content
0 commit comments