Changeset View
Standalone View
src/applications/diviner/publisher/DivinerLivePublisher.php
| <?php | <?php | ||||
| final class DivinerLivePublisher extends DivinerPublisher { | final class DivinerLivePublisher extends DivinerPublisher { | ||||
| private $book; | private $book; | ||||
| private function loadBook() { | protected function getBook() { | ||||
| if (!$this->book) { | if (!$this->book) { | ||||
| $book_name = $this->getConfig('name'); | $book_name = $this->getConfig('name'); | ||||
| $book = id(new DivinerLiveBook())->loadOneWhere( | $book = id(new DivinerLiveBook())->loadOneWhere( | ||||
| 'name = %s', | 'name = %s', | ||||
| $book_name); | $book_name); | ||||
| if (!$book) { | if (!$book) { | ||||
| $book = id(new DivinerLiveBook()) | $book = id(new DivinerLiveBook()) | ||||
| ->setName($book_name) | ->setName($book_name) | ||||
| ->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy()) | ->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy()) | ||||
| ->setEditPolicy(PhabricatorPolicies::POLICY_ADMIN) | ->setEditPolicy(PhabricatorPolicies::POLICY_ADMIN) | ||||
joshuaspence: Maybe we should set this to the view policy of the repository? | |||||
| ->save(); | ->save(); | ||||
Done Inline ActionsWe should just enforce it implicitly, like with Differential revisions. The describeAutomaticCapability() method of DivinerLiveBook should be updated to explain this, though (see DifferentialRevision). epriestley: We should just enforce it implicitly, like with Differential revisions.
The… | |||||
Done Inline ActionsAnd then not set a view policy on the DivinerLiveBook at all? joshuaspence: And then not set a view policy on the `DivinerLiveBook` at all? | |||||
| } | } | ||||
Not Done Inline ActionsRight. In a future diff, the new DivinerLiveBook() can become DivinerLiveBook::initializeNewBook() which would read the default application view/edit policies. epriestley: Right. In a future diff, the `new DivinerLiveBook()` can become `DivinerLiveBook… | |||||
| $book->setConfigurationData($this->getConfigurationData())->save(); | $conn_w = $book->establishConnection('w'); | ||||
| $conn_w->openTransaction(); | |||||
| $book | |||||
| ->setRepositoryPHID($this->getRepositoryPHID()) | |||||
| ->setConfigurationData($this->getConfigurationData()) | |||||
Not Done Inline ActionsWe'll have to revisit this at some point if we build arc diviner or similar, but it should be fine for now. epriestley: We'll have to revisit this at some point if we build `arc diviner` or similar, but it should be… | |||||
| ->save(); | |||||
| // TODO: This is gross. Without this, the repository won't be updated for | |||||
| // atoms which have already been published. | |||||
| queryfx( | |||||
| $conn_w, | |||||
| 'UPDATE %T SET repositoryPHID = %s WHERE bookPHID = %s', | |||||
| id(new DivinerLiveSymbol())->getTableName(), | |||||
| $this->getRepositoryPHID(), | |||||
| $book->getPHID()); | |||||
| $conn_w->saveTransaction(); | |||||
| $this->book = $book; | $this->book = $book; | ||||
| id(new PhabricatorSearchIndexer()) | id(new PhabricatorSearchIndexer()) | ||||
| ->queueDocumentForIndexing($book->getPHID()); | ->queueDocumentForIndexing($book->getPHID()); | ||||
| } | } | ||||
Done Inline ActionsThis seems really gross and I might try to clean it up. joshuaspence: This seems really gross and I might try to clean it up. | |||||
| return $this->book; | return $this->book; | ||||
| } | } | ||||
| private function loadSymbolForAtom(DivinerAtom $atom) { | private function loadSymbolForAtom(DivinerAtom $atom) { | ||||
| $symbol = id(new DivinerAtomQuery()) | $symbol = id(new DivinerAtomQuery()) | ||||
| ->setViewer(PhabricatorUser::getOmnipotentUser()) | ->setViewer(PhabricatorUser::getOmnipotentUser()) | ||||
| ->withBookPHIDs(array($this->loadBook()->getPHID())) | ->withBookPHIDs(array($atom->getBook())) | ||||
Done Inline ActionsThis is unrelated, but I think that this was wrong originally? joshuaspence: This is unrelated, but I think that this was wrong originally? | |||||
Done Inline ActionsThis looks wrong now, since it passes a Book object to a with...PHIDs() method? (The original code seems more wrong, but I think there's still a getPHID() missing.) epriestley: This looks wrong now, since it passes a Book object to a `with...PHIDs()` method?
(The… | |||||
Done Inline ActionsOh you're right about the missing getPHID. It's confusing because some classes (such as DivinerAtom) have getBook() and setBook() methods which handle PHIDs rather than book objects. joshuaspence: Oh you're right about the missing `getPHID`. It's confusing because some classes (such as… | |||||
Done Inline ActionsActually yeah... in the DivinerAtom class, $book is a PHID, not an instance of DivinerLiveBook. joshuaspence: Actually yeah... in the `DivinerAtom` class, `$book` is a PHID, not an instance of… | |||||
Not Done Inline ActionsOh, yuck. We should maybe fix this at some point, although that might be involved. epriestley: Oh, yuck. We should maybe fix this at some point, although that might be involved. | |||||
| ->withTypes(array($atom->getType())) | ->withTypes(array($atom->getType())) | ||||
| ->withNames(array($atom->getName())) | ->withNames(array($atom->getName())) | ||||
| ->withContexts(array($atom->getContext())) | ->withContexts(array($atom->getContext())) | ||||
| ->withIndexes(array($this->getAtomSimilarIndex($atom))) | ->withIndexes(array($this->getAtomSimilarIndex($atom))) | ||||
| ->executeOne(); | ->executeOne(); | ||||
| if ($symbol) { | if ($symbol) { | ||||
| return $symbol; | return $symbol; | ||||
| } | } | ||||
| return id(new DivinerLiveSymbol()) | return id(new DivinerLiveSymbol()) | ||||
| ->setBookPHID($this->loadBook()->getPHID()) | ->setBookPHID($this->getBook()->getPHID()) | ||||
| ->setType($atom->getType()) | ->setType($atom->getType()) | ||||
| ->setName($atom->getName()) | ->setName($atom->getName()) | ||||
| ->setContext($atom->getContext()) | ->setContext($atom->getContext()) | ||||
| ->setAtomIndex($this->getAtomSimilarIndex($atom)); | ->setAtomIndex($this->getAtomSimilarIndex($atom)); | ||||
| } | } | ||||
| private function loadAtomStorageForSymbol(DivinerLiveSymbol $symbol) { | private function loadAtomStorageForSymbol(DivinerLiveSymbol $symbol) { | ||||
| $storage = id(new DivinerLiveAtom())->loadOneWhere( | $storage = id(new DivinerLiveAtom())->loadOneWhere( | ||||
| 'symbolPHID = %s', | 'symbolPHID = %s', | ||||
| $symbol->getPHID()); | $symbol->getPHID()); | ||||
| if ($storage) { | if ($storage) { | ||||
| return $storage; | return $storage; | ||||
| } | } | ||||
| return id(new DivinerLiveAtom()) | return id(new DivinerLiveAtom()) | ||||
| ->setSymbolPHID($symbol->getPHID()); | ->setSymbolPHID($symbol->getPHID()); | ||||
| } | } | ||||
| protected function loadAllPublishedHashes() { | protected function loadAllPublishedHashes() { | ||||
| $symbols = id(new DivinerAtomQuery()) | $symbols = id(new DivinerAtomQuery()) | ||||
| ->setViewer(PhabricatorUser::getOmnipotentUser()) | ->setViewer(PhabricatorUser::getOmnipotentUser()) | ||||
| ->withBookPHIDs(array($this->loadBook()->getPHID())) | ->withBookPHIDs(array($this->getBook()->getPHID())) | ||||
| ->withGhosts(false) | ->withGhosts(false) | ||||
| ->execute(); | ->execute(); | ||||
| return mpull($symbols, 'getGraphHash'); | return mpull($symbols, 'getGraphHash'); | ||||
| } | } | ||||
| protected function deleteDocumentsByHash(array $hashes) { | protected function deleteDocumentsByHash(array $hashes) { | ||||
| $atom_table = new DivinerLiveAtom(); | $atom_table = new DivinerLiveAtom(); | ||||
| Show All 28 Lines | foreach ($hashes as $hash) { | ||||
| $atom = $this->getAtomFromGraphHash($hash); | $atom = $this->getAtomFromGraphHash($hash); | ||||
| $ref = $atom->getRef(); | $ref = $atom->getRef(); | ||||
| $symbol = $this->loadSymbolForAtom($atom); | $symbol = $this->loadSymbolForAtom($atom); | ||||
| $is_documentable = $this->shouldGenerateDocumentForAtom($atom); | $is_documentable = $this->shouldGenerateDocumentForAtom($atom); | ||||
| $symbol | $symbol | ||||
| ->setRepositoryPHID($this->getRepositoryPHID()) | |||||
| ->setGraphHash($hash) | ->setGraphHash($hash) | ||||
| ->setIsDocumentable((int)$is_documentable) | ->setIsDocumentable((int)$is_documentable) | ||||
| ->setTitle($ref->getTitle()) | ->setTitle($ref->getTitle()) | ||||
| ->setGroupName($ref->getGroup()) | ->setGroupName($ref->getGroup()) | ||||
| ->setNodeHash($atom->getHash()); | ->setNodeHash($atom->getHash()); | ||||
| if ($atom->getType() !== DivinerAtom::TYPE_FILE) { | if ($atom->getType() !== DivinerAtom::TYPE_FILE) { | ||||
| $renderer = $this->getRenderer(); | $renderer = $this->getRenderer(); | ||||
| Show All 36 Lines | |||||
Maybe we should set this to the view policy of the repository?