Example #1
0
 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 (\Aws\S3\Exception\BucketNotEmptyException $e) {
         self::log("Deleting bucket fail");
     }
 }
Example #2
0
 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 static function tearDownAfterClass()
 {
     $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");
     $client->waitUntil('bucket_not_exists', $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()));
         }
     }
 }
Example #5
0
 /**
  * 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 Aws\S3\S3Client::listObjects
  * @see Aws\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();
 }
 /**
  * Clear the contents and delete a bucket
  *
  * @depends testPutObjectSigV4
  * @example Aws\S3\S3Client::clearBucket
  * @example Aws\S3\S3Client::deleteBucket
  * @example Aws\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));
 }
Example #7
0
 /**
  * Helper used to clear the contents of a bucket. Use the {@see ClearBucket} object directly
  * for more advanced options and control.
  *
  * @param string $bucket Name of the bucket to clear.
  *
  * @return int Returns the number of deleted keys
  */
 public function clearBucket($bucket)
 {
     $clear = new ClearBucket($this, $bucket);
     return $clear->clear();
 }
 /**
  * Removes all objects from a bucket
  *
  * This command deletes all objects (files) of the given bucket.
  *
  * @param string $bucket Name of the bucket
  * @return void
  */
 public function flushBucketCommand($bucket)
 {
     try {
         $s3Client = S3Client::factory($this->s3DefaultProfile);
         $clearBucket = new ClearBucket($s3Client, $bucket);
         $clearBucket->clear();
     } catch (\Exception $e) {
         $this->outputLine($e->getMessage());
         $this->quit(1);
     }
     $this->outputLine('Successfully flushed bucket %s.', array($bucket));
 }
Example #9
0
                    $deletobj = $s3Client->deleteObject(array('Bucket' => $buketname, 'Key' => $objectname));
                    echo "Object Deleted : " . $objectname;
                } catch (\Aws\S3\Exception\S3Exception $e) {
                    echo $e->getMessage();
                }
                break;
                // ----------------------------------------------------------------------
            // ----------------------------------------------------------------------
            case 'bucket':
                // ----------------------------------------------------------------------
                // Remove a Bucket (All Objects will be deleted in the bucket as well!)
                // Ex. php aisS3client.php remove:bucket paglatest
                // ----------------------------------------------------------------------
                $buketname = $argv[2];
                // Get Bucket Name
                try {
                    $clear = new ClearBucket($s3Client, $buketname);
                    $clear->clear();
                    // Delete the bucket
                    $s3Client->deleteBucket(array('Bucket' => $buketname));
                    // Wait until the bucket is not accessible
                    $s3Client->waitUntilBucketNotExists(array('Bucket' => $buketname));
                    echo "Bucket Cleand & Deleted : " . $buketname;
                } catch (\Aws\S3\Exception\S3Exception $e) {
                    echo $e->getMessage();
                }
                break;
                // ----------------------------------------------------------------------
        }
        break;
}
Example #10
0
 /**
  * @param  string                               $container_name
  * @return bool
  * @throws \PHPQueue\Exception\BackendException
  */
 public function deleteContainer($container_name)
 {
     if (empty($container_name)) {
         throw new BackendException('Invalid Bucket name: ' . $container_name);
     }
     try {
         $clear = new ClearBucket($this->getConnection(), $container_name);
         $clear->clear();
         $this->getConnection()->deleteBucket(array('Bucket' => $container_name));
         $this->getConnection()->waitUntilBucketNotExists(array('Bucket' => $container_name));
     } catch (NoSuchBucketException $exception) {
         return true;
     } catch (S3Exception $exception) {
         throw new BackendException($exception->getMessage(), $exception->getCode());
     }
     return true;
 }