Beispiel #1
0
 protected function _createBucketIfNecessary()
 {
     if (!$this->_bucketExists) {
         if (!$this->_api->isBucketAvailable($this->_config['bucket'])) {
             $this->_api->createBucket($this->_config['bucket']);
         }
         $this->_bucketExists = true;
     }
 }
Beispiel #2
0
 /**
  * Test creating bucket with IP
  *
  * ZF-6686
  */
 public function testBucketIPMaskPostCondition()
 {
     try {
         $this->_amazon->createBucket("127.0.0.1");
     } catch (\Zend\Service\Amazon\Sqs\Exception\InvalidArgumentException $e) {
         $this->_amazon->createBucket("123-456-789-123");
         $this->assertTrue($this->_amazon->isBucketAvailable("123-456-789-123"));
         $this->_amazon->removeBucket("123-456-789-123");
         return;
     }
     $this->fail("Failed to throw expected exception");
 }
Beispiel #3
0
 /**
  * Test creating bucket with IP
  *
  * ZF-6686
  */
 public function testBucketIPMask()
 {
     try {
         $this->_amazon->createBucket("127.0.0.1");
         $this->fail("Failed to throw expected exception");
     } catch (Zend_Service_Amazon_S3_Exception $e) {
         $this->assertContains("cannot be an IP address", $e->getMessage());
     }
     $this->_amazon->createBucket("123-456-789-123");
     $this->assertTrue($this->_amazon->isBucketAvailable("123-456-789-123"));
     $this->_amazon->removeBucket("123-456-789-123");
 }
 /**
  * Removes the object specified by the file name and user id
  * @param unknown_type $user_id
  * @param unknown_type $file_name
  * @return boolean
  */
 private function removeAmazonS3Object($user_id, $file_name)
 {
     // TODO: make this asynchronous later
     global $app;
     $objectURL = null;
     $aws_key = null;
     $aws_secret_key = null;
     $aws_key = $app->configData['configuration']['api_keys']['value']['amazon_aws_key']['value'];
     $aws_secret_key = $app->configData['configuration']['api_keys']['value']['amazon_aws_secret']['value'];
     $amazon_bucket_name = $app->configData['configuration']['api_keys']['value']['amazon_s3_bucket']['value'];
     if (isset($aws_key) && isset($aws_secret_key)) {
         $s3 = null;
         $bucketAvailable = false;
         $s3 = new Zend_Service_Amazon_S3($aws_key, $aws_secret_key);
         $bucketAvailable = $s3->isBucketAvailable($amazon_bucket_name);
         if ($bucketAvailable) {
             // bucket is available so try to delete the object
             try {
                 foreach ($this->_image_sizes as $imageSizeType => $imageDimensions) {
                     $objectPath = $this->buildAmazonS3ObjectURL($imageSizeType, $user_id, $file_name);
                     $objectPath = $amazon_bucket_name . $objectPath;
                     $s3->removeObject($objectPath);
                 }
                 return true;
             } catch (Exception $e) {
                 // ignore this error - the extra amazons3 object in the bucket
                 // will not harm anything. It will just be an unclean directory
                 // take care of cleaning asynchronously by deleting orphan objects
                 // that do not appear in the user's picture/avatar urls
                 //$this->message = $e->getMessage();
             }
         } else {
             // no bucket is available
             return false;
         }
     }
     return false;
 }
Beispiel #5
0
 public function canStore()
 {
     $bucket = $this->_getBucketName();
     return $this->_s3->isBucketAvailable($bucket);
 }