public function testConvertsDeleteObjectCommandsToArrays() { $client = $this->getServiceBuilder()->get('s3'); $batch = DeleteObjectsBatch::factory($client, 'foo'); $batch->add($client->getCommand('DeleteObject', array('Bucket' => 'bucket', 'Key' => 'foo', 'VersionId' => 'bar'))); $decorated = $this->readAttribute($batch, 'decoratedBatch'); $queue = $this->readAttribute($decorated, 'queue'); $this->assertEquals(array('Key' => 'foo', 'VersionId' => 'bar'), $queue->pop()); }
/** * Clear the bucket * * @return int Returns the number of deleted keys * @throws ExceptionCollection */ public function clear() { $that = $this; $batch = DeleteObjectsBatch::factory($this->client, $this->bucket, $this->mfa); $batch = new NotifyingBatch($batch, function ($items) use($that) { $that->dispatch(ClearBucket::AFTER_DELETE, array('keys' => $items)); }); $batch = new FlushingBatch(new ExceptionBufferingBatch($batch), 1000); // Let any listeners know that the bucket is about to be cleared $this->dispatch(self::BEFORE_CLEAR, array('iterator' => $this->getIterator(), 'batch' => $batch, 'mfa' => $this->mfa)); $deleted = 0; foreach ($this->getIterator() as $object) { if (isset($object['VersionId'])) { $versionId = $object['VersionId'] == 'null' ? null : $object['VersionId']; } else { $versionId = null; } $batch->addKey($object['Key'], $versionId); $deleted++; } $batch->flush(); // If any errors were encountered, then throw an ExceptionCollection if (count($batch->getExceptions())) { $e = new ExceptionCollection(); foreach ($batch->getExceptions() as $exception) { $e->add($exception->getPrevious()); } throw $e; } // Let any listeners know that the bucket was cleared $this->dispatch(self::AFTER_CLEAR, array('deleted' => $deleted)); return $deleted; }