diff --git a/src/applications/files/transform/PhabricatorFileTransform.php b/src/applications/files/transform/PhabricatorFileTransform.php index 292640b1c9..cfec8aa335 100644 --- a/src/applications/files/transform/PhabricatorFileTransform.php +++ b/src/applications/files/transform/PhabricatorFileTransform.php @@ -15,6 +15,46 @@ abstract class PhabricatorFileTransform extends Phobject { return array($this); } + /** + * Get an existing transformed file, or create a new transformed file if no + * transformed file already exists. + * If a new file is produced, it is connected to the original file + * in an explicit way, so, persisting a new 'PhabricatorTransformedFile' row. + * + * @param PhabricatorFile $file Original file. + * You must check yourself if the viewer has + * sufficient permissions to see this file. + * @return PhabricatorFile Transformed file + */ + public function getOrExecuteTransformExplicit(PhabricatorFile $file) { + // Use of omnipotent user is okay here because the assume + // the user can see the input $file, and so, its transforms. + // See PhabricatorFile::hasAutomaticCapability(). + $xformed_file = id(new PhabricatorFileQuery()) + ->setViewer(PhabricatorUser::getOmnipotentUser()) + ->withTransforms( + array( + array( + 'originalPHID' => $file->getPHID(), + 'transform' => $this->getTransformKey(), + ), + )) + ->executeOne(); + + if ($xformed_file) { + return $xformed_file; + } + + return $this->executeTransformExplicit($file); + } + + /** + * Create a new transformed file. + * This usually causes the creation of a new 'PhabricatorFile'. + * + * @param PhabricatorFile $file Original file + * @return PhabricatorFile Transformed file + */ public function executeTransform(PhabricatorFile $file) { if ($this->canApplyTransform($file)) { try { @@ -30,6 +70,9 @@ abstract class PhabricatorFileTransform extends Phobject { /** * Wrapper of executeTransform() that also persists the relationship * between the original file and the transform, if it makes sense to do so. + * + * @param PhabricatorFile $file Original file + * @return PhabricatorFile Transformed file */ public function executeTransformExplicit(PhabricatorFile $file) { // This can be NULL. diff --git a/src/applications/people/controller/PhabricatorPeopleProfilePictureController.php b/src/applications/people/controller/PhabricatorPeopleProfilePictureController.php index ed2c0ea84b..b000e21059 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->executeTransformExplicit($file); + $xformed = $xform->getOrExecuteTransformExplicit($file); } } diff --git a/src/infrastructure/lint/linter/__tests__/map.php b/src/infrastructure/lint/linter/__tests__/map.php index d0a99e3017..fae3e4d3c1 100644 --- a/src/infrastructure/lint/linter/__tests__/map.php +++ b/src/infrastructure/lint/linter/__tests__/map.php @@ -15,7 +15,7 @@ return array( 'unnecessary-dependency.lint-test' => '1608e0c1', ), 'symbols' => array( - 'javelin-test' => 'e575f333', + 'javelin-test' => '3f966f42', ), 'requires' => array( '1608e0c1' => array(