[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhragmentPatchController extends PhragmentController { 4 5 private $aid; 6 private $bid; 7 8 public function shouldAllowPublic() { 9 return true; 10 } 11 12 public function willProcessRequest(array $data) { 13 $this->aid = idx($data, 'aid', 0); 14 $this->bid = idx($data, 'bid', 0); 15 } 16 17 public function processRequest() { 18 $request = $this->getRequest(); 19 $viewer = $request->getUser(); 20 21 // If "aid" is "x", then it means the user wants to generate 22 // a patch of an empty file to the version specified by "bid". 23 24 $ids = array($this->aid, $this->bid); 25 if ($this->aid === 'x') { 26 $ids = array($this->bid); 27 } 28 29 $versions = id(new PhragmentFragmentVersionQuery()) 30 ->setViewer($viewer) 31 ->withIDs($ids) 32 ->execute(); 33 34 $version_a = null; 35 if ($this->aid !== 'x') { 36 $version_a = idx($versions, $this->aid, null); 37 if ($version_a === null) { 38 return new Aphront404Response(); 39 } 40 } 41 42 $version_b = idx($versions, $this->bid, null); 43 if ($version_b === null) { 44 return new Aphront404Response(); 45 } 46 47 $file_phids = array(); 48 if ($version_a !== null) { 49 $file_phids[] = $version_a->getFilePHID(); 50 } 51 $file_phids[] = $version_b->getFilePHID(); 52 53 $files = id(new PhabricatorFileQuery()) 54 ->setViewer($viewer) 55 ->withPHIDs($file_phids) 56 ->execute(); 57 $files = mpull($files, null, 'getPHID'); 58 59 $file_a = null; 60 if ($version_a != null) { 61 $file_a = idx($files, $version_a->getFilePHID(), null); 62 } 63 $file_b = idx($files, $version_b->getFilePHID(), null); 64 65 $patch = PhragmentPatchUtil::calculatePatch($file_a, $file_b); 66 67 if ($patch === null) { 68 // There are no differences between the two files, so we output 69 // an empty patch. 70 $patch = ''; 71 } 72 73 $a_sequence = 'x'; 74 if ($version_a !== null) { 75 $a_sequence = $version_a->getSequence(); 76 } 77 78 $name = 79 $version_b->getFragment()->getName().'.'. 80 $a_sequence.'.'. 81 $version_b->getSequence().'.patch'; 82 83 $return = $version_b->getURI(); 84 if ($request->getExists('return')) { 85 $return = $request->getStr('return'); 86 } 87 88 $result = PhabricatorFile::buildFromFileDataOrHash( 89 $patch, 90 array( 91 'name' => $name, 92 'mime-type' => 'text/plain', 93 'ttl' => time() + 60 * 60 * 24, 94 )); 95 96 $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); 97 $result->attachToObject($version_b->getFragmentPHID()); 98 unset($unguarded); 99 100 return id(new AphrontRedirectResponse()) 101 ->setURI($result->getDownloadURI($return)); 102 } 103 104 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |