Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phragment/controller/PhragmentPatchController.php
<?php | <?php | ||||
final class PhragmentPatchController extends PhragmentController { | final class PhragmentPatchController extends PhragmentController { | ||||
private $aid; | private $aid; | ||||
private $bid; | private $bid; | ||||
public function shouldAllowPublic() { | |||||
return true; | |||||
} | |||||
public function willProcessRequest(array $data) { | public function willProcessRequest(array $data) { | ||||
$this->aid = idx($data, "aid", 0); | $this->aid = idx($data, "aid", 0); | ||||
$this->bid = idx($data, "bid", 0); | $this->bid = idx($data, "bid", 0); | ||||
} | } | ||||
public function processRequest() { | public function processRequest() { | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
$viewer = $request->getUser(); | $viewer = $request->getUser(); | ||||
Show All 40 Lines | public function processRequest() { | ||||
if ($version_a != null) { | if ($version_a != null) { | ||||
$file_a = idx($files, $version_a->getFilePHID(), null); | $file_a = idx($files, $version_a->getFilePHID(), null); | ||||
} | } | ||||
$file_b = idx($files, $version_b->getFilePHID(), null); | $file_b = idx($files, $version_b->getFilePHID(), null); | ||||
$patch = PhragmentPatchUtil::calculatePatch($file_a, $file_b); | $patch = PhragmentPatchUtil::calculatePatch($file_a, $file_b); | ||||
if ($patch === null) { | if ($patch === null) { | ||||
throw new Exception("Unable to compute patch!"); | // There are no differences between the two files, so we output | ||||
// an empty patch. | |||||
$patch = ''; | |||||
} | } | ||||
$a_sequence = 'x'; | $a_sequence = 'x'; | ||||
if ($version_a !== null) { | if ($version_a !== null) { | ||||
$a_sequence = $version_a->getSequence(); | $a_sequence = $version_a->getSequence(); | ||||
} | } | ||||
$name = | $name = | ||||
$version_b->getFragment()->getName().'.'. | $version_b->getFragment()->getName().'.'. | ||||
$a_sequence.'.'. | $a_sequence.'.'. | ||||
$version_b->getSequence().'.patch'; | $version_b->getSequence().'.patch'; | ||||
$return = $version_b->getURI(); | |||||
if ($request->getExists('return')) { | |||||
$return = $request->getStr('return'); | |||||
} | |||||
$result = PhabricatorFile::buildFromFileDataOrHash( | $result = PhabricatorFile::buildFromFileDataOrHash( | ||||
$patch, | $patch, | ||||
array( | array( | ||||
'name' => $name, | 'name' => $name, | ||||
'mime-type' => 'text/plain', | 'mime-type' => 'text/plain', | ||||
'ttl' => time() + 60 * 60 * 24, | 'ttl' => time() + 60 * 60 * 24, | ||||
)); | )); | ||||
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); | |||||
$result->attachToObject($viewer, $version_b->getFragmentPHID()); | |||||
unset($unguarded); | |||||
return id(new AphrontRedirectResponse()) | return id(new AphrontRedirectResponse()) | ||||
epriestley: Maybe easier to just attach it to the fragment itself. | |||||
->setURI($result->getBestURI()); | ->setURI($result->getDownloadURI($return)); | ||||
} | } | ||||
} | } |
Maybe easier to just attach it to the fragment itself.