コード例 #1
0
 private function buildRawFileResponse(DifferentialChangeset $changeset, $is_new)
 {
     $viewer = $this->getViewer();
     if ($is_new) {
         $key = 'raw:new:phid';
     } else {
         $key = 'raw:old:phid';
     }
     $metadata = $changeset->getMetadata();
     $file = null;
     $phid = idx($metadata, $key);
     if ($phid) {
         $file = id(new PhabricatorFileQuery())->setViewer($viewer)->withPHIDs(array($phid))->execute();
         if ($file) {
             $file = head($file);
         }
     }
     if (!$file) {
         // This is just building a cache of the changeset content in the file
         // tool, and is safe to run on a read pathway.
         $unguard = AphrontWriteGuard::beginScopedUnguardedWrites();
         if ($is_new) {
             $data = $changeset->makeNewFile();
         } else {
             $data = $changeset->makeOldFile();
         }
         $file = PhabricatorFile::newFromFileData($data, array('name' => $changeset->getFilename(), 'mime-type' => 'text/plain'));
         $metadata[$key] = $file->getPHID();
         $changeset->setMetadata($metadata);
         $changeset->save();
         unset($unguard);
     }
     return $file->getRedirectResponse();
 }