Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / diffusion / query / DiffusionFileFutureQuery.php
blob18779e5fb8d6166b36ee0d84477357cbfb1a0d50
1 <?php
3 abstract class DiffusionFileFutureQuery
4 extends DiffusionQuery {
6 private $timeout;
7 private $byteLimit;
9 private $didHitByteLimit = false;
10 private $didHitTimeLimit = false;
12 public static function getConduitParameters() {
13 return array(
14 'timeout' => 'optional int',
15 'byteLimit' => 'optional int',
19 public function setTimeout($timeout) {
20 $this->timeout = $timeout;
21 return $this;
24 public function getTimeout() {
25 return $this->timeout;
28 public function setByteLimit($byte_limit) {
29 $this->byteLimit = $byte_limit;
30 return $this;
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');
51 if ($timeout) {
52 $this->setTimeout($timeout);
55 $byte_limit = $request->getValue('byteLimit');
56 if ($byte_limit) {
57 $this->setByteLimit($byte_limit);
60 $file = $this->execute();
62 $too_slow = (bool)$this->getExceededTimeLimit();
63 $too_huge = (bool)$this->getExceededByteLimit();
65 $file_phid = null;
66 if (!$too_slow && !$too_huge) {
67 $repository = $drequest->getRepository();
68 $repository_phid = $repository->getPHID();
70 $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
71 $file->attachToObject($repository_phid);
72 unset($unguarded);
74 $file_phid = $file->getPHID();
77 return array(
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();
87 return $stdout;
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');
98 try {
99 $threshold = PhabricatorFileStorageEngine::getChunkThreshold();
100 $future->setReadBufferSize($threshold);
102 $source = id(new PhabricatorExecFutureFileUploadSource())
103 ->setName($name)
104 ->setRelativeTTL($relative_ttl)
105 ->setViewPolicy(PhabricatorPolicies::POLICY_NOONE)
106 ->setExecFuture($future);
108 $byte_limit = $this->getByteLimit();
109 if ($byte_limit) {
110 $source->setByteLimit($byte_limit);
113 $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
114 $file = $source->uploadFile();
115 unset($unguarded);
117 } catch (CommandException $ex) {
118 if (!$future->getWasKilledByTimeout()) {
119 throw $ex;
122 $this->didHitTimeLimit = true;
123 $file = null;
124 } catch (PhabricatorFileUploadSourceByteLimitException $ex) {
125 $this->didHitByteLimit = true;
126 $file = null;
129 return $file;
132 private function newConfiguredQueryFuture() {
133 $future = $this->newQueryFuture();
135 if ($this->getTimeout()) {
136 $future->setTimeout($this->getTimeout());
139 return $future;