[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/diviner/publisher/ -> DivinerLivePublisher.php (source)

   1  <?php
   2  
   3  final class DivinerLivePublisher extends DivinerPublisher {
   4  
   5    private $book;
   6  
   7    private function loadBook() {
   8      if (!$this->book) {
   9        $book_name = $this->getConfig('name');
  10  
  11        $book = id(new DivinerLiveBook())->loadOneWhere(
  12          'name = %s',
  13          $book_name);
  14        if (!$book) {
  15          $book = id(new DivinerLiveBook())
  16            ->setName($book_name)
  17            ->setViewPolicy(PhabricatorPolicies::POLICY_USER)
  18            ->save();
  19        }
  20  
  21        $book->setConfigurationData($this->getConfigurationData())->save();
  22  
  23        $this->book = $book;
  24      }
  25      return $this->book;
  26    }
  27  
  28    private function loadSymbolForAtom(DivinerAtom $atom) {
  29      $symbol = id(new DivinerAtomQuery())
  30        ->setViewer(PhabricatorUser::getOmnipotentUser())
  31        ->withBookPHIDs(array($this->loadBook()->getPHID()))
  32        ->withTypes(array($atom->getType()))
  33        ->withNames(array($atom->getName()))
  34        ->withContexts(array($atom->getContext()))
  35        ->withIndexes(array($this->getAtomSimilarIndex($atom)))
  36        ->withIncludeUndocumentable(true)
  37        ->withIncludeGhosts(true)
  38        ->executeOne();
  39  
  40      if ($symbol) {
  41        return $symbol;
  42      }
  43  
  44      return id(new DivinerLiveSymbol())
  45        ->setBookPHID($this->loadBook()->getPHID())
  46        ->setType($atom->getType())
  47        ->setName($atom->getName())
  48        ->setContext($atom->getContext())
  49        ->setAtomIndex($this->getAtomSimilarIndex($atom));
  50    }
  51  
  52    private function loadAtomStorageForSymbol(DivinerLiveSymbol $symbol) {
  53      $storage = id(new DivinerLiveAtom())->loadOneWhere(
  54        'symbolPHID = %s',
  55        $symbol->getPHID());
  56  
  57      if ($storage) {
  58        return $storage;
  59      }
  60  
  61      return id(new DivinerLiveAtom())
  62        ->setSymbolPHID($symbol->getPHID());
  63    }
  64  
  65    protected function loadAllPublishedHashes() {
  66      $symbols = id(new DivinerAtomQuery())
  67        ->setViewer(PhabricatorUser::getOmnipotentUser())
  68        ->withBookPHIDs(array($this->loadBook()->getPHID()))
  69        ->withIncludeUndocumentable(true)
  70        ->execute();
  71  
  72      return mpull($symbols, 'getGraphHash');
  73    }
  74  
  75    protected function deleteDocumentsByHash(array $hashes) {
  76      $atom_table = new DivinerLiveAtom();
  77      $symbol_table = new DivinerLiveSymbol();
  78  
  79      $conn_w = $symbol_table->establishConnection('w');
  80  
  81      $strings = array();
  82      foreach ($hashes as $hash) {
  83        $strings[] = qsprintf($conn_w, '%s', $hash);
  84      }
  85  
  86      foreach (PhabricatorLiskDAO::chunkSQL($strings, ', ') as $chunk) {
  87        queryfx(
  88          $conn_w,
  89          'UPDATE %T SET graphHash = NULL, nodeHash = NULL
  90            WHERE graphHash IN (%Q)',
  91          $symbol_table->getTableName(),
  92          $chunk);
  93      }
  94  
  95      queryfx(
  96        $conn_w,
  97        'DELETE a FROM %T a LEFT JOIN %T s
  98          ON a.symbolPHID = s.phid
  99          WHERE s.graphHash IS NULL',
 100        $atom_table->getTableName(),
 101        $symbol_table->getTableName());
 102    }
 103  
 104    protected function createDocumentsByHash(array $hashes) {
 105      foreach ($hashes as $hash) {
 106        $atom = $this->getAtomFromGraphHash($hash);
 107        $ref = $atom->getRef();
 108  
 109        $symbol = $this->loadSymbolForAtom($atom);
 110  
 111        $is_documentable = $this->shouldGenerateDocumentForAtom($atom);
 112  
 113        $symbol
 114          ->setGraphHash($hash)
 115          ->setIsDocumentable((int)$is_documentable)
 116          ->setTitle($ref->getTitle())
 117          ->setGroupName($ref->getGroup())
 118          ->setNodeHash($atom->getHash());
 119  
 120        if ($atom->getType() !== DivinerAtom::TYPE_FILE) {
 121          $renderer = $this->getRenderer();
 122          $summary = $renderer->getAtomSummary($atom);
 123          $symbol->setSummary($summary);
 124        } else {
 125          $symbol->setSummary('');
 126        }
 127  
 128        $symbol->save();
 129  
 130        // TODO: We probably need a finer-grained sense of what "documentable"
 131        // atoms are. Neither files nor methods are currently considered
 132        // documentable, but for different reasons: files appear nowhere, while
 133        // methods just don't appear at the top level. These are probably
 134        // separate concepts. Since we need atoms in order to build method
 135        // documentation, we insert them here. This also means we insert files,
 136        // which are unnecessary and unused. Make sure this makes sense, but then
 137        // probably introduce separate "isTopLevel" and "isDocumentable" flags?
 138        // TODO: Yeah do that soon ^^^
 139  
 140        if ($atom->getType() !== DivinerAtom::TYPE_FILE) {
 141          $storage = $this->loadAtomStorageForSymbol($symbol)
 142            ->setAtomData($atom->toDictionary())
 143            ->setContent(null)
 144            ->save();
 145        }
 146  
 147      }
 148    }
 149  
 150    public function findAtomByRef(DivinerAtomRef $ref) {
 151      // TODO: Actually implement this.
 152  
 153      return null;
 154    }
 155  
 156  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1