@@ -55,45 +55,36 @@ class ContentReleaseManager
5555
5656 public function startIncrementalContentRelease (string $ currentContentReleaseId = null , Workspace $ workspace = null , array $ additionalVariables = []): ContentReleaseIdentifier
5757 {
58- $ redis = $ this ->redisClientManager ->getPrimaryRedis ();
59- if ($ currentContentReleaseId ) {
60- $ currentContentReleaseId = $ redis ->get (self ::REDIS_CURRENT_RELEASE_KEY );
61- }
62-
6358 $ contentReleaseId = ContentReleaseIdentifier::create ();
59+
6460 // the currentContentReleaseId is not used in any pipeline step in this package, but is a common need in other
6561 // use cases in extensions, e.g. calculating the differences between current and new release
6662 $ this ->prunnerApiService ->schedulePipeline (PipelineName::create ('do_content_release ' ), array_merge ($ additionalVariables , [
6763 'contentReleaseId ' => $ contentReleaseId ,
68- 'currentContentReleaseId ' => $ currentContentReleaseId ?: self :: NO_PREVIOUS_RELEASE ,
64+ 'currentContentReleaseId ' => $ this -> resolveCurrentContentReleaseId ( $ currentContentReleaseId) ,
6965 'validate ' => true ,
70- 'workspaceName ' => $ workspace ? $ workspace ->getName () : 'live ' ,
71- 'accountId ' => $ this ->securityContext ->isInitialized ()
72- ? $ this ->securityContext ->getAccount ()->getAccountIdentifier () :
73- null ,
66+ 'workspaceName ' => $ workspace !== null ? $ workspace ->getName () : 'live ' ,
67+ 'accountId ' => $ this ->getAccountId (),
7468 ]));
69+
7570 return $ contentReleaseId ;
7671 }
7772
7873 // the validate parameter can be used to intentionally skip the validation step for this release
7974 public function startFullContentRelease (bool $ validate = true , string $ currentContentReleaseId = null , Workspace $ workspace = null , array $ additionalVariables = []): ContentReleaseIdentifier
8075 {
81- $ redis = $ this ->redisClientManager ->getPrimaryRedis ();
82- if ($ currentContentReleaseId ) {
83- $ currentContentReleaseId = $ redis ->get (self ::REDIS_CURRENT_RELEASE_KEY );
84- }
85-
8676 $ contentReleaseId = ContentReleaseIdentifier::create ();
77+
8778 $ this ->contentCache ->flush ();
79+
8880 $ this ->prunnerApiService ->schedulePipeline (PipelineName::create ('do_content_release ' ), array_merge ($ additionalVariables , [
8981 'contentReleaseId ' => $ contentReleaseId ,
90- 'currentContentReleaseId ' => $ currentContentReleaseId ?: self :: NO_PREVIOUS_RELEASE ,
82+ 'currentContentReleaseId ' => $ this -> resolveCurrentContentReleaseId ( $ currentContentReleaseId) ,
9183 'validate ' => $ validate ,
92- 'workspaceName ' => $ workspace ? $ workspace ->getName () : 'live ' ,
93- 'accountId ' => $ this ->securityContext ->isInitialized ()
94- ? $ this ->securityContext ->getAccount ()->getAccountIdentifier () :
95- null ,
84+ 'workspaceName ' => $ workspace !== null ? $ workspace ->getName () : 'live ' ,
85+ 'accountId ' => $ this ->getAccountId (),
9686 ]));
87+
9788 return $ contentReleaseId ;
9889 }
9990
@@ -134,4 +125,29 @@ public function toggleConfigEpoch(RedisInstanceIdentifier $redisInstanceIdentifi
134125 $ redis ->set ('contentStore:configEpoch ' , $ currentConfigEpochConfig );
135126 }
136127 }
128+
129+ private function resolveCurrentContentReleaseId (?string $ currentContentReleaseId ): string
130+ {
131+ if ($ currentContentReleaseId !== null ) {
132+ return $ currentContentReleaseId ;
133+ }
134+
135+ $ redis = $ this ->redisClientManager ->getPrimaryRedis ();
136+ $ currentContentReleaseIdFromRedis = $ redis ->get (self ::REDIS_CURRENT_RELEASE_KEY );
137+
138+ if ($ currentContentReleaseIdFromRedis !== false ) {
139+ return $ currentContentReleaseIdFromRedis ;
140+ }
141+
142+ return self ::NO_PREVIOUS_RELEASE ;
143+ }
144+
145+ private function getAccountId (): ?string
146+ {
147+ if ($ this ->securityContext ->isInitialized ()) {
148+ return $ this ->securityContext ->getAccount ()->getAccountIdentifier ();
149+ }
150+
151+ return null ;
152+ }
137153}
0 commit comments