From 15ece66cd6fff302e921eaa9e37842a304e05d33 Mon Sep 17 00:00:00 2001 From: Sneha Sahu Date: Mon, 9 Nov 2026 15:24:23 +0000 Subject: [PATCH] revert(storage): remove delete object contexts sample (#2342) This reverts commit a4823a49b07ae3dbba22cb93f338c50fee4336db. PR #2342 was created and merged accidentally. Also drops the follow-up one-line tweak to this file from #2353. --- storage/src/delete_object_contexts.php | 66 -------------------------- storage/test/ObjectsTest.php | 13 ++--- 2 files changed, 5 insertions(+), 74 deletions(-) delete mode 100644 storage/src/delete_object_contexts.php diff --git a/storage/src/delete_object_contexts.php b/storage/src/delete_object_contexts.php deleted file mode 100644 index b0bb0deba..000000000 --- a/storage/src/delete_object_contexts.php +++ /dev/null @@ -1,66 +0,0 @@ -bucket($bucketName); - $object = $bucket->object($objectName); - - // Fetch the current metageneration so the update can be made conditional. - $info = $object->info(); - - // To delete all contexts, set the 'custom' key to null, which is sent as a - // JSON null and clears every context. Do not use an empty PHP array: it - // serializes as a JSON list ([]) rather than an empty map. - // Optional: set a metageneration-match precondition to avoid potential - // race conditions and data corruptions. The request to update is aborted - // if the object's metageneration does not match your precondition. - $object->update([ - 'contexts' => [ - 'custom' => null, - ], - ], [ - 'ifMetagenerationMatch' => $info['metageneration'] ?? null, - ]); - - printf('Deleted object contexts for object %s in bucket %s.' . PHP_EOL, $objectName, $bucketName); -} -# [END storage_delete_object_contexts] - -// 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/ObjectsTest.php b/storage/test/ObjectsTest.php index c6260fde8..5f1acc644 100644 --- a/storage/test/ObjectsTest.php +++ b/storage/test/ObjectsTest.php @@ -77,15 +77,12 @@ public function testObjectContexts() ]); $this->assertStringContainsString("Found object: $objectInfo", $listOutput); - // Delete all contexts on the object. - $deleteOutput = $this->runFunctionSnippet('delete_object_contexts', [ - $bucketName, - $objectInfo, + // Clear all contexts on the object. + $object->update([ + 'contexts' => [ + 'custom' => null, + ], ]); - $this->assertStringContainsString( - "Deleted object contexts for object $objectInfo in bucket $bucketName.", - $deleteOutput - ); $object->reload(); $clearedGetOutput = $this->runFunctionSnippet('get_object_contexts', [