Ejemplo n.º 1
0
 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->bookPHIDs) {
         $where[] = qsprintf($conn_r, 'bookPHID IN (%Ls)', $this->bookPHIDs);
     }
     if ($this->types) {
         $where[] = qsprintf($conn_r, 'type IN (%Ls)', $this->types);
     }
     if ($this->names) {
         $where[] = qsprintf($conn_r, 'name IN (%Ls)', $this->names);
     }
     if ($this->titles) {
         $hashes = array();
         foreach ($this->titles as $title) {
             $slug = DivinerAtomRef::normalizeTitleString($title);
             $hash = PhabricatorHash::digestForIndex($slug);
             $hashes[] = $hash;
         }
         $where[] = qsprintf($conn_r, 'titleSlugHash in (%Ls)', $hashes);
     }
     if ($this->contexts) {
         $with_null = false;
         $contexts = $this->contexts;
         foreach ($contexts as $key => $value) {
             if ($value === null) {
                 unset($contexts[$key]);
                 $with_null = true;
                 continue;
             }
         }
         if ($contexts && $with_null) {
             $where[] = qsprintf($conn_r, 'context IN (%Ls) OR context IS NULL', $contexts);
         } else {
             if ($contexts) {
                 $where[] = qsprintf($conn_r, 'context IN (%Ls)', $contexts);
             } else {
                 if ($with_null) {
                     $where[] = qsprintf($conn_r, 'context IS NULL');
                 }
             }
         }
     }
     if ($this->indexes) {
         $where[] = qsprintf($conn_r, 'atomIndex IN (%Ld)', $this->indexes);
     }
     if ($this->isDocumentable !== null) {
         $where[] = qsprintf($conn_r, 'isDocumentable = %d', (int) $this->isDocumentable);
     }
     if ($this->isGhost !== null) {
         if ($this->isGhost) {
             $where[] = qsprintf($conn_r, 'graphHash IS NULL');
         } else {
             $where[] = qsprintf($conn_r, 'graphHash IS NOT NULL');
         }
     }
     if ($this->nodeHashes) {
         $where[] = qsprintf($conn_r, 'nodeHash IN (%Ls)', $this->nodeHashes);
     }
     if ($this->nameContains) {
         // NOTE: This `CONVERT()` call makes queries case-insensitive, since
         // the column has binary collation. Eventually, this should move into
         // fulltext.
         $where[] = qsprintf($conn_r, 'CONVERT(name USING utf8) LIKE %~', $this->nameContains);
     }
     if ($this->repositoryPHIDs) {
         $where[] = qsprintf($conn_r, 'repositoryPHID IN (%Ls)', $this->repositoryPHIDs);
     }
     $where[] = $this->buildPagingClause($conn_r);
     return $this->formatWhereClause($where);
 }
Ejemplo n.º 2
0
 public function setTitle($value)
 {
     $this->writeField('title', $value);
     if (strlen($value)) {
         $slug = DivinerAtomRef::normalizeTitleString($value);
         $hash = PhabricatorHash::digestForIndex($slug);
         $this->titleSlugHash = $hash;
     } else {
         $this->titleSlugHash = null;
     }
     return $this;
 }