diff --git a/storagecontrol/composer.json b/storagecontrol/composer.json index 46deccbf4c..c2e2a38fcb 100644 --- a/storagecontrol/composer.json +++ b/storagecontrol/composer.json @@ -1,6 +1,6 @@ { "require": { - "google/cloud-storage-control": "1.6.1" + "google/cloud-storage-control": "^1.7.0" }, "require-dev": { "google/cloud-storage": "^1.48.1" diff --git a/storagecontrol/src/delete_folder_recursive.php b/storagecontrol/src/delete_folder_recursive.php new file mode 100644 index 0000000000..ad1c98ccb0 --- /dev/null +++ b/storagecontrol/src/delete_folder_recursive.php @@ -0,0 +1,64 @@ +folderName('_', $bucketName, $folderName); + + $request = new DeleteFolderRecursiveRequest([ + 'name' => $formattedName, + ]); + + $operation = $storageControlClient->deleteFolderRecursive($request); + + $operation->pollUntilComplete(); + + if ($operation->operationSucceeded()) { + printf('Deleted folder: %s', $folderName); + } else { + $error = $operation->getError(); + printf('Failed to delete folder: %s', $error ? $error->getMessage() : 'Unknown error'); + } +} +# [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); diff --git a/storagecontrol/test/StorageControlTest.php b/storagecontrol/test/StorageControlTest.php index f32230e9d1..b40fe69f36 100644 --- a/storagecontrol/test/StorageControlTest.php +++ b/storagecontrol/test/StorageControlTest.php @@ -206,4 +206,22 @@ public function testDeleteFolder() $output ); } + + public function testDeleteFolderRecursive() + { + $recursiveFolderId = time() . rand(); + + $this->runFunctionSnippet('create_folder', [ + self::$sourceBucket->name(), $recursiveFolderId + ]); + + $output = $this->runFunctionSnippet('delete_folder_recursive', [ + self::$sourceBucket->name(), $recursiveFolderId + ]); + + $this->assertStringContainsString( + sprintf('Deleted folder: %s', $recursiveFolderId), + $output + ); + } }