@@ -112,8 +112,7 @@ public async Task SyncAsync(CancellationToken cancellationToken = default)
112112
113113 var eventContent = GetOrCreateEvent ( existingEvents , references . EventsContainerId , eventPlan ) ;
114114 SaveEventContent ( eventContent , eventPlan ) ;
115- _contentService . Save ( eventContent , SystemUserId ) ;
116- var presentationsToPublish = new List < IContent > ( ) ;
115+ SaveAndPublishContent ( eventContent , "event" , clearSchedule : true ) ;
117116
118117 var existingPresentations = GetChildren ( eventContent . Id )
119118 . Where ( content => string . Equals ( content . ContentType . Alias , PresentationAlias , StringComparison . Ordinal ) )
@@ -136,14 +135,7 @@ public async Task SyncAsync(CancellationToken cancellationToken = default)
136135
137136 var presentationContent = GetOrCreatePresentation ( existingPresentations , eventContent . Id , presentationPlan ) ;
138137 SavePresentationContent ( presentationContent , references . SpringfieldDevsGroupKey , enrichedPresentationPlan , meetupMatch ? . EventUrl ) ;
139- _contentService . Save ( presentationContent , SystemUserId ) ;
140- presentationsToPublish . Add ( presentationContent ) ;
141- }
142-
143- PublishContent ( eventContent , "event" , clearSchedule : true ) ;
144- foreach ( var presentationContent in presentationsToPublish )
145- {
146- PublishContent ( presentationContent , "presentation" ) ;
138+ SaveAndPublishContent ( presentationContent , "presentation" ) ;
147139 }
148140 }
149141 }
@@ -262,29 +254,31 @@ private async Task<IReadOnlyList<ImportedPresenterPlan>> ImportPresenterImagesAs
262254 return enrichedPresenters ;
263255 }
264256
265- private void PublishContent ( IContent content , string contentKind , bool clearSchedule = false )
257+ private void SaveAndPublishContent ( IContent content , string contentKind , bool clearSchedule = false )
266258 {
267- if ( clearSchedule )
259+ if ( content . IsDirty ( ) == false && content . IsCultureEdited ( null ! ) == false )
260+ {
261+ return ;
262+ }
263+
264+ if ( clearSchedule && content . HasIdentity )
268265 {
269266 _contentService . PersistContentSchedule ( content , new ContentScheduleCollection ( ) ) ;
270267 }
271268
272- var publishResult = _contentService . Publish ( content , [ "*" ] , SystemUserId ) ;
269+ var publishResult = _contentService . SaveAndPublish ( content , [ ] , SystemUserId ) ;
273270 if ( publishResult . Success )
274271 {
275272 _logger . LogInformation (
276- "Published {ContentKind} {ContentName} with result {PublishResult}." ,
273+ "Saved and published {ContentKind} {ContentName} with result {PublishResult}." ,
277274 contentKind ,
278275 content . Name ,
279276 publishResult . Result ) ;
280277 return ;
281278 }
282279
283- _logger . LogWarning (
284- "Failed to publish {ContentKind} {ContentName}. Publish result was {PublishResult}." ,
285- contentKind ,
286- content . Name ,
287- publishResult . Result ) ;
280+ throw new InvalidOperationException (
281+ $ "Failed to save and publish { contentKind } { content . Name } . Publish result was { publishResult . Result } .") ;
288282 }
289283
290284 private IReadOnlyList < IContent > GetChildren ( int parentId )
0 commit comments