Differential D15072 Diff 36395 src/applications/diffusion/conduit/DiffusionFileContentQueryConduitAPIMethod.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/conduit/DiffusionFileContentQueryConduitAPIMethod.php
| Show All 33 Lines | if ($timeout) { | ||||
| $file_query->setTimeout($timeout); | $file_query->setTimeout($timeout); | ||||
| } | } | ||||
| $byte_limit = $request->getValue('byteLimit'); | $byte_limit = $request->getValue('byteLimit'); | ||||
| if ($byte_limit) { | if ($byte_limit) { | ||||
| $file_query->setByteLimit($byte_limit); | $file_query->setByteLimit($byte_limit); | ||||
| } | } | ||||
| $content = $file_query->execute(); | $file = $file_query->execute(); | ||||
| $too_slow = (bool)$file_query->getExceededTimeLimit(); | $too_slow = (bool)$file_query->getExceededTimeLimit(); | ||||
| $too_huge = (bool)$file_query->getExceededByteLimit(); | $too_huge = (bool)$file_query->getExceededByteLimit(); | ||||
| $file_phid = null; | $file_phid = null; | ||||
| if (!$too_slow && !$too_huge) { | if (!$too_slow && !$too_huge) { | ||||
| $file = $this->newFile($drequest, $content); | $repository = $drequest->getRepository(); | ||||
| $repository_phid = $repository->getPHID(); | |||||
| $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); | |||||
| $file->attachToObject($repository_phid); | |||||
| unset($unguarded); | |||||
| $file_phid = $file->getPHID(); | $file_phid = $file->getPHID(); | ||||
| } | } | ||||
| return array( | return array( | ||||
| 'tooSlow' => $too_slow, | 'tooSlow' => $too_slow, | ||||
| 'tooHuge' => $too_huge, | 'tooHuge' => $too_huge, | ||||
| 'filePHID' => $file_phid, | 'filePHID' => $file_phid, | ||||
| ); | ); | ||||
| } | } | ||||
| private function newFile(DiffusionRequest $drequest, $content) { | |||||
| $path = $drequest->getPath(); | |||||
| $name = basename($path); | |||||
| $repository = $drequest->getRepository(); | |||||
| $repository_phid = $repository->getPHID(); | |||||
| $file = PhabricatorFile::buildFromFileDataOrHash( | |||||
| $content, | |||||
| array( | |||||
| 'name' => $name, | |||||
| 'ttl' => time() + phutil_units('48 hours in seconds'), | |||||
| 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE, | |||||
| )); | |||||
| $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); | |||||
| $file->attachToObject($repository_phid); | |||||
| unset($unguarded); | |||||
| return $file; | |||||
| } | |||||
| } | } | ||||