3 abstract class DiffusionFileFutureQuery
4 extends DiffusionQuery
{
9 private $didHitByteLimit = false;
10 private $didHitTimeLimit = false;
12 public static function getConduitParameters() {
14 'timeout' => 'optional int',
15 'byteLimit' => 'optional int',
19 public function setTimeout($timeout) {
20 $this->timeout
= $timeout;
24 public function getTimeout() {
25 return $this->timeout
;
28 public function setByteLimit($byte_limit) {
29 $this->byteLimit
= $byte_limit;
33 public function getByteLimit() {
34 return $this->byteLimit
;
37 final public function getExceededByteLimit() {
38 return $this->didHitByteLimit
;
41 final public function getExceededTimeLimit() {
42 return $this->didHitTimeLimit
;
45 abstract protected function newQueryFuture();
47 final public function respondToConduitRequest(ConduitAPIRequest
$request) {
48 $drequest = $this->getRequest();
50 $timeout = $request->getValue('timeout');
52 $this->setTimeout($timeout);
55 $byte_limit = $request->getValue('byteLimit');
57 $this->setByteLimit($byte_limit);
60 $file = $this->execute();
62 $too_slow = (bool)$this->getExceededTimeLimit();
63 $too_huge = (bool)$this->getExceededByteLimit();
66 if (!$too_slow && !$too_huge) {
67 $repository = $drequest->getRepository();
68 $repository_phid = $repository->getPHID();
70 $unguarded = AphrontWriteGuard
::beginScopedUnguardedWrites();
71 $file->attachToObject($repository_phid);
74 $file_phid = $file->getPHID();
78 'tooSlow' => $too_slow,
79 'tooHuge' => $too_huge,
80 'filePHID' => $file_phid,
84 final public function executeInline() {
85 $future = $this->newConfiguredQueryFuture();
86 list($stdout) = $future->resolvex();
90 final protected function executeQuery() {
91 $future = $this->newConfiguredQueryFuture();
93 $drequest = $this->getRequest();
95 $name = basename($drequest->getPath());
96 $relative_ttl = phutil_units('48 hours in seconds');
99 $threshold = PhabricatorFileStorageEngine
::getChunkThreshold();
100 $future->setReadBufferSize($threshold);
102 $source = id(new PhabricatorExecFutureFileUploadSource())
104 ->setRelativeTTL($relative_ttl)
105 ->setViewPolicy(PhabricatorPolicies
::POLICY_NOONE
)
106 ->setExecFuture($future);
108 $byte_limit = $this->getByteLimit();
110 $source->setByteLimit($byte_limit);
113 $unguarded = AphrontWriteGuard
::beginScopedUnguardedWrites();
114 $file = $source->uploadFile();
117 } catch (CommandException
$ex) {
118 if (!$future->getWasKilledByTimeout()) {
122 $this->didHitTimeLimit
= true;
124 } catch (PhabricatorFileUploadSourceByteLimitException
$ex) {
125 $this->didHitByteLimit
= true;
132 private function newConfiguredQueryFuture() {
133 $future = $this->newQueryFuture();
135 if ($this->getTimeout()) {
136 $future->setTimeout($this->getTimeout());