Skip to content

Commit

Permalink
Merge pull request #28 from Flowpack/bugfix-current-content-release-i…
Browse files Browse the repository at this point in the history
…d-in-content-release-manager

BUGFIX: Fix content release manager ignoring currentContentRelease parameter
  • Loading branch information
JamesAlias authored May 16, 2023
2 parents 3b7b9f3 + 1c1475d commit f20b7b6
Showing 1 changed file with 36 additions and 20 deletions.
56 changes: 36 additions & 20 deletions Classes/ContentReleaseManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,45 +55,36 @@ class ContentReleaseManager

public function startIncrementalContentRelease(string $currentContentReleaseId = null, Workspace $workspace = null, array $additionalVariables = []): ContentReleaseIdentifier
{
$redis = $this->redisClientManager->getPrimaryRedis();
if ($currentContentReleaseId) {
$currentContentReleaseId = $redis->get(self::REDIS_CURRENT_RELEASE_KEY);
}

$contentReleaseId = ContentReleaseIdentifier::create();

// the currentContentReleaseId is not used in any pipeline step in this package, but is a common need in other
// use cases in extensions, e.g. calculating the differences between current and new release
$this->prunnerApiService->schedulePipeline(PipelineName::create('do_content_release'), array_merge($additionalVariables, [
'contentReleaseId' => $contentReleaseId,
'currentContentReleaseId' => $currentContentReleaseId ?: self::NO_PREVIOUS_RELEASE,
'currentContentReleaseId' => $this->resolveCurrentContentReleaseId($currentContentReleaseId),
'validate' => true,
'workspaceName' => $workspace ? $workspace->getName() : 'live',
'accountId' => $this->securityContext->isInitialized()
? $this->securityContext->getAccount()->getAccountIdentifier() :
null,
'workspaceName' => $workspace !== null ? $workspace->getName() : 'live',
'accountId' => $this->getAccountId(),
]));

return $contentReleaseId;
}

// the validate parameter can be used to intentionally skip the validation step for this release
public function startFullContentRelease(bool $validate = true, string $currentContentReleaseId = null, Workspace $workspace = null, array $additionalVariables = []): ContentReleaseIdentifier
{
$redis = $this->redisClientManager->getPrimaryRedis();
if ($currentContentReleaseId) {
$currentContentReleaseId = $redis->get(self::REDIS_CURRENT_RELEASE_KEY);
}

$contentReleaseId = ContentReleaseIdentifier::create();

$this->contentCache->flush();

$this->prunnerApiService->schedulePipeline(PipelineName::create('do_content_release'), array_merge($additionalVariables, [
'contentReleaseId' => $contentReleaseId,
'currentContentReleaseId' => $currentContentReleaseId ?: self::NO_PREVIOUS_RELEASE,
'currentContentReleaseId' => $this->resolveCurrentContentReleaseId($currentContentReleaseId),
'validate' => $validate,
'workspaceName' => $workspace ? $workspace->getName() : 'live',
'accountId' => $this->securityContext->isInitialized()
? $this->securityContext->getAccount()->getAccountIdentifier() :
null,
'workspaceName' => $workspace !== null ? $workspace->getName() : 'live',
'accountId' => $this->getAccountId(),
]));

return $contentReleaseId;
}

Expand Down Expand Up @@ -134,4 +125,29 @@ public function toggleConfigEpoch(RedisInstanceIdentifier $redisInstanceIdentifi
$redis->set('contentStore:configEpoch', $currentConfigEpochConfig);
}
}

private function resolveCurrentContentReleaseId(?string $currentContentReleaseId): string
{
if ($currentContentReleaseId !== null) {
return $currentContentReleaseId;
}

$redis = $this->redisClientManager->getPrimaryRedis();
$currentContentReleaseIdFromRedis = $redis->get(self::REDIS_CURRENT_RELEASE_KEY);

if ($currentContentReleaseIdFromRedis !== false) {
return $currentContentReleaseIdFromRedis;
}

return self::NO_PREVIOUS_RELEASE;
}

private function getAccountId(): ?string
{
if ($this->securityContext->isInitialized()) {
return $this->securityContext->getAccount()->getAccountIdentifier();
}

return null;
}
}

0 comments on commit f20b7b6

Please sign in to comment.