Skip to content

Commit 5c5967a

Browse files
Add support for restoreByAssetIds Admin API
1 parent 121376a commit 5c5967a

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

src/Api/Admin/AssetsTrait.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,24 @@ public function restore(array|string $publicIds, array $options = []): ApiRespon
301301
return $this->apiClient->postJson($uri, $params);
302302
}
303303

304+
/**
305+
* Reverts to the latest backed up version of the specified deleted assets by asset IDs.
306+
*
307+
* @param array|string $assetIds The asset IDs of the backed up assets to restore. They can be existing or
308+
* deleted assets.
309+
* @param array $options The optional parameters.
310+
*
311+
* @return ApiResponse The result of the restore operation.
312+
*/
313+
public function restoreByAssetIds(array|string $assetIds, array $options = []): ApiResponse
314+
{
315+
$uri = [ApiEndPoint::ASSETS, 'restore'];
316+
317+
$params = array_merge($options, ['asset_ids' => ArrayUtils::build($assetIds)]);
318+
319+
return $this->apiClient->postJson($uri, $params);
320+
}
321+
304322
/**
305323
* Updates details of an existing asset.
306324
*

tests/Unit/Admin/AssetsTest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,57 @@ public function testRestoreDeletedAssetSpecificVersion($publicIds, $options, $ur
127127
self::assertRequestJsonBodySubset($lastRequest, $bodyFields);
128128
}
129129

130+
/**
131+
* @return array[]
132+
*/
133+
public function restoreDeletedAssetByAssetIDSpecificVersionDataProvider()
134+
{
135+
return [
136+
[
137+
'assetIds' => self::API_TEST_ASSET_ID,
138+
'options' => [
139+
'versions' => ['293272f6bd9ec6ae9fa643e295b4dd1b'],
140+
],
141+
'url' => '/resources/restore',
142+
'bodyFields' => [
143+
'asset_ids' => [self::API_TEST_ASSET_ID],
144+
'versions' => ['293272f6bd9ec6ae9fa643e295b4dd1b'],
145+
],
146+
],
147+
[
148+
'assetIds' => [self::API_TEST_ASSET_ID2, self::API_TEST_ASSET_ID3],
149+
'options' => [
150+
'versions' => ['9fa643e295b4dd1b293272f6bd9ec6ae', 'b4dd1b293272f6bd9fa643e2959ec6ae'],
151+
],
152+
'url' => '/resources/restore',
153+
'bodyFields' => [
154+
'asset_ids' => [self::API_TEST_ASSET_ID2, self::API_TEST_ASSET_ID3],
155+
'versions' => ['9fa643e295b4dd1b293272f6bd9ec6ae', 'b4dd1b293272f6bd9fa643e2959ec6ae'],
156+
],
157+
],
158+
];
159+
}
160+
161+
/**
162+
* Restore specific versions of a deleted asset by asset IDs.
163+
*
164+
* @dataProvider restoreDeletedAssetByAssetIDSpecificVersionDataProvider
165+
*
166+
* @param array|string $assetIds
167+
* @param array $options
168+
* @param string $url
169+
* @param array $bodyFields
170+
*/
171+
public function testRestoreDeletedAssetByAssetIDSpecificVersion($assetIds, $options, $url, $bodyFields)
172+
{
173+
$mockAdminApi = new MockAdminApi();
174+
$mockAdminApi->restoreByAssetIds($assetIds, $options);
175+
$lastRequest = $mockAdminApi->getMockHandler()->getLastRequest();
176+
177+
self::assertRequestUrl($lastRequest, $url);
178+
self::assertRequestJsonBodySubset($lastRequest, $bodyFields);
179+
}
180+
130181
/**
131182
* Test update assets complex fields serialization.
132183
*/

0 commit comments

Comments
 (0)