public static function tearDownAfterClass() { try { unlink(self::LARGE_OBJECT); $client = self::getServiceBuilder()->get('s3'); $bucket = self::getResourcePrefix() . '-s3-test'; self::log("Clearing the contents of the {$bucket} bucket"); // Delete the bucket $clear = new ClearBucket($client, $bucket); $clear->clear(); self::log("Deleting the {$bucket} bucket"); $client->deleteBucket(array('Bucket' => $bucket)); self::log("Waiting for {$bucket} to not exist"); // commit for test //$client->waitUntil('bucket_not_exists', array('Bucket' => $bucket)); // Delete the other bucket //$bucket = self::getResourcePrefix() . '_path'; //$clear = new ClearBucket($client, $bucket); //$clear->clear(); //self::log("Deleting the {$bucket} bucket"); //$client->deleteBucket(array('Bucket' => $bucket)); //self::log("Waiting for {$bucket} to not exist"); //$client->waitUntil('bucket_not_exists', array('Bucket' => $bucket)); } catch (\Mss\S3\Exception\BucketNotEmptyException $e) { self::log("Deleting bucket fail"); } }
public static function tearDownAfterClass() { $client = self::getServiceBuilder()->get('s3', array('signature' => 'v4')); $bucket = self::getResourcePrefix() . '-s3-test'; self::log("Clearing the contents of the {$bucket} bucket"); $clear = new ClearBucket($client, $bucket); $clear->clear(); self::log("Deleting the {$bucket} bucket"); $client->deleteBucket(array('Bucket' => $bucket)); }
public function testClearsBucketAndBuffersExceptions() { $client = $this->getServiceBuilder()->get('s3'); $mock = $this->setMockResponse($client, array('s3/get_bucket_object_versions_page_2', 's3/delete_multiple_objects_errors')); $clear = new ClearBucket($client, 'foo'); try { $clear->clear(); $this->fail('Did not throw expected exception'); } catch (ExceptionCollection $e) { $requests = $mock->getReceivedRequests(); $this->assertEquals(2, count($requests)); $this->assertEquals(1, count($e)); foreach ($e->getIterator() as $ee) { $this->assertEquals(1, count($ee->getErrors())); } } }
/** * Clear the contents and delete a bucket * * @depends testPutObjectSigV4 * @example Mss\S3\S3Client::clearBucket * @example Mss\S3\S3Client::deleteBucket * @example Mss\S3\S3Client::waitUntilBucketNotExists */ public function testCleanUpBucket() { $client = $this->client; $bucket = $this->bucket; $client->waitUntil('BucketExists', array('Bucket' => $bucket)); // @begin // Delete the objects in the bucket before attempting to delete // the bucket $clear = new ClearBucket($client, $bucket); $clear->clear(); // Delete the bucket $client->deleteBucket(array('Bucket' => $bucket)); // Wait until the bucket is not accessible //$client->waitUntil('BucketNotExists', array('Bucket' => $bucket)); }
/** * Deletes objects from Amazon S3 that match the result of a ListObjects operation. For example, this allows you * to do things like delete all objects that match a specific key prefix. * * @param string $bucket Bucket that contains the object keys * @param string $prefix Optionally delete only objects under this key prefix * @param string $regex Delete only objects that match this regex * @param array $options Options used when deleting the object: * - before_delete: Callback to invoke before each delete. The callback will receive a * Guzzle\Common\Event object with context. * * @see Mss\S3\S3Client::listObjects * @see Mss\S3\Model\ClearBucket For more options or customization * @return int Returns the number of deleted keys * @throws RuntimeException if no prefix and no regex is given */ public function deleteMatchingObjects($bucket, $prefix = '', $regex = '', array $options = array()) { if (!$prefix && !$regex) { throw new RuntimeException('A prefix or regex is required, or use S3Client::clearBucket().'); } $clear = new ClearBucket($this, $bucket); $iterator = $this->getIterator('ListObjects', array('Bucket' => $bucket, 'Prefix' => $prefix)); if ($regex) { $iterator = new FilterIterator($iterator, function ($current) use($regex) { return preg_match($regex, $current['Key']); }); } $clear->setIterator($iterator); if (isset($options['before_delete'])) { $clear->getEventDispatcher()->addListener(ClearBucket::BEFORE_CLEAR, $options['before_delete']); } return $clear->clear(); }