@@ -642,6 +642,46 @@ private function canPerformEventTypeTransition(SummitEventType $old_event_type,
642642 private function saveOrUpdateEvent (Summit $ summit , array $ data , $ event_id = null )
643643 {
644644
645+
646+ // check first if there is an upgrade or not
647+
648+ $ res = $ this ->tx_service ->transaction (function () use ($ summit , $ data , $ event_id ) {
649+ $ event_type = null ;
650+ if (isset ($ data ['type_id ' ])) {
651+ $ event_type = $ summit ->getEventType (intval ($ data ['type_id ' ]));
652+ if (is_null ($ event_type )) {
653+ throw new EntityNotFoundException (sprintf ("event type id %s does not exists! " , $ data ['type_id ' ]));
654+ }
655+ }
656+
657+ if (!is_null ($ event_id ) && $ event_id > 0 ) {
658+ $ event = $ this ->event_repository ->getByIdRefreshed ($ event_id );
659+ if (is_null ($ event ))
660+ throw new ValidationException (sprintf ("event id %s does not exists! " , $ event_id ));
661+ $ old_event_type = $ event ->getType ();
662+
663+ // check event type transition ...
664+
665+ if (!is_null ($ event_type )) {
666+
667+ if ($ old_event_type ->getClassName () != $ event_type ->getClassName () && $ event_type instanceof PresentationType) {
668+ Log::debug (sprintf ("SummitService::saveOrUpdateEvent promoting event %s 2 presentation ... " , $ event_id ));
669+ $ event ->promote2Presentation ($ event_type );
670+ return $ event ;
671+ }
672+ }
673+ }
674+ return null ;
675+ });
676+
677+ // we performed an upgrade, return the event
678+ if (!is_null ($ res ))
679+ {
680+ return $ this ->tx_service ->transaction (function () use ($ summit , $ data , $ event_id ) {
681+ return $ this ->event_repository ->getByIdRefreshed ($ event_id );
682+ });
683+ }
684+
645685 return $ this ->tx_service ->transaction (function () use ($ summit , $ data , $ event_id ) {
646686
647687 Log::debug
@@ -689,25 +729,25 @@ private function saveOrUpdateEvent(Summit $summit, array $data, $event_id = null
689729
690730 // existing event
691731
692- if (!is_null ($ event_id ) && intval ( $ event_id) > 0 ) {
693- $ event = $ this ->event_repository ->getById ($ event_id );
732+ if (!is_null ($ event_id ) && $ event_id > 0 ) {
733+ $ event = $ this ->event_repository ->getByIdRefreshed ($ event_id );
694734 if (is_null ($ event ))
695735 throw new ValidationException (sprintf ("event id %s does not exists! " , $ event_id ));
696736 $ old_event_type = $ event ->getType ();
697737
698738 // check event type transition ...
699739
700740 if (!is_null ($ event_type ) && !$ this ->canPerformEventTypeTransition ($ old_event_type , $ event_type )) {
701- throw new ValidationException
702- (
703- sprintf
741+ throw new ValidationException
704742 (
705- "invalid event type transition for event id %s ( from %s to %s) " ,
706- $ event_id ,
707- $ old_event_type ->getType (),
708- $ event_type ->getType ()
709- )
710- );
743+ sprintf
744+ (
745+ "invalid event type transition for event id %s ( from %s to %s) " ,
746+ $ event_id ,
747+ $ old_event_type ->getType (),
748+ $ event_type ->getType ()
749+ )
750+ );
711751 }
712752 if (is_null ($ event_type )) $ event_type = $ old_event_type ;
713753 }
0 commit comments