Something went wrong. Try again.
@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
Something went wrong. Try again.
3.4 kB · 142 lines
PHP
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143<?php
abstract class DiffusionFileFutureQuery extends DiffusionQuery {
private $timeout; private $byteLimit;
private $didHitByteLimit = false; private $didHitTimeLimit = false;
public static function getConduitParameters() { return array( 'timeout' => 'optional int', 'byteLimit' => 'optional int', ); }
public function setTimeout($timeout) { $this->timeout = $timeout; return $this; }
public function getTimeout() { return $this->timeout; }
public function setByteLimit($byte_limit) { $this->byteLimit = $byte_limit; return $this; }
public function getByteLimit() { return $this->byteLimit; }
final public function getExceededByteLimit() { return $this->didHitByteLimit; }
final public function getExceededTimeLimit() { return $this->didHitTimeLimit; }
abstract protected function newQueryFuture();
final public function respondToConduitRequest(ConduitAPIRequest $request) { $drequest = $this->getRequest();
$timeout = $request->getValue('timeout'); if ($timeout) { $this->setTimeout($timeout); }
$byte_limit = $request->getValue('byteLimit'); if ($byte_limit) { $this->setByteLimit($byte_limit); }
$file = $this->execute();
$too_slow = (bool)$this->getExceededTimeLimit(); $too_huge = (bool)$this->getExceededByteLimit();
$file_phid = null; if (!$too_slow && !$too_huge) { $repository = $drequest->getRepository(); $repository_phid = $repository->getPHID();
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); $file->attachToObject($repository_phid); unset($unguarded);
$file_phid = $file->getPHID(); }
return array( 'tooSlow' => $too_slow, 'tooHuge' => $too_huge, 'filePHID' => $file_phid, ); }
final public function executeInline() { $future = $this->newConfiguredQueryFuture(); list($stdout) = $future->resolvex(); return $stdout; }
final protected function executeQuery() { $future = $this->newConfiguredQueryFuture();
$drequest = $this->getRequest();
$name = basename($drequest->getPath()); $relative_ttl = phutil_units('48 hours in seconds');
try { $threshold = PhabricatorFileStorageEngine::getChunkThreshold(); $future->setReadBufferSize($threshold);
$source = id(new PhabricatorExecFutureFileUploadSource()) ->setName($name) ->setRelativeTTL($relative_ttl) ->setViewPolicy(PhabricatorPolicies::POLICY_NOONE) ->setExecFuture($future);
$byte_limit = $this->getByteLimit(); if ($byte_limit) { $source->setByteLimit($byte_limit); }
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); $file = $source->uploadFile(); unset($unguarded);
} catch (CommandException $ex) { if (!$future->getWasKilledByTimeout()) { throw $ex; }
$this->didHitTimeLimit = true; $file = null; } catch (PhabricatorFileUploadSourceByteLimitException $ex) { $this->didHitByteLimit = true; $file = null; }
return $file; }
private function newConfiguredQueryFuture() { $future = $this->newQueryFuture();
if ($this->getTimeout()) { $future->setTimeout($this->getTimeout()); }
return $future; }
}