Skip to content

feat(storage): update compose sample to support deleteSourceObjects option#2219

Draft
nidhiii-27 wants to merge 1 commit into
mainfrom
feat/php-compose-delete-sources
Draft

feat(storage): update compose sample to support deleteSourceObjects option#2219
nidhiii-27 wants to merge 1 commit into
mainfrom
feat/php-compose-delete-sources

Conversation

@nidhiii-27

Copy link
Copy Markdown

Update compose_file snippet to support deleteSourceObjects option.
Add corresponding integration tests.

[Generated-by: AI]

…ption

Update compose_file snippet to support deleteSourceObjects option.
Add corresponding integration tests.

[Generated-by: AI]
@nidhiii-27 nidhiii-27 added ai-generated Generated by AI storage-sample-architect Generated by storage-sample-architect skill labels Jun 16, 2026
@product-auto-label product-auto-label Bot added api: storage Issues related to the Cloud Storage API. samples Issues that are directly related to samples. labels Jun 16, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 56 to 72
$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
);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

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
        );
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated Generated by AI api: storage Issues related to the Cloud Storage API. samples Issues that are directly related to samples. storage-sample-architect Generated by storage-sample-architect skill

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant