Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LCH-6279: New methods for reorigination. #160

Merged
merged 2 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/ContentHubClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,54 @@ public function suppressWebhook(string $webhook_uuid, string $suppress_duration
return self::getResponseJson($this->put("webhook/$webhook_uuid/suppress", $options));
}

/**
* Reoriginates entity uuid with new target origin.
*
* @param string $entity_uuid
* Entity uuid.
* @param string $target
* Origin of target site.
*
* @return mixed
* API response.
*
* @throws \Exception
*/
public function reoriginateEntity(string $entity_uuid, string $target) {
$client = $this->getClientByUuid($target);
if (empty($client)) {
throw new \RuntimeException(sprintf('%s target client is not registered, please check target origin uuid.', $target));
}
$options['body'] = json_encode(['target' => $target]);
return self::getResponseJson($this->post("entities/$entity_uuid/reoriginate", $options));
}

/**
* Reoriginate all entities from source origin to target origin.
*
* @param string $source
* Source origin uuid.
* @param string $target
* Target origin uuid.
*
* @return mixed
* API response.
*
* @throws \Exception
*/
public function reoriginateAllEntities(string $source, string $target) {
$clients = array_column($this->getClients(), 'uuid');
if (!in_array($source, $clients, TRUE)) {
throw new \RuntimeException(sprintf('%s source client is not registered, first register it and then try reorigination to target.', $source));
}

if (!in_array($target, $clients, TRUE)) {
throw new \RuntimeException(sprintf('%s target client is not registered, please check target origin uuid.', $target));
}
$options['body'] = json_encode(['origin' => $source, 'target' => $target]);
return self::getResponseJson($this->post('entities/reoriginate', $options));
}

/**
* Remove suppression from webhook.
*
Expand Down
40 changes: 40 additions & 0 deletions test/ContentHubClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,46 @@ public function testDeleteEntities(): void {
$this->assertSame($response_body, $this->ch_client->deleteEntities($uuids));
}

/**
* @covers \Acquia\ContentHubClient\ContentHubClient::reoriginateEntity
*/
public function testReoriginateEntity(): void {
$uuid = '0e714009-72f9-4016-8f26-5fae32e6abb8';
$target = 'client-2-uuid';
$response_body = [
'success' => TRUE,
'request_id' => 'some-uuid',
];

$this->ch_client
->shouldReceive('post')
->once()
->with("entities/$uuid/reoriginate", ['body' => json_encode(['target' => $target])])
->andReturn($this->makeMockResponse(SymfonyResponse::HTTP_ACCEPTED, [], json_encode($response_body)));
$this->assertSame($response_body, $this->ch_client->reoriginateEntity($uuid, $target));
}

/**
* @covers \Acquia\ContentHubClient\ContentHubClient::reoriginateAllEntities
*/
public function testReoriginateAllEntities(): void {
$source = 'client-1-uuid';
$target = 'client-2-uuid';
$response_body = [
'success' => TRUE,
'request_id' => 'some-uuid',
];

$this->ch_client
->shouldReceive('post')
->once()
->with('entities/reoriginate', [
'body' => json_encode(['origin' => $source, 'target' => $target]),
])
->andReturn($this->makeMockResponse(SymfonyResponse::HTTP_ACCEPTED, [], json_encode($response_body)));
$this->assertSame($response_body, $this->ch_client->reoriginateAllEntities($source, $target));
}

/**
* @covers \Acquia\ContentHubClient\ContentHubClient::deleteInterest
*/
Expand Down