Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phragment/controller/PhragmentZIPController.php
<?php | <?php | ||||
final class PhragmentZIPController extends PhragmentController { | final class PhragmentZIPController extends PhragmentController { | ||||
private $dblob; | private $dblob; | ||||
private $snapshot; | private $snapshot; | ||||
private $snapshotCache; | private $snapshotCache; | ||||
public function shouldAllowPublic() { | |||||
return true; | |||||
} | |||||
public function willProcessRequest(array $data) { | public function willProcessRequest(array $data) { | ||||
$this->dblob = idx($data, "dblob", ""); | $this->dblob = idx($data, "dblob", ""); | ||||
$this->snapshot = idx($data, "snapshot", null); | $this->snapshot = idx($data, "snapshot", null); | ||||
} | } | ||||
public function processRequest() { | public function processRequest() { | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
$viewer = $request->getUser(); | $viewer = $request->getUser(); | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | public function processRequest() { | ||||
foreach ($mappings as $path => $file_phid) { | foreach ($mappings as $path => $file_phid) { | ||||
if (!isset($files[$file_phid])) { | if (!isset($files[$file_phid])) { | ||||
unset($mappings[$path]); | unset($mappings[$path]); | ||||
} | } | ||||
$mappings[$path] = $files[$file_phid]; | $mappings[$path] = $files[$file_phid]; | ||||
} | } | ||||
foreach ($mappings as $path => $file) { | foreach ($mappings as $path => $file) { | ||||
if ($file !== null) { | |||||
$zip->addFromString($path, $file->loadFileData()); | $zip->addFromString($path, $file->loadFileData()); | ||||
} | } | ||||
} | |||||
$zip->close(); | $zip->close(); | ||||
$zip_name = $fragment->getName(); | $zip_name = $fragment->getName(); | ||||
if (substr($zip_name, -4) !== '.zip') { | if (substr($zip_name, -4) !== '.zip') { | ||||
$zip_name .= '.zip'; | $zip_name .= '.zip'; | ||||
} | } | ||||
$data = Filesystem::readFile((string)$temp); | $data = Filesystem::readFile((string)$temp); | ||||
$file = PhabricatorFile::buildFromFileDataOrHash( | $file = PhabricatorFile::buildFromFileDataOrHash( | ||||
$data, | $data, | ||||
array( | array( | ||||
'name' => $zip_name, | 'name' => $zip_name, | ||||
'ttl' => time() + 60 * 60 * 24, | 'ttl' => time() + 60 * 60 * 24, | ||||
)); | )); | ||||
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); | |||||
$file->attachToObject($viewer, $fragment->getPHID()); | |||||
unset($unguarded); | |||||
$return = $fragment->getURI(); | |||||
if ($request->getExists('return')) { | |||||
$return = $request->getStr('return'); | |||||
} | |||||
return id(new AphrontRedirectResponse()) | return id(new AphrontRedirectResponse()) | ||||
->setURI($file->getBestURI()); | ->setURI($file->getDownloadURI($return)); | ||||
} | } | ||||
/** | /** | ||||
* Returns a list of mappings like array('some/path.txt' => 'file PHID'); | * Returns a list of mappings like array('some/path.txt' => 'file PHID'); | ||||
*/ | */ | ||||
private function getFragmentMappings(PhragmentFragment $current, $base_path) { | private function getFragmentMappings(PhragmentFragment $current, $base_path) { | ||||
$mappings = $current->getFragmentMappings( | $mappings = $current->getFragmentMappings( | ||||
$this->getRequest()->getUser(), | $this->getRequest()->getUser(), | ||||
Show All 21 Lines |