/**
  * Move a file or folder to a specific location
  *
  * @param string $from The location to move from
  * @param string $to The location to move to
  * @param string $point
  * @return boolean
  */
 public function moveObject($from, $to, $point = 'append')
 {
     $this->xpdo->lexicon->load('source');
     $success = false;
     if (substr(strrev($from), 0, 1) == '/') {
         $this->xpdo->error->message = $this->xpdo->lexicon('s3_no_move_folder', array('from' => $from));
         return $success;
     }
     if (!$this->driver->if_object_exists($this->bucket, $from)) {
         $this->xpdo->error->message = $this->xpdo->lexicon('file_err_ns') . ': ' . $from;
         return $success;
     }
     if ($to != '/') {
         if (!$this->driver->if_object_exists($this->bucket, $to)) {
             $this->xpdo->error->message = $this->xpdo->lexicon('file_err_ns') . ': ' . $to;
             return $success;
         }
         $toPath = rtrim($to, '/') . '/' . basename($from);
     } else {
         $toPath = basename($from);
     }
     $response = $this->driver->copy_object(array('bucket' => $this->bucket, 'filename' => $from), array('bucket' => $this->bucket, 'filename' => $toPath), array('acl' => AmazonS3::ACL_PUBLIC));
     $success = $response->isOK();
     if ($success) {
         $deleteResponse = $this->driver->delete_object($this->bucket, $from);
         $success = $deleteResponse->isOK();
     } else {
         $this->xpdo->error->message = $this->xpdo->lexicon('file_folder_err_rename') . ': ' . $to . ' -> ' . $from;
     }
     return $success;
 }
 /**
  * Checks whether an object exists.
  *
  * @param string $objectPath
  *
  * @return bool
  */
 protected function objectExists($objectPath)
 {
     return $this->storage->if_object_exists($this->bucket, $objectPath);
 }
 public function moveEpisodeFileToAmazon()
 {
     if (!$this->getAudioFile()) {
         throw new Exception("No local file to upload!");
     }
     $file_location = ProjectConfiguration::getEpisodeAudioFileLocalDirectory();
     $filename = $file_location . $this->getAudioFile();
     if (!file_exists($filename)) {
         throw new Exception("No local file to upload!");
     }
     ProjectConfiguration::registerAws();
     $s3 = new AmazonS3();
     $bucket = $this->getSubreddit()->getBucketName();
     if ($s3->if_bucket_exists($bucket)) {
         $nice_filename = $this->getNiceFilename();
         while ($s3->if_object_exists($bucket, $nice_filename)) {
             $nice_filename = $nice_filename . rand(0, 1000);
             $this->setNiceFilename($nice_filename);
         }
         $response = $s3->create_object($bucket, $this->getNiceFilename(), array('fileUpload' => $file_location . $this->getAudioFile(), 'acl' => AmazonS3::ACL_PUBLIC));
         if ($response->isOK()) {
             //$this->setRemoteUrl($s3->get_object_url($bucket,
             //                                        $this->getNiceFilename()));
             $this->setRemoteUrl('http://' . $this->getSubreddit()->getCfDomainName() . '/' . urlencode($this->getNiceFilename()));
             $this->deleteLocalFile($this->getAudioFile());
         }
     } else {
         throw new Exception("Amazon bucket '{$bucket}' does not exist!");
     }
     $this->setFileIsRemote(true);
 }