protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { $where = parent::buildWhereClauseParts($conn); if ($this->ids !== null) { $where[] = qsprintf($conn, 'service.id IN (%Ld)', $this->ids); } if ($this->phids !== null) { $where[] = qsprintf($conn, 'service.phid IN (%Ls)', $this->phids); } if ($this->names !== null) { $hashes = array(); foreach ($this->names as $name) { $hashes[] = PhabricatorHash::digestForIndex($name); } $where[] = qsprintf($conn, 'service.nameIndex IN (%Ls)', $hashes); } if ($this->serviceTypes !== null) { $where[] = qsprintf($conn, 'service.serviceType IN (%Ls)', $this->serviceTypes); } if ($this->devicePHIDs !== null) { $where[] = qsprintf($conn, 'binding.devicePHID IN (%Ls)', $this->devicePHIDs); } if ($this->namePrefix !== null) { $where[] = qsprintf($conn, 'service.name LIKE %>', $this->namePrefix); } if ($this->nameSuffix !== null) { $where[] = qsprintf($conn, 'service.name LIKE %<', $this->nameSuffix); } return $where; }
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { $where = array(); if ($this->ids !== null) { $where[] = qsprintf($conn_r, 'id IN (%Ld)', $this->ids); } if ($this->phids !== null) { $where[] = qsprintf($conn_r, 'phid IN (%Ls)', $this->phids); } if ($this->names !== null) { $hashes = array(); foreach ($this->names as $name) { $hashes[] = PhabricatorHash::digestForIndex($name); } $where[] = qsprintf($conn_r, 'nameIndex IN (%Ls)', $hashes); } if ($this->namePrefix !== null) { $where[] = qsprintf($conn_r, 'name LIKE %>', $this->namePrefix); } if ($this->nameSuffix !== null) { $where[] = qsprintf($conn_r, 'name LIKE %<', $this->nameSuffix); } $where[] = $this->buildPagingClause($conn_r); return $this->formatWhereClause($where); }
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { $where = parent::buildWhereClauseParts($conn); if ($this->ids !== null) { $where[] = qsprintf($conn, 'id IN (%Ld)', $this->ids); } if ($this->phids !== null) { $where[] = qsprintf($conn, 'phid IN (%Ls)', $this->phids); } if ($this->repositoryPHIDs !== null) { $where[] = qsprintf($conn, 'repositoryPHID IN (%Ls)', $this->repositoryPHIDs); } if ($this->refTypes !== null) { $where[] = qsprintf($conn, 'refType IN (%Ls)', $this->refTypes); } if ($this->refNames !== null) { $name_hashes = array(); foreach ($this->refNames as $name) { $name_hashes[] = PhabricatorHash::digestForIndex($name); } $where[] = qsprintf($conn, 'refNameHash IN (%Ls)', $name_hashes); } if (strlen($this->datasourceQuery)) { $where[] = qsprintf($conn, 'refNameRaw LIKE %>', $this->datasourceQuery); } return $where; }
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { $where = array(); if ($this->ids !== null) { $where[] = qsprintf($conn_r, 'id IN (%Ld)', $this->ids); } if ($this->phids !== null) { $where[] = qsprintf($conn_r, 'phid IN (%Ls)', $this->phids); } if ($this->emailAddresses !== null) { $where[] = qsprintf($conn_r, 'emailAddress IN (%Ls)', $this->emailAddresses); } if ($this->verificationCodes !== null) { $hashes = array(); foreach ($this->verificationCodes as $code) { $hashes[] = PhabricatorHash::digestForIndex($code); } $where[] = qsprintf($conn_r, 'verificationHash IN (%Ls)', $hashes); } if ($this->authorPHIDs !== null) { $where[] = qsprintf($conn_r, 'authorPHID IN (%Ls)', $this->authorPHIDs); } $where[] = $this->buildPagingClause($conn_r); return $this->formatWhereClause($where); }
public static function getArtifactIndex(HarbormasterBuildTarget $target, $artifact_key) { $build = $target->getBuild(); $parts = array($build->getPHID(), $target->getBuildGeneration(), $artifact_key); $parts = implode("", $parts); return PhabricatorHash::digestForIndex($parts); }
public function setRefName($ref_raw) { $this->setRefNameRaw($ref_raw); $this->setRefNameHash(PhabricatorHash::digestForIndex($ref_raw)); $this->setRefNameEncoding($this->detectEncodingForStorage($ref_raw)); return $this; }
public function save() { if (!$this->getVerificationHash()) { $hash = PhabricatorHash::digestForIndex($this->getVerificationCode()); $this->setVerificationHash($hash); } return parent::save(); }
public function getIndexVersion($object) { $ngrams = $object->newNgrams(); $map = mpull($ngrams, 'getValue', 'getNgramKey'); ksort($map); $serialized = serialize($map); return PhabricatorHash::digestForIndex($serialized); }
public function save() { AlmanacNames::validateName($this->getName()); $this->nameIndex = PhabricatorHash::digestForIndex($this->getName()); if (!$this->mailKey) { $this->mailKey = Filesystem::readRandomCharacters(20); } return parent::save(); }
protected function doWork() { $resource_phid = $this->getTaskDataValue('resourcePHID'); $hash = PhabricatorHash::digestForIndex($resource_phid); $lock_key = 'drydock.resource:' . $hash; $lock = PhabricatorGlobalLock::newLock($lock_key)->lock(1); $resource = $this->loadResource($resource_phid); $this->updateResource($resource); $lock->unlock(); }
public static function clearCacheForAllUsers($key) { if (PhabricatorEnv::isReadOnly()) { return; } $table = new self(); $conn_w = $table->establishConnection('w'); $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); queryfx($conn_w, 'DELETE FROM %T WHERE cacheIndex = %s', $table->getTableName(), PhabricatorHash::digestForIndex($key)); unset($unguarded); }
public function applyApplicationTransactionExternalEffects(PhabricatorApplicationTransaction $xaction) { $object = $this->getObject(); $phid = $object->getPHID(); $key = $this->getFieldKey(); $property = id(new AlmanacPropertyQuery())->setViewer($this->getViewer())->withObjectPHIDs(array($phid))->withNames(array($key))->executeOne(); if (!$property) { $property = id(new AlmanacProperty())->setObjectPHID($phid)->setFieldIndex(PhabricatorHash::digestForIndex($key))->setFieldName($key); } $property->setFieldValue($xaction->getNewValue())->save(); }
public function save() { if ($this->getEngineClassName() === null) { throw new Exception(pht('Engine class is null.')); } // Instantiate the engine to make sure it's valid. $this->newEngine(); $serial = $this->getEngineClassName() . serialize($this->parameters); $this->queryKey = PhabricatorHash::digestForIndex($serial); return parent::save(); }
public function handleRequest(AphrontRequest $request) { $show_prototypes = PhabricatorEnv::getEnvConfig('phabricator.show-prototypes'); if (!$show_prototypes) { throw new Exception(pht('Show prototypes is disabled. Set `phabricator.show-prototypes` to `true` to use the image proxy')); } $viewer = $request->getViewer(); $img_uri = $request->getStr('uri'); // Validate the URI before doing anything PhabricatorEnv::requireValidRemoteURIForLink($img_uri); $uri = new PhutilURI($img_uri); $proto = $uri->getProtocol(); if (!in_array($proto, array('http', 'https'))) { throw new Exception(pht('The provided image URI must be either http or https')); } // Check if we already have the specified image URI downloaded $cached_request = id(new PhabricatorFileExternalRequest())->loadOneWhere('uriIndex = %s', PhabricatorHash::digestForIndex($img_uri)); if ($cached_request) { return $this->getExternalResponse($cached_request); } $ttl = PhabricatorTime::getNow() + phutil_units('7 days in seconds'); $external_request = id(new PhabricatorFileExternalRequest())->setURI($img_uri)->setTTL($ttl); $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); // Cache missed so we'll need to validate and download the image try { // Rate limit outbound fetches to make this mechanism less useful for // scanning networks and ports. PhabricatorSystemActionEngine::willTakeAction(array($viewer->getPHID()), new PhabricatorFilesOutboundRequestAction(), 1); $file = PhabricatorFile::newFromFileDownload($uri, array('viewPolicy' => PhabricatorPolicies::POLICY_NOONE, 'canCDN' => true)); if (!$file->isViewableImage()) { $mime_type = $file->getMimeType(); $engine = new PhabricatorDestructionEngine(); $engine->destroyObject($file); $file = null; throw new Exception(pht('The URI "%s" does not correspond to a valid image file, got ' . 'a file with MIME type "%s". You must specify the URI of a ' . 'valid image file.', $uri, $mime_type)); } else { $file->save(); } $external_request->setIsSuccessful(true)->setFilePHID($file->getPHID())->save(); unset($unguarded); return $this->getExternalResponse($external_request); } catch (HTTPFutureHTTPResponseStatus $status) { $external_request->setIsSuccessful(false)->setResponseMessage($status->getMessage())->save(); return $this->getExternalResponse($external_request); } catch (Exception $ex) { // Not actually saving the request in this case $external_request->setResponseMessage($ex->getMessage()); return $this->getExternalResponse($external_request); } }
public function setHeaders(array $headers) { // Normalize headers to lowercase. $normalized = array(); foreach ($headers as $name => $value) { $name = $this->normalizeMailHeaderName($name); if ($name == 'message-id') { $this->setMessageIDHash(PhabricatorHash::digestForIndex($value)); } $normalized[$name] = $value; } $this->headers = $normalized; return $this; }
protected function doWork() { $lease_phid = $this->getTaskDataValue('leasePHID'); $hash = PhabricatorHash::digestForIndex($lease_phid); $lock_key = 'drydock.lease:' . $hash; $lock = PhabricatorGlobalLock::newLock($lock_key)->lock(1); try { $lease = $this->loadLease($lease_phid); $this->handleUpdate($lease); } catch (Exception $ex) { $lock->unlock(); throw $ex; } $lock->unlock(); }
protected function doWork() { $resource_phid = $this->getTaskDataValue('resourcePHID'); $hash = PhabricatorHash::digestForIndex($resource_phid); $lock_key = 'drydock.resource:' . $hash; $lock = PhabricatorGlobalLock::newLock($lock_key)->lock(1); try { $resource = $this->loadResource($resource_phid); $this->handleUpdate($resource); } catch (Exception $ex) { $lock->unlock(); $this->flushDrydockTaskQueue(); throw $ex; } $lock->unlock(); }
private function getEngine() { $options = $this->options; $viewer = $this->getViewer(); $viewer_key = $viewer->getCacheFragment(); ksort($options); $engine_key = serialize($options); $engine_key = PhabricatorHash::digestForIndex($engine_key); $cache = PhabricatorCaches::getRequestCache(); $cache_key = "remarkup.engine({$viewer_key}, {$engine_key})"; $engine = $cache->getKey($cache_key); if (!$engine) { $engine = PhabricatorMarkupEngine::newMarkupEngine($options); $cache->setKey($cache_key, $engine); } return $engine; }
public function testHashForIndex() { $map = array('dog' => 'Aliif7Qjd5ct', 'cat' => 'toudDsue3Uv8', 'rat' => 'RswaKgTjqOuj', 'bat' => 'rAkJKyX4YdYm'); foreach ($map as $input => $expect) { $this->assertEqual($expect, PhabricatorHash::digestForIndex($input), "Input: {$input}"); } // Test that the encoding produces 6 bits of entropy per byte. $entropy = array('dog', 'cat', 'rat', 'bat', 'dig', 'fig', 'cot', 'cut', 'fog', 'rig', 'rug', 'dug', 'mat', 'pat', 'eat', 'tar', 'pot'); $seen = array(); foreach ($entropy as $input) { $chars = preg_split('//', PhabricatorHash::digestForIndex($input)); foreach ($chars as $char) { $seen[$char] = true; } } $this->assertEqual(1 << 6, count($seen), "Distinct characters in hash of: {$input}"); }
protected function doWork() { $item_phid = $this->getTaskDataValue('itemPHID'); $hash = PhabricatorHash::digestForIndex($item_phid); $lock_key = "nuance.item.{$hash}"; $lock = PhabricatorGlobalLock::newLock($lock_key); $lock->lock(1); try { $item = $this->loadItem($item_phid); $this->updateItem($item); $this->routeItem($item); $this->applyCommands($item); } catch (Exception $ex) { $lock->unlock(); throw $ex; } $lock->unlock(); }
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { $where = parent::buildWhereClauseParts($conn); if ($this->ids !== null) { $where[] = qsprintf($conn, 'id IN (%Ld)', $this->ids); } if ($this->phids !== null) { $where[] = qsprintf($conn, 'phid IN (%Ls)', $this->phids); } if ($this->names !== null) { $name_indexes = array(); foreach ($this->names as $name) { $name_indexes[] = PhabricatorHash::digestForIndex($name); } $where[] = qsprintf($conn, 'nameIndex IN (%Ls)', $name_indexes); } return $where; }
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { $where = array(); if ($this->ids !== null) { $where[] = qsprintf($conn_r, 'id IN (%Ld)', $this->ids); } if ($this->objectPHIDs !== null) { $where[] = qsprintf($conn_r, 'objectPHID IN (%Ls)', $this->objectPHIDs); } if ($this->names !== null) { $hashes = array(); foreach ($this->names as $name) { $hashes[] = PhabricatorHash::digestForIndex($name); } $where[] = qsprintf($conn_r, 'fieldIndex IN (%Ls)', $hashes); } $where[] = $this->buildPagingClause($conn_r); return $this->formatWhereClause($where); }
private function buildWhereClause(AphrontDatabaseConnection $conn_r) { $where = array(); if ($this->repositoryPHIDs !== null) { $where[] = qsprintf($conn_r, 'repositoryPHID IN (%Ls)', $this->repositoryPHIDs); } if ($this->refTypes !== null) { $where[] = qsprintf($conn_r, 'refType IN (%Ls)', $this->refTypes); } if ($this->refNames !== null) { $name_hashes = array(); foreach ($this->refNames as $name) { $name_hashes[] = PhabricatorHash::digestForIndex($name); } $where[] = qsprintf($conn_r, 'refNameHash IN (%Ls)', $name_hashes); } $where[] = $this->buildPagingClause($conn_r); return $this->formatWhereClause($where); }
protected function buildWhereClause(AphrontDatabaseConnection $conn) { $where = array(); if ($this->ids !== null) { $where[] = qsprintf($conn, 'id IN (%Ld)', $this->ids); } if ($this->phids !== null) { $where[] = qsprintf($conn, 'phid IN (%Ls)', $this->phids); } if ($this->refMap !== null) { $sql = array(); foreach ($this->refMap as $class => $refs) { foreach ($refs as $ref) { $sql[] = qsprintf($conn, '(productClassKey = %s AND productRefKey = %s)', PhabricatorHash::digestForIndex($class), PhabricatorHash::digestForIndex($ref)); } } $where[] = implode(' OR ', $sql); } $where[] = $this->buildPagingClause($conn); return $this->formatWhereClause($where); }
/** * Resolve refs in Git and Mercurial repositories. * * We can resolve commit hashes from the commits table, and branch and tag * names from the refcursor table. */ private function resolveGitAndMercurialRefs() { $repository = $this->getRepository(); $conn_r = $repository->establishConnection('r'); $results = array(); $prefixes = array(); foreach ($this->refs as $ref) { // We require refs to look like hashes and be at least 4 characters // long. This is similar to the behavior of git. if (preg_match('/^[a-f0-9]{4,}$/', $ref)) { $prefixes[] = qsprintf($conn_r, '(commitIdentifier LIKE %>)', $ref); } } if ($prefixes) { $commits = queryfx_all($conn_r, 'SELECT commitIdentifier FROM %T WHERE repositoryID = %s AND %Q', id(new PhabricatorRepositoryCommit())->getTableName(), $repository->getID(), implode(' OR ', $prefixes)); foreach ($commits as $commit) { $hash = $commit['commitIdentifier']; foreach ($this->refs as $ref) { if (!strncmp($hash, $ref, strlen($ref))) { $results[$ref][] = array('type' => 'commit', 'identifier' => $hash); } } } } $name_hashes = array(); foreach ($this->refs as $ref) { $name_hashes[PhabricatorHash::digestForIndex($ref)] = $ref; } $cursors = queryfx_all($conn_r, 'SELECT refNameHash, refType, commitIdentifier, isClosed FROM %T WHERE repositoryPHID = %s AND refNameHash IN (%Ls)', id(new PhabricatorRepositoryRefCursor())->getTableName(), $repository->getPHID(), array_keys($name_hashes)); foreach ($cursors as $cursor) { if (isset($name_hashes[$cursor['refNameHash']])) { $results[$name_hashes[$cursor['refNameHash']]][] = array('type' => $cursor['refType'], 'identifier' => $cursor['commitIdentifier'], 'closed' => (bool) $cursor['isClosed']); // TODO: In Git, we don't store (and thus don't return) the hash // of the tag itself. It would be vaguely nice to do this. } } return $results; }
private function buildWhereClause(AphrontDatabaseConnection $conn_r) { $where = array(); if ($this->ids) { $where[] = qsprintf($conn_r, 'id IN (%Ld)', $this->ids); } if ($this->buildTargetPHIDs) { $where[] = qsprintf($conn_r, 'buildTargetPHID IN (%Ls)', $this->buildTargetPHIDs); } if ($this->artifactTypes) { $where[] = qsprintf($conn_r, 'artifactType in (%Ls)', $this->artifactTypes); } if ($this->artifactKeys) { $indexes = array(); foreach ($this->artifactKeys as $key) { $indexes[] = PhabricatorHash::digestForIndex($this->keyBuildPHID . $this->keyBuildGeneration . $key); } $where[] = qsprintf($conn_r, 'artifactIndex IN (%Ls)', $indexes); } $where[] = $this->buildPagingClause($conn_r); return $this->formatWhereClause($where); }
public function save() { $this->subscriptionClassKey = PhabricatorHash::digestForIndex($this->subscriptionClass); $this->subscriptionRefKey = PhabricatorHash::digestForIndex($this->subscriptionRef); $is_new = !$this->getID(); $this->openTransaction(); // If we're saving this subscription for the first time, we're also // going to set up the trigger for it. if ($is_new) { $trigger_phid = PhabricatorPHID::generateNewPHID(PhabricatorWorkerTriggerPHIDType::TYPECONST); $this->setTriggerPHID($trigger_phid); } $result = parent::save(); if ($is_new) { $trigger_action = new PhabricatorScheduleTaskTriggerAction(array('class' => 'PhortuneSubscriptionWorker', 'data' => array('subscriptionPHID' => $this->getPHID()), 'options' => array('objectPHID' => $this->getPHID(), 'priority' => PhabricatorWorker::PRIORITY_BULK))); $trigger = $this->getTrigger(); $trigger->setPHID($trigger_phid); $trigger->setAction($trigger_action); $trigger->save(); } $this->saveTransaction(); return $result; }
public function getMarkupFieldKey($field) { $hash = PhabricatorHash::digestForIndex($this->getMarkupText($field)); return "repo:{$hash}"; }
<?php $conn_w = id(new PhabricatorProject())->establishConnection('w'); $table_name = id(new PhabricatorProjectCustomFieldStorage())->getTableName(); $rows = new LiskRawMigrationIterator($conn_w, 'project_profile'); echo "Migrating project descriptions to custom storage...\n"; foreach ($rows as $row) { $phid = $row['projectPHID']; echo "Migrating {$phid}...\n"; $desc = $row['blurb']; if (strlen($desc)) { queryfx($conn_w, 'INSERT IGNORE INTO %T (objectPHID, fieldIndex, fieldValue) VALUES (%s, %s, %s)', $table_name, $phid, PhabricatorHash::digestForIndex('std:project:internal:description'), $desc); } } echo "Done.\n";
public function save() { $this->productClassKey = PhabricatorHash::digestForIndex($this->productClass); $this->productRefKey = PhabricatorHash::digestForIndex($this->productRef); return parent::save(); }