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);
 }
 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn)
 {
     $where = parent::buildWhereClauseParts($conn);
     if ($this->phids !== null) {
         $where[] = qsprintf($conn, 'p.phid IN (%Ls)', $this->phids);
     }
     if ($this->ids !== null) {
         $where[] = qsprintf($conn, 'p.id IN (%Ld)', $this->ids);
     }
     if ($this->repositoryPHIDs !== null) {
         $where[] = qsprintf($conn, 'rpath.repositoryPHID IN (%Ls)', $this->repositoryPHIDs);
     }
     if ($this->ownerPHIDs !== null) {
         $base_phids = $this->ownerPHIDs;
         $projects = id(new PhabricatorProjectQuery())->setViewer($this->getViewer())->withMemberPHIDs($base_phids)->execute();
         $project_phids = mpull($projects, 'getPHID');
         $all_phids = array_merge($base_phids, $project_phids);
         $where[] = qsprintf($conn, 'o.userPHID IN (%Ls)', $all_phids);
     }
     if (strlen($this->namePrefix)) {
         // NOTE: This is a hacky mess, but this column is currently case
         // sensitive and unique.
         $where[] = qsprintf($conn, 'LOWER(p.name) LIKE %>', phutil_utf8_strtolower($this->namePrefix));
     }
     return $where;
 }
 protected function buildWhereClauseComponents(AphrontDatabaseConnection $conn_r)
 {
     $where = array();
     if ($this->ids !== null) {
         $where[] = qsprintf($conn_r, 'xcomment.id IN (%Ld)', $this->ids);
     }
     if ($this->phids !== null) {
         $where[] = qsprintf($conn_r, 'xcomment.phid IN (%Ls)', $this->phids);
     }
     if ($this->authorPHIDs !== null) {
         $where[] = qsprintf($conn_r, 'xcomment.authorPHID IN (%Ls)', $this->authorPHIDs);
     }
     if ($this->transactionPHIDs !== null) {
         $where[] = qsprintf($conn_r, 'xcomment.transactionPHID IN (%Ls)', $this->transactionPHIDs);
     }
     if ($this->isDeleted !== null) {
         $where[] = qsprintf($conn_r, 'xcomment.isDeleted = %d', (int) $this->isDeleted);
     }
     if ($this->hasTransaction !== null) {
         if ($this->hasTransaction) {
             $where[] = qsprintf($conn_r, 'xcomment.transactionPHID IS NOT NULL');
         } else {
             $where[] = qsprintf($conn_r, 'xcomment.transactionPHID IS NULL');
         }
     }
     return $where;
 }
 private static function loadPackagesForPaths(PhabricatorRepository $repository, array $paths, $limit = 0)
 {
     $package = new PhabricatorOwnersPackage();
     $path = new PhabricatorOwnersPath();
     $conn = $package->establishConnection('r');
     $repository_clause = qsprintf($conn, 'AND p.repositoryPHID = %s', $repository->getPHID());
     $limit_clause = '';
     if (!empty($limit)) {
         $limit_clause = qsprintf($conn, 'LIMIT %d', $limit);
     }
     $data = queryfx_all($conn, 'SELECT pkg.id FROM %T pkg JOIN %T p ON p.packageID = pkg.id
     WHERE p.path IN (%Ls) %Q ORDER BY LENGTH(p.path) DESC %Q', $package->getTableName(), $path->getTableName(), $paths, $repository_clause, $limit_clause);
     $ids = ipull($data, 'id');
     if (empty($ids)) {
         return array();
     }
     $order = array();
     foreach ($ids as $id) {
         if (empty($order[$id])) {
             $order[$id] = true;
         }
     }
     $packages = $package->loadAllWhere('id in (%Ld)', array_keys($order));
     $packages = array_select_keys($packages, array_keys($order));
     return $packages;
 }
 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn)
 {
     $where = parent::buildWhereClauseParts($conn);
     if ($this->callerPHIDs !== null) {
         $where[] = qsprintf($conn, 'callerPHID IN (%Ls)', $this->callerPHIDs);
     }
     if ($this->methods !== null) {
         $where[] = qsprintf($conn, 'method IN (%Ls)', $this->methods);
     }
     if ($this->methodStatuses !== null) {
         $statuses = array_fuse($this->methodStatuses);
         $methods = id(new PhabricatorConduitMethodQuery())->setViewer($this->getViewer())->execute();
         $method_names = array();
         foreach ($methods as $method) {
             $status = $method->getMethodStatus();
             if (isset($statuses[$status])) {
                 $method_names[] = $method->getAPIMethodName();
             }
         }
         if (!$method_names) {
             throw new PhabricatorEmptyQueryException();
         }
         $where[] = qsprintf($conn, 'method IN (%Ls)', $method_names);
     }
     return $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->objectPHIDs !== null) {
         $where[] = qsprintf($conn, 'objectPHID IN (%Ls)', $this->objectPHIDs);
     }
     if ($this->keys !== null) {
         $sql = array();
         foreach ($this->keys as $key) {
             $sql[] = qsprintf($conn, '(keyType = %s AND keyIndex = %s)', $key->getType(), $key->getHash());
         }
         $where[] = implode(' OR ', $sql);
     }
     if ($this->isActive !== null) {
         if ($this->isActive) {
             $where[] = qsprintf($conn, 'isActive = %d', 1);
         } else {
             $where[] = qsprintf($conn, 'isActive IS NULL');
         }
     }
     return $where;
 }
 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn)
 {
     $where = parent::buildWhereClauseParts($conn);
     if ($this->ids !== null) {
         $where[] = qsprintf($conn, 'id IN (%Ld)', $this->ids);
     }
     if ($this->tokenResources !== null) {
         $where[] = qsprintf($conn, 'tokenResource IN (%Ls)', $this->tokenResources);
     }
     if ($this->tokenTypes !== null) {
         $where[] = qsprintf($conn, 'tokenType IN (%Ls)', $this->tokenTypes);
     }
     if ($this->expired !== null) {
         if ($this->expired) {
             $where[] = qsprintf($conn, 'tokenExpires <= %d', time());
         } else {
             $where[] = qsprintf($conn, 'tokenExpires > %d', time());
         }
     }
     if ($this->tokenCodes !== null) {
         $where[] = qsprintf($conn, 'tokenCode IN (%Ls)', $this->tokenCodes);
     }
     if ($this->userPHIDs !== null) {
         $where[] = qsprintf($conn, 'userPHID IN (%Ls)', $this->userPHIDs);
     }
     return $where;
 }
 protected function buildWhereClause($conn_r)
 {
     $where = array();
     if ($this->ids) {
         $where[] = qsprintf($conn_r, 'id IN (%Ld)', $this->ids);
     }
     if ($this->phids) {
         $where[] = qsprintf($conn_r, 'phid IN (%Ls)', $this->phids);
     }
     if ($this->rangeBegin) {
         $where[] = qsprintf($conn_r, 'dateTo >= %d', $this->rangeBegin);
     }
     if ($this->rangeEnd) {
         $where[] = qsprintf($conn_r, 'dateFrom <= %d', $this->rangeEnd);
     }
     // TODO: Currently, the creator is always the only invitee, but you can
     // query them separately since this won't always be true.
     if ($this->invitedPHIDs) {
         $where[] = qsprintf($conn_r, 'userPHID IN (%Ls)', $this->invitedPHIDs);
     }
     if ($this->creatorPHIDs) {
         $where[] = qsprintf($conn_r, 'userPHID IN (%Ls)', $this->creatorPHIDs);
     }
     $where[] = $this->buildPagingClause($conn_r);
     return $this->formatWhereClause($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->tokens !== null) {
         $where[] = qsprintf($conn_r, 'token IN (%Ls)', $this->tokens);
     }
     if ($this->tokenTypes !== null) {
         $where[] = qsprintf($conn_r, 'tokenType IN (%Ls)', $this->tokenTypes);
     }
     if ($this->expired !== null) {
         if ($this->expired) {
             $where[] = qsprintf($conn_r, 'expires <= %d', PhabricatorTime::getNow());
         } else {
             $where[] = qsprintf($conn_r, 'expires IS NULL OR expires > %d', PhabricatorTime::getNow());
         }
     }
     $where[] = $this->buildPagingClause($conn_r);
     return $this->formatWhereClause($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->networkPHIDs !== null) {
         $where[] = qsprintf($conn_r, 'networkPHID IN (%Ls)', $this->networkPHIDs);
     }
     if ($this->devicePHIDs !== null) {
         $where[] = qsprintf($conn_r, 'devicePHID IN (%Ls)', $this->devicePHIDs);
     }
     if ($this->addresses !== null) {
         $parts = array();
         foreach ($this->addresses as $address) {
             $parts[] = qsprintf($conn_r, '(networkPHID = %s AND address = %s AND port = %d)', $address->getNetworkPHID(), $address->getAddress(), $address->getPort());
         }
         $where[] = implode(' OR ', $parts);
     }
     $where[] = $this->buildPagingClause($conn_r);
     return $this->formatWhereClause($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 execute(ConduitAPIRequest $request)
 {
     $viewer = $request->getUser();
     $repository_phid = $request->getValue('repositoryPHID');
     $repository = id(new PhabricatorRepositoryQuery())->setViewer($viewer)->withPHIDs(array($repository_phid))->executeOne();
     if (!$repository) {
         throw new Exception(pht('No repository exists with PHID "%s".', $repository_phid));
     }
     $commit_name = $request->getValue('commit');
     $commit = id(new DiffusionCommitQuery())->setViewer($viewer)->withRepository($repository)->withIdentifiers(array($commit_name))->executeOne();
     if (!$commit) {
         throw new Exception(pht('No commit exists with identifier "%s".', $commit_name));
     }
     $branch = PhabricatorRepositoryBranch::loadOrCreateBranch($repository->getID(), $request->getValue('branch'));
     $coverage = $request->getValue('coverage');
     $path_map = id(new DiffusionPathIDQuery(array_keys($coverage)))->loadPathIDs();
     $conn = $repository->establishConnection('w');
     $sql = array();
     foreach ($coverage as $path => $coverage_info) {
         $sql[] = qsprintf($conn, '(%d, %d, %d, %s)', $branch->getID(), $path_map[$path], $commit->getID(), $coverage_info);
     }
     $table_name = 'repository_coverage';
     $conn->openTransaction();
     queryfx($conn, 'DELETE FROM %T WHERE branchID = %d', $table_name, $branch->getID());
     foreach (PhabricatorLiskDAO::chunkSQL($sql) as $chunk) {
         queryfx($conn, 'INSERT INTO %T (branchID, pathID, commitID, coverage) VALUES %Q', $table_name, $chunk);
     }
     $conn->saveTransaction();
 }
 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->tokenTypes !== null) {
         $where[] = qsprintf($conn_r, 'tokenType IN (%Ls)', $this->tokenTypes);
     }
     if ($this->expired !== null) {
         if ($this->expired) {
             $where[] = qsprintf($conn_r, 'tokenExpires <= %d', time());
         } else {
             $where[] = qsprintf($conn_r, 'tokenExpires > %d', time());
         }
     }
     if ($this->tokenCodes !== null) {
         $where[] = qsprintf($conn_r, 'tokenCode IN (%Ls)', $this->tokenCodes);
     }
     $where[] = $this->buildPagingClause($conn_r);
     return $this->formatWhereClause($where);
 }
 public function setKeys(array $keys, $ttl = null)
 {
     if (PhabricatorEnv::isReadOnly()) {
         return;
     }
     if ($keys) {
         $map = $this->digestKeys(array_keys($keys));
         $conn_w = $this->establishConnection('w');
         $sql = array();
         foreach ($map as $key => $hash) {
             $value = $keys[$key];
             list($format, $storage_value) = $this->willWriteValue($key, $value);
             $sql[] = qsprintf($conn_w, '(%s, %s, %s, %B, %d, %nd)', $hash, $key, $format, $storage_value, time(), $ttl ? time() + $ttl : null);
         }
         $guard = AphrontWriteGuard::beginScopedUnguardedWrites();
         foreach (PhabricatorLiskDAO::chunkSQL($sql) as $chunk) {
             queryfx($conn_w, 'INSERT INTO %T
           (cacheKeyHash, cacheKey, cacheFormat, cacheData,
             cacheCreated, cacheExpires) VALUES %Q
           ON DUPLICATE KEY UPDATE
             cacheKey = VALUES(cacheKey),
             cacheFormat = VALUES(cacheFormat),
             cacheData = VALUES(cacheData),
             cacheCreated = VALUES(cacheCreated),
             cacheExpires = VALUES(cacheExpires)', $this->getTableName(), $chunk);
         }
         unset($guard);
     }
     return $this;
 }
 protected function buildWhereClause(AphrontDatabaseConnection $conn_r)
 {
     $where = array();
     if ($this->ids) {
         $where[] = qsprintf($conn_r, 'id IN (%Ld)', $this->ids);
     }
     if ($this->phids) {
         $where[] = qsprintf($conn_r, 'phid IN (%Ls)', $this->phids);
     }
     if ($this->providerClasses) {
         $where[] = qsprintf($conn_r, 'providerClass IN (%Ls)', $this->providerClasses);
     }
     $status = $this->status;
     switch ($status) {
         case self::STATUS_ALL:
             break;
         case self::STATUS_ENABLED:
             $where[] = qsprintf($conn_r, 'isEnabled = 1');
             break;
         default:
             throw new Exception("Unknown status '{$status}'!");
     }
     $where[] = $this->buildPagingClause($conn_r);
     return $this->formatWhereClause($where);
 }
 public static function reindexAbstractDocument(PhabricatorSearchAbstractDocument $doc)
 {
     $phid = $doc->getPHID();
     if (!$phid) {
         throw new Exception("Document has no PHID!");
     }
     $store = new PhabricatorSearchDocument();
     $store->setPHID($doc->getPHID());
     $store->setDocumentType($doc->getDocumentType());
     $store->setDocumentTitle($doc->getDocumentTitle());
     $store->setDocumentCreated($doc->getDocumentCreated());
     $store->setDocumentModified($doc->getDocumentModified());
     $store->replace();
     $conn_w = $store->establishConnection('w');
     $field_dao = new PhabricatorSearchDocumentField();
     queryfx($conn_w, 'DELETE FROM %T WHERE phid = %s', $field_dao->getTableName(), $phid);
     foreach ($doc->getFieldData() as $field) {
         list($ftype, $corpus, $aux_phid) = $field;
         queryfx($conn_w, 'INSERT INTO %T (phid, phidType, field, auxPHID, corpus) ' . ' VALUES (%s, %s, %s, %ns, %s)', $field_dao->getTableName(), $phid, $doc->getDocumentType(), $ftype, $aux_phid, $corpus);
     }
     $sql = array();
     foreach ($doc->getRelationshipData() as $relationship) {
         list($rtype, $to_phid, $to_type, $time) = $relationship;
         $sql[] = qsprintf($conn_w, '(%s, %s, %s, %s, %d)', $phid, $to_phid, $rtype, $to_type, $time);
     }
     $rship_dao = new PhabricatorSearchDocumentRelationship();
     queryfx($conn_w, 'DELETE FROM %T WHERE phid = %s', $rship_dao->getTableName(), $phid);
     if ($sql) {
         queryfx($conn_w, 'INSERT INTO %T' . ' (phid, relatedPHID, relation, relatedType, relatedTime) ' . ' VALUES %Q', $rship_dao->getTableName(), implode(', ', $sql));
     }
 }
 public static function writeCaches(array $values)
 {
     if (PhabricatorEnv::isReadOnly()) {
         return;
     }
     if (!$values) {
         return;
     }
     $table = new self();
     $conn_w = $table->establishConnection('w');
     $sql = array();
     foreach ($values as $value) {
         $key = $value['key'];
         $sql[] = qsprintf($conn_w, '(%s, %s, %s, %s, %s)', $value['userPHID'], PhabricatorHash::digestForIndex($key), $key, $value['value'], $value['type']->getUserCacheType());
     }
     $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
     foreach (PhabricatorLiskDAO::chunkSQL($sql) as $chunk) {
         queryfx($conn_w, 'INSERT INTO %T (userPHID, cacheIndex, cacheKey, cacheData, cacheType)
       VALUES %Q
       ON DUPLICATE KEY UPDATE
         cacheData = VALUES(cacheData),
         cacheType = VALUES(cacheType)', $table->getTableName(), $chunk);
     }
     unset($unguarded);
 }
 private function buildWhereClause($conn_r)
 {
     $where = array();
     if ($this->getUserPHIDs()) {
         $where[] = qsprintf($conn_r, 'userPHID IN (%Ls)', $this->getUserPHIDs());
     }
     return $this->formatWhereClause($where);
 }
 private function buildOrderByClause(AphrontDatabaseConnection $conn_r)
 {
     if (strlen($this->fulltext)) {
         return qsprintf($conn_r, 'ORDER BY MATCH(i.corpus) AGAINST (%s IN BOOLEAN MODE) DESC', $this->fulltext);
     } else {
         return qsprintf($conn_r, 'ORDER BY id DESC');
     }
 }
Beispiel #20
0
 private function buildWhereClause($conn_r)
 {
     $where = array();
     if ($this->phids) {
         $where[] = qsprintf($conn_r, 'phid IN (%Ls)', $this->phids);
     }
     return $this->formatWhereClause($where);
 }
 private function buildJoinClause(AphrontDatabaseConnection $conn)
 {
     $joins = array();
     if ($this->memberPHIDs) {
         $joins[] = qsprintf($conn, 'LEFT JOIN %T m ON a.phid = m.src AND m.type = %d', PhabricatorEdgeConfig::TABLE_NAME_EDGE, PhabricatorEdgeConfig::TYPE_ACCOUNT_HAS_MEMBER);
     }
     return implode(' ', $joins);
 }
 private function buildWhereClause($conn_r)
 {
     $where = array();
     if ($this->ruleIDs) {
         $where[] = qsprintf($conn_r, 'ruleID IN (%Ld)', $this->ruleIDs);
     }
     return $this->formatWhereClause($where);
 }
 protected final function buildOrderClause(AphrontDatabaseConnection $conn_r)
 {
     if ($this->beforeID) {
         return qsprintf($conn_r, 'ORDER BY %C ASC', $this->getPagingColumn());
     } else {
         return qsprintf($conn_r, 'ORDER BY %C DESC', $this->getPagingColumn());
     }
 }
 protected function buildWhereClauseComponents(AphrontDatabaseConnection $conn_r)
 {
     $where = parent::buildWhereClauseComponents($conn_r);
     if ($this->revisionPHIDs !== null) {
         $where[] = qsprintf($conn_r, 'revisionPHID IN (%Ls)', $this->revisionPHIDs);
     }
     return $where;
 }
 protected final function buildOrderClause(AphrontDatabaseConnection $conn_r)
 {
     if ($this->beforeID) {
         return qsprintf($conn_r, 'ORDER BY %Q %Q', $this->getPagingColumn(), $this->getReversePaging() ? 'DESC' : 'ASC');
     } else {
         return qsprintf($conn_r, 'ORDER BY %Q %Q', $this->getPagingColumn(), $this->getReversePaging() ? 'ASC' : 'DESC');
     }
 }
 protected function buildGroupClause(AphrontDatabaseConnection $conn_r)
 {
     if ($this->filterPHIDs) {
         return qsprintf($conn_r, 'GROUP BY ref.chronologicalKey');
     } else {
         return qsprintf($conn_r, 'GROUP BY story.chronologicalKey');
     }
 }
 protected function buildJoinClause(AphrontDatabaseConnection $conn)
 {
     $joins = array();
     if ($this->memberPHIDs) {
         $joins[] = qsprintf($conn, 'LEFT JOIN %T m ON a.phid = m.src AND m.type = %d', PhabricatorEdgeConfig::TABLE_NAME_EDGE, PhortuneAccountHasMemberEdgeType::EDGECONST);
     }
     return implode(' ', $joins);
 }
 private function buildLimitClause(AphrontDatabaseConnection $conn_r)
 {
     $clause = '';
     if ($this->limit) {
         $clause = qsprintf($conn_r, 'LIMIT %d', $this->limit);
     }
     return $clause;
 }
 protected function buildWhereClauseComponents(AphrontDatabaseConnection $conn_r)
 {
     $where = parent::buildWhereClauseComponents($conn_r);
     if ($this->fixedStates !== null) {
         $where[] = qsprintf($conn_r, 'fixedState IN (%Ls)', $this->fixedStates);
     }
     return $where;
 }
 protected function buildWhereClause(AphrontDatabaseConnection $conn_r)
 {
     $where = array();
     if ($this->objectPHIDs) {
         $where[] = qsprintf($conn_r, 'objectPHID IN (%Ls)', $this->objectPHIDs);
     }
     return $this->formatWhereClause($where);
 }