feat(storage): update compose sample to support deleteSourceObjects option#2219
feat(storage): update compose sample to support deleteSourceObjects option#2219nidhiii-27 wants to merge 1 commit into
Conversation
…ption Update compose_file snippet to support deleteSourceObjects option. Add corresponding integration tests. [Generated-by: AI]
There was a problem hiding this comment.
Code Review
This pull request introduces a $deleteSourceObjects parameter to the compose_file function to allow deleting source objects after they are composed, along with corresponding test updates. However, the deleteSourceObjects option is not supported by the Bucket::compose() method or the underlying Cloud Storage API. You should instead explicitly delete the source objects in your code after a successful compose operation.
| $targetObject = $bucket->compose($objectsToCompose, $targetObjectName, [ | ||
| 'deleteSourceObjects' => $deleteSourceObjects, | ||
| 'destination' => [ | ||
| 'contentType' => 'application/octet-stream' | ||
| ] | ||
| ]); | ||
|
|
||
| if ($targetObject->exists()) { | ||
| $deletionMessage = $deleteSourceObjects ? ' and the source objects were deleted' : ''; | ||
| printf( | ||
| 'New composite object %s was created by combining %s and %s', | ||
| 'New composite object %s was created by combining %s and %s%s', | ||
| $targetObject->name(), | ||
| $firstObjectName, | ||
| $secondObjectName | ||
| $secondObjectName, | ||
| $deletionMessage | ||
| ); | ||
| } |
There was a problem hiding this comment.
The deleteSourceObjects option is not supported by the Google\Cloud\Storage\Bucket::compose() method or the underlying Cloud Storage Compose API. Passing this option will either be ignored or cause an API error, and the source objects will not be deleted.
To support this option, you should explicitly delete the source objects after a successful compose operation.
$targetObject = $bucket->compose($objectsToCompose, $targetObjectName, [
'destination' => [
'contentType' => 'application/octet-stream'
]
]);
if ($targetObject->exists()) {
if ($deleteSourceObjects) {
foreach ($objectsToCompose as $sourceObjectName) {
$bucket->object($sourceObjectName)->delete();
}
}
$deletionMessage = $deleteSourceObjects ? ' and the source objects were deleted' : '';
printf(
'New composite object %s was created by combining %s and %s%s',
$targetObject->name(),
$firstObjectName,
$secondObjectName,
$deletionMessage
);
}
Update compose_file snippet to support deleteSourceObjects option.
Add corresponding integration tests.
[Generated-by: AI]