@@ -55,45 +55,36 @@ class ContentReleaseManager
55
55
56
56
public function startIncrementalContentRelease (string $ currentContentReleaseId = null , Workspace $ workspace = null , array $ additionalVariables = []): ContentReleaseIdentifier
57
57
{
58
- $ redis = $ this ->redisClientManager ->getPrimaryRedis ();
59
- if ($ currentContentReleaseId ) {
60
- $ currentContentReleaseId = $ redis ->get (self ::REDIS_CURRENT_RELEASE_KEY );
61
- }
62
-
63
58
$ contentReleaseId = ContentReleaseIdentifier::create ();
59
+
64
60
// the currentContentReleaseId is not used in any pipeline step in this package, but is a common need in other
65
61
// use cases in extensions, e.g. calculating the differences between current and new release
66
62
$ this ->prunnerApiService ->schedulePipeline (PipelineName::create ('do_content_release ' ), array_merge ($ additionalVariables , [
67
63
'contentReleaseId ' => $ contentReleaseId ,
68
- 'currentContentReleaseId ' => $ currentContentReleaseId ?: self :: NO_PREVIOUS_RELEASE ,
64
+ 'currentContentReleaseId ' => $ this -> resolveCurrentContentReleaseId ( $ currentContentReleaseId) ,
69
65
'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 (),
74
68
]));
69
+
75
70
return $ contentReleaseId ;
76
71
}
77
72
78
73
// the validate parameter can be used to intentionally skip the validation step for this release
79
74
public function startFullContentRelease (bool $ validate = true , string $ currentContentReleaseId = null , Workspace $ workspace = null , array $ additionalVariables = []): ContentReleaseIdentifier
80
75
{
81
- $ redis = $ this ->redisClientManager ->getPrimaryRedis ();
82
- if ($ currentContentReleaseId ) {
83
- $ currentContentReleaseId = $ redis ->get (self ::REDIS_CURRENT_RELEASE_KEY );
84
- }
85
-
86
76
$ contentReleaseId = ContentReleaseIdentifier::create ();
77
+
87
78
$ this ->contentCache ->flush ();
79
+
88
80
$ this ->prunnerApiService ->schedulePipeline (PipelineName::create ('do_content_release ' ), array_merge ($ additionalVariables , [
89
81
'contentReleaseId ' => $ contentReleaseId ,
90
- 'currentContentReleaseId ' => $ currentContentReleaseId ?: self :: NO_PREVIOUS_RELEASE ,
82
+ 'currentContentReleaseId ' => $ this -> resolveCurrentContentReleaseId ( $ currentContentReleaseId) ,
91
83
'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 (),
96
86
]));
87
+
97
88
return $ contentReleaseId ;
98
89
}
99
90
@@ -134,4 +125,29 @@ public function toggleConfigEpoch(RedisInstanceIdentifier $redisInstanceIdentifi
134
125
$ redis ->set ('contentStore:configEpoch ' , $ currentConfigEpochConfig );
135
126
}
136
127
}
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
+ }
137
153
}
0 commit comments