diff --git a/src/applications/auth/controller/PhabricatorAuthRegisterController.php b/src/applications/auth/controller/PhabricatorAuthRegisterController.php index fdd0bc81ce..9b1eafd415 100644 --- a/src/applications/auth/controller/PhabricatorAuthRegisterController.php +++ b/src/applications/auth/controller/PhabricatorAuthRegisterController.php @@ -710,7 +710,7 @@ final class PhabricatorAuthRegisterController $xform = PhabricatorFileTransform::getTransformByKey( PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE); - return $xform->executeTransform($file); + return $xform->executeTransformExplicit($file); } protected function renderError($message) { diff --git a/src/applications/conpherence/controller/ConpherenceRoomPictureController.php b/src/applications/conpherence/controller/ConpherenceRoomPictureController.php index 5be8331610..47a0576d70 100644 --- a/src/applications/conpherence/controller/ConpherenceRoomPictureController.php +++ b/src/applications/conpherence/controller/ConpherenceRoomPictureController.php @@ -66,7 +66,7 @@ final class ConpherenceRoomPictureController } else { $xform = PhabricatorFileTransform::getTransformByKey( PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE); - $xformed = $xform->executeTransform($file); + $xformed = $xform->executeTransformExplicit($file); } } diff --git a/src/applications/diffusion/controller/DiffusionRepositoryProfilePictureController.php b/src/applications/diffusion/controller/DiffusionRepositoryProfilePictureController.php index 59a49def6f..d2e7700c98 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryProfilePictureController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryProfilePictureController.php @@ -67,7 +67,7 @@ final class DiffusionRepositoryProfilePictureController } else { $xform = PhabricatorFileTransform::getTransformByKey( PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE); - $xformed = $xform->executeTransform($file); + $xformed = $xform->executeTransformExplicit($file); } } diff --git a/src/applications/files/transform/PhabricatorFileTransform.php b/src/applications/files/transform/PhabricatorFileTransform.php index a60a3d4b37..acad6d6d61 100644 --- a/src/applications/files/transform/PhabricatorFileTransform.php +++ b/src/applications/files/transform/PhabricatorFileTransform.php @@ -27,6 +27,30 @@ abstract class PhabricatorFileTransform extends Phobject { return $this->getDefaultTransform($file); } + /** + * Wrapper of executeTransform() that also persists the relationship + * between the original file and the transform, if it makes sense to do so. + */ + public function executeTransformExplicit(PhabricatorFile $file) { + // This can be NULL. + $xform = $this->executeTransform($file); + + // Connect the original file to its transform, if any. + // Skip transforms that are derived from a builtin as cautionary measure: + // - Builtins may have a lot of transforms. We don't know if the UX scales. + // Example page: /file/transforms/1/ + // - Tracking builtins gives unclear benefits. + if ($xform && !$file->isBuiltin()) { + id(new PhabricatorTransformedFile()) + ->setOriginalPHID($file->getPHID()) + ->setTransformedPHID($xform->getPHID()) + ->setTransform($this->getTransformKey()) + ->save(); + } + + return $xform; + } + public static function getAllTransforms() { return id(new PhutilClassMapQuery()) ->setAncestorClass(__CLASS__) diff --git a/src/applications/maniphest/xaction/ManiphestTaskCoverImageTransaction.php b/src/applications/maniphest/xaction/ManiphestTaskCoverImageTransaction.php index 0c057f54f5..7d8d986e29 100644 --- a/src/applications/maniphest/xaction/ManiphestTaskCoverImageTransaction.php +++ b/src/applications/maniphest/xaction/ManiphestTaskCoverImageTransaction.php @@ -30,14 +30,7 @@ final class ManiphestTaskCoverImageTransaction // Generate an image transformation, usually smaller (orphan now). $xform_key = PhabricatorFileThumbnailTransform::TRANSFORM_WORKCARD; $xform = PhabricatorFileTransform::getTransformByKey($xform_key) - ->executeTransform($file); - - // Make that image transformation non-orphan. - id(new PhabricatorTransformedFile()) - ->setOriginalPHID($file_phid) - ->setTransformedPHID($xform->getPHID()) - ->setTransform($xform_key) - ->save(); + ->executeTransformExplicit($file); $object->setProperty('cover.filePHID', $file->getPHID()); $object->setProperty('cover.thumbnailPHID', $xform->getPHID()); diff --git a/src/applications/people/controller/PhabricatorPeopleProfilePictureController.php b/src/applications/people/controller/PhabricatorPeopleProfilePictureController.php index e5d04254e6..fb2c5c6a62 100644 --- a/src/applications/people/controller/PhabricatorPeopleProfilePictureController.php +++ b/src/applications/people/controller/PhabricatorPeopleProfilePictureController.php @@ -76,7 +76,7 @@ final class PhabricatorPeopleProfilePictureController $e_file = pht('Not Supported'); $errors[] = $supported_formats_message; } else { - $xformed = $xform->executeTransform($file); + $xformed = $xform->executeTransformExplicit($file); } } diff --git a/src/applications/phame/controller/blog/PhameBlogProfilePictureController.php b/src/applications/phame/controller/blog/PhameBlogProfilePictureController.php index 91daa784cd..1f0488cce4 100644 --- a/src/applications/phame/controller/blog/PhameBlogProfilePictureController.php +++ b/src/applications/phame/controller/blog/PhameBlogProfilePictureController.php @@ -66,7 +66,7 @@ final class PhameBlogProfilePictureController } else { $xform = PhabricatorFileTransform::getTransformByKey( PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE); - $xformed = $xform->executeTransform($file); + $xformed = $xform->executeTransformExplicit($file); } } diff --git a/src/applications/phortune/controller/merchant/PhortuneMerchantPictureController.php b/src/applications/phortune/controller/merchant/PhortuneMerchantPictureController.php index a3b9ada7af..86268280a0 100644 --- a/src/applications/phortune/controller/merchant/PhortuneMerchantPictureController.php +++ b/src/applications/phortune/controller/merchant/PhortuneMerchantPictureController.php @@ -56,7 +56,7 @@ final class PhortuneMerchantPictureController } else { $xform = PhabricatorFileTransform::getTransformByKey( PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE); - $xformed = $xform->executeTransform($file); + $xformed = $xform->executeTransformExplicit($file); } } diff --git a/src/applications/project/controller/PhabricatorProjectEditPictureController.php b/src/applications/project/controller/PhabricatorProjectEditPictureController.php index b41439e8d3..886e506bae 100644 --- a/src/applications/project/controller/PhabricatorProjectEditPictureController.php +++ b/src/applications/project/controller/PhabricatorProjectEditPictureController.php @@ -75,7 +75,7 @@ final class PhabricatorProjectEditPictureController $e_file = pht('Not Supported'); $errors[] = $supported_formats_message; } else { - $xformed = $xform->executeTransform($file); + $xformed = $xform->executeTransformExplicit($file); } }