Skip to content

Commit

Permalink
Abstract deployment check
Browse files Browse the repository at this point in the history
  • Loading branch information
dbhynds committed Nov 20, 2023
1 parent 36db980 commit 8b1e590
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/LtiMessageLaunch.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function validate(array $request = null)
public function migrate()
{
if (!$this->shouldMigrate()) {
return $this;
return $this->ensureDeploymentExists();
}

if (!isset($this->jwt['body'][LtiConstants::LTI1P1]['oauth_consumer_key_sign'])) {
Expand All @@ -191,11 +191,7 @@ public function migrate()

$this->deployment = $this->db->migrateFromLti1p1($this);

if (!isset($this->deployment)) {
throw new LtiException(static::ERR_NO_DEPLOYMENT);
}

return $this;
return $this->ensureDeploymentExists();
}

public function cacheLaunchData()
Expand Down Expand Up @@ -522,8 +518,8 @@ protected function validateDeployment(): self
$client_id = $this->getAud();
$this->deployment = $this->db->findDeployment($this->jwt['body']['iss'], $this->jwt['body'][LtiConstants::DEPLOYMENT_ID], $client_id);

if (!isset($this->deployment) && !$this->canMigrate()) {
throw new LtiException(static::ERR_NO_DEPLOYMENT);
if (!$this->canMigrate()) {
return $this->ensureDeploymentExists();
}

return $this;
Expand Down Expand Up @@ -573,6 +569,15 @@ private function getAud(): string
}
}

private function ensureDeploymentExists(): self
{
if (!isset($this->deployment)) {
throw new LtiException(static::ERR_NO_DEPLOYMENT);
}

return $this;
}

private function canMigrate(): bool
{
return $this->db instanceof IMigrationDatabase;
Expand Down

0 comments on commit 8b1e590

Please sign in to comment.