diff --git a/storage/src/get_soft_deleted_bucket.php b/storage/src/get_soft_deleted_bucket.php new file mode 100644 index 000000000..d4f90f124 --- /dev/null +++ b/storage/src/get_soft_deleted_bucket.php @@ -0,0 +1,54 @@ + $generation, 'softDeleted' => true]; + $storage = new StorageClient(); + $bucket = $storage->bucket($bucketName); + $info = $bucket->info($options); + + printf('Bucket: %s' . PHP_EOL, $bucketName); + printf('Generation: %s' . PHP_EOL, $info['generation']); + printf('SoftDeleteTime: %s' . PHP_EOL, $info['softDeleteTime']); + printf('HardDeleteTime: %s' . PHP_EOL, $info['hardDeleteTime']); +} +# [END storage_get_soft_deleted_bucket] + +// 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/storage/src/list_soft_deleted_buckets.php b/storage/src/list_soft_deleted_buckets.php new file mode 100644 index 000000000..1ecddcddd --- /dev/null +++ b/storage/src/list_soft_deleted_buckets.php @@ -0,0 +1,44 @@ + true ]; + foreach ($storage->buckets($options) as $bucket) { + printf('Bucket: %s' . PHP_EOL, $bucket->name()); + } +} +# [END storage_list_soft_deleted_buckets] + +// 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/storage/src/restore_soft_deleted_bucket.php b/storage/src/restore_soft_deleted_bucket.php new file mode 100644 index 000000000..a4bd9a84e --- /dev/null +++ b/storage/src/restore_soft_deleted_bucket.php @@ -0,0 +1,49 @@ +restore($bucketName, $generation); + + printf('Soft deleted bucket %s was restored.' . PHP_EOL, $bucketName); +} +# [END storage_restore_soft_deleted_bucket] + +// 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/storage/test/storageTest.php b/storage/test/storageTest.php index ab144489e..56a4b173a 100644 --- a/storage/test/storageTest.php +++ b/storage/test/storageTest.php @@ -147,6 +147,12 @@ public function testListBuckets() $this->assertStringContainsString('Bucket:', $output); } + public function testListSoftDeletedBuckets() + { + $output = $this->runFunctionSnippet('list_soft_deleted_buckets'); + $this->assertStringContainsString('Bucket:', $output); + } + public function testCreateGetDeleteBuckets() { $bucketName = sprintf('test-bucket-%s-%s', time(), rand()); @@ -559,6 +565,7 @@ public function testObjectGetKmsKey(string $objectName) $output, ); } + public function testBucketVersioning() { $output = self::runFunctionSnippet('enable_versioning', [ @@ -938,6 +945,46 @@ public function testGetBucketWithAutoclass() ); } + public function testGetRestoreSoftDeletedBucket() + { + $bucketName = sprintf('test-soft-deleted-bucket-%s-%s', time(), rand()); + $bucket = self::$storage->createBucket($bucketName); + + $this->assertTrue($bucket->exists()); + $generation = $bucket->info()['generation']; + $bucket->delete(); + + $this->assertFalse($bucket->exists()); + + $info = $bucket->reload(['softDeleted' => true, 'generation' => $generation]); + $output = self::runFunctionSnippet('get_soft_deleted_bucket', [ + $bucketName, + $generation + ]); + $outputString = <<assertEquals($outputString, $output); + + $output = self::runFunctionSnippet('restore_soft_deleted_bucket', [ + $bucketName, + $generation + ]); + + $this->assertTrue($bucket->exists()); + $this->assertEquals( + sprintf( + 'Soft deleted bucket %s was restored.' . PHP_EOL, + $bucketName + ), + $output + ); + } + public function testSetBucketWithAutoclass() { $bucket = self::$storage->createBucket(uniqid('samples-set-autoclass-'), [