Skip to content
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
18 changes: 18 additions & 0 deletions src/Api/Admin/AssetsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,24 @@ public function restore(array|string $publicIds, array $options = []): ApiRespon
return $this->apiClient->postJson($uri, $params);
}

/**
* Reverts to the latest backed up version of the specified deleted assets by asset IDs.
*
* @param array|string $assetIds The asset IDs of the backed up assets to restore. They can be existing or
* deleted assets.
* @param array $options The optional parameters.
*
* @return ApiResponse The result of the restore operation.
*/
public function restoreByAssetIds(array|string $assetIds, array $options = []): ApiResponse
{
$uri = [ApiEndPoint::ASSETS, 'restore'];

$params = array_merge($options, ['asset_ids' => ArrayUtils::build($assetIds)]);

return $this->apiClient->postJson($uri, $params);
}

/**
* Updates details of an existing asset.
*
Expand Down
51 changes: 51 additions & 0 deletions tests/Unit/Admin/AssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,57 @@ public function testRestoreDeletedAssetSpecificVersion($publicIds, $options, $ur
self::assertRequestJsonBodySubset($lastRequest, $bodyFields);
}

/**
* @return array[]
*/
public function restoreDeletedAssetByAssetIDSpecificVersionDataProvider()
{
return [
[
'assetIds' => self::API_TEST_ASSET_ID,
'options' => [
'versions' => ['293272f6bd9ec6ae9fa643e295b4dd1b'],
],
'url' => '/resources/restore',
'bodyFields' => [
'asset_ids' => [self::API_TEST_ASSET_ID],
'versions' => ['293272f6bd9ec6ae9fa643e295b4dd1b'],
],
],
[
'assetIds' => [self::API_TEST_ASSET_ID2, self::API_TEST_ASSET_ID3],
'options' => [
'versions' => ['9fa643e295b4dd1b293272f6bd9ec6ae', 'b4dd1b293272f6bd9fa643e2959ec6ae'],
],
'url' => '/resources/restore',
'bodyFields' => [
'asset_ids' => [self::API_TEST_ASSET_ID2, self::API_TEST_ASSET_ID3],
'versions' => ['9fa643e295b4dd1b293272f6bd9ec6ae', 'b4dd1b293272f6bd9fa643e2959ec6ae'],
],
],
];
}

/**
* Restore specific versions of a deleted asset by asset IDs.
*
* @dataProvider restoreDeletedAssetByAssetIDSpecificVersionDataProvider
*
* @param array|string $assetIds
* @param array $options
* @param string $url
* @param array $bodyFields
*/
public function testRestoreDeletedAssetByAssetIDSpecificVersion($assetIds, $options, $url, $bodyFields)
{
$mockAdminApi = new MockAdminApi();
$mockAdminApi->restoreByAssetIds($assetIds, $options);
$lastRequest = $mockAdminApi->getMockHandler()->getLastRequest();

self::assertRequestUrl($lastRequest, $url);
self::assertRequestJsonBodySubset($lastRequest, $bodyFields);
}

/**
* Test update assets complex fields serialization.
*/
Expand Down
Loading