public function delete(sfImagePoolCrop $crop = null)
 {
     parent::delete($crop);
     // Then deal with stuff on the edge - delete crop from edge
     if ($crop) {
         $resizer_options = array('width' => $crop->width, 'height' => $crop->height, 'scale' => !$crop->is_crop);
         $object_name = $this->getCloudName($resizer_options);
         try {
             $this->container->delete_object($object_name);
         } catch (NoSuchObjectException $e) {
             // Image already deleted from cloud - that's ok
         }
     }
 }
 public function syncFile($file)
 {
     $extension = pathinfo($file, PATHINFO_EXTENSION);
     if ('php' === $extension) {
         return;
     }
     // local hash
     $md5Local = md5_file($file);
     // remote hash
     $relativePath = $this->getRelativePath($file);
     try {
         $obj = $this->container->get_object($relativePath);
         if ($obj->getETag() != $md5Local) {
             $this->log('~ ' . $relativePath);
             $obj->content_type = $this->getMimeTypeFromExtension($extension);
             $obj->load_from_filename($file);
         }
     } catch (NoSuchObjectException $e) {
         $this->log('+ ' . $relativePath);
         $obj = $this->container->create_object($relativePath);
         $obj->content_type = $this->getMimeTypeFromExtension($extension);
         $obj->load_from_filename($file);
     }
 }
Example #3
0
 /**
  * Test CDN connection
  *
  * @param string $error
  * @return boolean
  */
 function test(&$error)
 {
     if (!parent::test($error)) {
         return false;
     }
     if (!$this->_init($error) || !$this->_init_container($error)) {
         return false;
     }
     $string = 'test_rscf_' . md5(time());
     try {
         $object = $this->_container->create_object($string);
         $object->content_type = 'text/plain';
         $object->write($string, strlen($string));
     } catch (Exception $exception) {
         $error = sprintf('Unable to write object (%s).', $exception->getMessage());
         return false;
     }
     try {
         $object = $this->_container->get_object($string);
         $data = $object->read();
     } catch (Exception $exception) {
         $error = sprintf('Unable to read object (%s).', $exception->getMessage());
         try {
             $this->_container->delete_object($string);
         } catch (Exception $exception) {
         }
         return false;
     }
     if ($data != $string) {
         $error = 'Objects are not equal.';
         try {
             $this->_container->delete_object($string);
         } catch (Exception $exception) {
         }
         return false;
     }
     try {
         $this->_container->delete_object($string);
     } catch (Exception $exception) {
         $error = sprintf('Unable to delete object (%s).', $exception->getMessage());
         return false;
     }
     return true;
 }
Example #4
0
 /**
  * ensure a subcontainer file exists and return it's object
  * @param \CF_Container $container
  * @return \CF_Object
  */
 private function getSubContainerFile($container)
 {
     try {
         return $container->get_object(self::SUBCONTAINER_FILE);
     } catch (\NoSuchObjectException $e) {
         return $container->create_object(self::SUBCONTAINER_FILE);
     }
 }
 /**
  * @param \CF_Container $container
  */
 function it_should_not_mask_exception_when_delete($container)
 {
     $container->delete_object('filename')->willThrow(new \RuntimeException('delete'));
     $this->shouldThrow(new \RuntimeException('delete'))->duringDelete('filename');
 }
Example #6
0
 /**
  * Helper function to create "path" elements for a given Object name
  *
  * Given an Object whos name contains '/' path separators, this function
  * will create the "directory marker" Objects of one byte with the
  * Content-Type of "application/directory".
  *
  * It assumes the last element of the full path is the "real" Object
  * and does NOT create a remote storage Object for that last element.
  */
 function create_paths($path_name)
 {
     $this->initContainer();
     return parent::create_paths($path_name);
 }