Skip to content

Instantly share code, notes, and snippets.

@mattcdavis1
Created September 7, 2017 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattcdavis1/2ca495fea90f3aad55e678893b606f8b to your computer and use it in GitHub Desktop.
Save mattcdavis1/2ca495fea90f3aad55e678893b606f8b to your computer and use it in GitHub Desktop.
Craft Transform Issue
<?php
/**
* Copy a transform for a file from source location to target location.
*
* @param AssetFileModel $file The assetFileModel that has the transform to copy.
* @param string $targetFolderPath The target folder path.
* @param AssetTransformIndexModel $source The source transform index data.
* @param AssetTransformIndexModel $target The destination transform index data.
*
* @return mixed
*/
public function copyTransform(AssetFileModel $file, $targetFolderPath, AssetTransformIndexModel $source, AssetTransformIndexModel $target)
{
$sourceTransformPath = $file->folderPath.craft()->assetTransforms->getTransformSubpath($file, $source);
$targetTransformPath = $targetFolderPath.craft()->assetTransforms->getTransformSubpath($file, $target);
if ($sourceTransformPath == $targetTransformPath)
{
return true;
}
return $this->copySourceFile($sourceTransformPath, $targetTransformPath);
}
<?php
/**
* @inheritDoc BaseAssetSourceType::copySourceFile()
*
* @param $sourceUri
* @param $targetUri
*
* @return bool
*/
protected function copySourceFile($sourceUri, $targetUri)
{
if ($sourceUri == $targetUri)
{
return true;
}
$bucket = $this->getSettings()->bucket;
if (is_null($this->_s3)) {
$this->_prepareForRequests();
}
return (bool) @$this->_s3->copyObject($bucket, $sourceUri, $bucket, $targetUri, $this->_getACL());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment