-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(storagecontrol): add PHP delete_folder_recursive sample #2225
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
base: main
Are you sure you want to change the base?
Changes from all commits
861a79c
fc7a6d6
188d478
7911a95
d8c42c3
5068cd1
d8dea39
45df9bb
d16c695
dd8695d
44c01cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| <?php | ||
| /** | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other samples in storagecontrol/src/ include a docblock before the namespace statement linking to the sample README. Let's add that here for consistency.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done Co-authored by AI Agent |
||
| /** | ||
| * For instructions on how to run the full sample: | ||
| * | ||
| * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storagecontrol/README.md | ||
| */ | ||
|
|
||
| namespace Google\Cloud\Samples\StorageControl; | ||
|
|
||
| # [START storage_control_delete_folder_recursive] | ||
| use Google\Cloud\Storage\Control\V2\Client\StorageControlClient; | ||
| use Google\Cloud\Storage\Control\V2\DeleteFolderRecursiveRequest; | ||
|
|
||
| /** | ||
| * Delete a folder recursively in an existing bucket. | ||
| * | ||
| * @param string $bucketName The name of your Cloud Storage bucket. | ||
| * (e.g. 'my-bucket') | ||
| * @param string $folderName The name of your folder inside the bucket. | ||
| * (e.g. 'my-folder') | ||
| */ | ||
| function delete_folder_recursive(string $bucketName, string $folderName): void | ||
| { | ||
| $storageControlClient = new StorageControlClient(); | ||
|
|
||
| // Set project to "_" to signify global bucket | ||
| $formattedName = $storageControlClient->folderName('_', $bucketName, $folderName); | ||
|
|
||
| $request = new DeleteFolderRecursiveRequest([ | ||
| 'name' => $formattedName, | ||
| ]); | ||
|
|
||
| $operation = $storageControlClient->deleteFolderRecursive($request); | ||
| $operation->pollUntilComplete(); | ||
| if (!$operation->operationSucceeded()) { | ||
| $error = $operation->getError(); | ||
| throw new \Exception(sprintf( | ||
| 'DeleteFolderRecursive operation failed: %s', | ||
| $error ? $error->getMessage() : 'Unknown error' | ||
| )); | ||
| } | ||
|
|
||
| printf('Deleted folder recursively: %s', $folderName); | ||
| } | ||
| # [END storage_control_delete_folder_recursive] | ||
|
|
||
| // The following 2 lines are only needed to run the samples | ||
| require_once __DIR__ . '/../../testing/sample_helpers.php'; | ||
| \Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,7 @@ ALT_PROJECT_TESTS=( | |
| pubsub/api | ||
| pubsub/quickstart | ||
| storage | ||
| storagecontrol | ||
| spanner | ||
| video | ||
| vision | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if GOOGLE_ALT_PROJECT_ID is not explicitly exported in the environment, --project "${GOOGLE_ALT_PROJECT_ID}" may be empty. Should we extract it from the alternate credentials file if unset?
Side note: can we have someone familiar with this file verify that the fallback logic behaves as expected across all test pipelines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Co-authored by AI Agent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bshaffer could you please review the fallback logic in this file.