/** * @param $relativeDestinationPath * @param $destinationFilename * @param \CIC\Cicbase\Domain\Model\File $fileObject * @param boolean $isFinalDestination * @return \TYPO3\CMS\Extbase\Error\Error * @throws \Exception */ protected function moveToAWSDestination($relativeDestinationPath, $destinationFilename, \CIC\Cicbase\Domain\Model\File $fileObject, $isFinalDestination) { // make sure we have adequate configuration. if (!$this->cicbaseConfiguration['AWSTemporaryBucketName'] || !$this->cicbaseConfiguration['AWSPermanentBucketName'] || !$this->cicbaseConfiguration['AWSKey'] || !$this->cicbaseConfiguration['AWSSecret']) { throw new \Exception('AWS File Storage is enabled, yet it is not properly configured in the extension manager'); } // initialize the S3 object. $s3 = $this->initializeS3(); // get the destination bucket. if ($isFinalDestination) { $destinationBucket = $this->cicbaseConfiguration['AWSPermanentBucketName']; } else { $destinationBucket = $this->cicbaseConfiguration['AWSTemporaryBucketName']; } // source path $source = $fileObject->getPath(); if ($fileObject->getAwsbucket()) { // copy it to another bucket $sourceBucket = $fileObject->getAwsbucket(); $sourceConfig = array('bucket' => $sourceBucket, 'filename' => $source . '/' . $fileObject->getFilename()); $destinationConfig = array('bucket' => $destinationBucket, 'filename' => $relativeDestinationPath . '/' . $destinationFilename); $response = $s3->copy_object($sourceConfig, $destinationConfig, array('acl' => \AmazonS3::ACL_PUBLIC)); if ($response->isOk()) { $deleteResponse = $s3->delete_object($sourceBucket, $source . '/' . $fileObject->getFilename()); } else { return new \TYPO3\CMS\Extbase\Error\Error('Unable to save file to AWS S3', 1336600878); } } else { // create a new object $response = $s3->create_object($destinationBucket, $relativeDestinationPath . '/' . $destinationFilename, array('fileUpload' => $source, 'contentType' => $fileObject->getMimeType())); } if ($response->isOK()) { $fileObject->setFilename($destinationFilename); $fileObject->setPath($relativeDestinationPath); $fileObject->setAwsBucket($destinationBucket); } else { return new \TYPO3\CMS\Extbase\Error\Error('Unable to save file to AWS S3', 1336600875); } }
/** * @param \CIC\Cicbase\Domain\Model\File|\TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy|\TYPO3\CMS\Extbase\Domain\Model\FileReference $file * @param string $class * @param string $linkText * @return string */ public function render($file, $class = null, $linkText = null) { if ($file instanceof \TYPO3\CMS\Extbase\Domain\Model\FileReference) { $uri = $file->getOriginalResource()->getPublicUrl(); } elseif ($file) { $uri = $file->getPathAndFileName(); } else { return ''; } if ($linkText) { $text = $linkText; } elseif ($file->getTitle()) { $text = $file->getTitle(); } else { $text = $file->getOriginalFilename(); } if ($class) { $classAttr = 'class="' . $class . '"'; } else { $classAttr = ''; } return '<a target="_blank" href="' . $uri . '" ' . $classAttr . '>' . $text . '</a>'; }