diff --git a/resources/sql/autopatches/20150529.divinerrepository.sql b/resources/sql/autopatches/20150529.divinerrepository.sql new file mode 100644 --- /dev/null +++ b/resources/sql/autopatches/20150529.divinerrepository.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_diviner.diviner_livebook + ADD COLUMN repositoryPHID VARBINARY(64) AFTER name; diff --git a/src/applications/diviner/controller/DivinerBookController.php b/src/applications/diviner/controller/DivinerBookController.php --- a/src/applications/diviner/controller/DivinerBookController.php +++ b/src/applications/diviner/controller/DivinerBookController.php @@ -38,6 +38,14 @@ ->setPolicyObject($book) ->setEpoch($book->getDateModified()); + if ($book->getRepositoryPHID()) { + $header->addTag( + id(new PHUITagView()) + ->setType(PHUITagView::TYPE_STATE) + ->setBackgroundColor(PHUITagView::COLOR_BLUE) + ->setName($book->getRepository()->getMonogram())); + } + $document = new PHUIDocumentView(); $document->setHeader($header); $document->addClass('diviner-view'); diff --git a/src/applications/diviner/controller/DivinerController.php b/src/applications/diviner/controller/DivinerController.php --- a/src/applications/diviner/controller/DivinerController.php +++ b/src/applications/diviner/controller/DivinerController.php @@ -28,8 +28,8 @@ $user = $request->getUser(); $list = array(); - foreach ($symbols as $symbol) { + foreach ($symbols as $symbol) { switch ($symbol->getType()) { case DivinerAtom::TYPE_FUNCTION: $title = $symbol->getTitle().'()'; @@ -43,8 +43,7 @@ ->setTitle($title) ->setHref($symbol->getURI()) ->setSubtitle($symbol->getSummary()) - ->setType(DivinerAtom::getAtomTypeNameString( - $symbol->getType())); + ->setType(DivinerAtom::getAtomTypeNameString($symbol->getType())); $list[] = $item; } diff --git a/src/applications/diviner/publisher/DivinerLivePublisher.php b/src/applications/diviner/publisher/DivinerLivePublisher.php --- a/src/applications/diviner/publisher/DivinerLivePublisher.php +++ b/src/applications/diviner/publisher/DivinerLivePublisher.php @@ -12,8 +12,13 @@ if (!$book) { $book = id(new DivinerLiveBook()) ->setName($book_name) + ->setRepository($this->getRepositoryPHID()) ->setViewPolicy(PhabricatorPolicies::POLICY_USER) ->save(); + } else { + $book + ->setRepositoryPHID($this->getRepositoryPHID()) + ->save(); } $book->setConfigurationData($this->getConfigurationData())->save(); @@ -26,7 +31,7 @@ private function loadSymbolForAtom(DivinerAtom $atom) { $symbol = id(new DivinerAtomQuery()) ->setViewer(PhabricatorUser::getOmnipotentUser()) - ->withBookPHIDs(array($this->loadBook()->getPHID())) + ->withBookPHIDs(array($atom->getBook())) ->withTypes(array($atom->getType())) ->withNames(array($atom->getName())) ->withContexts(array($atom->getContext())) diff --git a/src/applications/diviner/publisher/DivinerPublisher.php b/src/applications/diviner/publisher/DivinerPublisher.php --- a/src/applications/diviner/publisher/DivinerPublisher.php +++ b/src/applications/diviner/publisher/DivinerPublisher.php @@ -9,6 +9,7 @@ private $config; private $symbolReverseMap; private $dropCaches; + private $repositoryPHID; public final function setDropCaches($drop_caches) { $this->dropCaches = $drop_caches; @@ -153,4 +154,13 @@ return true; } + final public function getRepositoryPHID() { + return $this->repositoryPHID; + } + + final public function setRepositoryPHID($repository_phid) { + $this->repositoryPHID = $repository_phid; + return $this; + } + } diff --git a/src/applications/diviner/query/DivinerBookQuery.php b/src/applications/diviner/query/DivinerBookQuery.php --- a/src/applications/diviner/query/DivinerBookQuery.php +++ b/src/applications/diviner/query/DivinerBookQuery.php @@ -5,6 +5,7 @@ private $ids; private $phids; private $names; + private $repositoryPHIDs; public function withIDs(array $ids) { $this->ids = $ids; @@ -21,6 +22,11 @@ return $this; } + public function withRepositoryPHIDs(array $repository_phids) { + $this->repositoryPHIDs = $repository_phids; + return $this; + } + protected function loadPage() { $table = new DivinerLiveBook(); $conn_r = $table->establishConnection('r'); @@ -36,6 +42,33 @@ return $table->loadAllFromArray($data); } + protected function willFilterPage(array $books) { + assert_instances_of($books, 'DivinerLiveBook'); + + $repos = id(new PhabricatorRepositoryQuery()) + ->setViewer($this->getViewer()) + ->withPHIDs(mpull($books, 'getRepositoryPHID')) + ->execute(); + $repos = mpull($repos, null, 'getPHID'); + + foreach ($books as $key => $book) { + if ($book->getRepositoryPHID() === null) { + continue; + } + + $repository = idx($repos, $book->getRepositoryPHID()); + + if (!$repository) { + unset($books[$key]); + continue; + } + + $book->attachRepository($repository); + } + + return $books; + } + protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { $where = array(); @@ -60,6 +93,13 @@ $this->names); } + if ($this->repositoryPHIDs !== null) { + $where[] = qsprintf( + $conn_r, + 'repositoryPHID IN (%Ls)', + $this->repositoryPHIDs); + } + $where[] = $this->buildPagingClause($conn_r); return $this->formatWhereClause($where); diff --git a/src/applications/diviner/storage/DivinerLiveBook.php b/src/applications/diviner/storage/DivinerLiveBook.php --- a/src/applications/diviner/storage/DivinerLiveBook.php +++ b/src/applications/diviner/storage/DivinerLiveBook.php @@ -6,9 +6,12 @@ PhabricatorDestructibleInterface { protected $name; + protected $repositoryPHID; protected $viewPolicy; protected $configurationData = array(); + private $repository = self::ATTACHABLE; + protected function getConfiguration() { return array( self::CONFIG_AUX_PHID => true, @@ -64,6 +67,15 @@ return idx($spec, 'name', $group); } + public function getRepository() { + return $this->assertAttached($this->repository); + } + + public function attachRepository(PhabricatorRepository $repository) { + $this->repository = $repository; + return $this; + } + /* -( PhabricatorPolicyInterface )----------------------------------------- */ public function getCapabilities() { diff --git a/src/applications/diviner/workflow/DivinerGenerateWorkflow.php b/src/applications/diviner/workflow/DivinerGenerateWorkflow.php --- a/src/applications/diviner/workflow/DivinerGenerateWorkflow.php +++ b/src/applications/diviner/workflow/DivinerGenerateWorkflow.php @@ -25,6 +25,11 @@ 'help' => pht('Specify a subclass of %s.', 'DivinerPublisher'), 'default' => 'DivinerLivePublisher', ), + array( + 'name' => 'repository', + 'param' => 'callsign', + 'help' => pht('Repository that the documentation belongs to.'), + ), )); } @@ -185,6 +190,20 @@ } $publisher = newv($publisher_class, array()); + $callsign = $args->getArg('repository'); + if ($callsign) { + $repository = id(new PhabricatorRepositoryQuery()) + ->setViewer(PhabricatorUser::getOmnipotentUser()) + ->withCallsigns(array($callsign)) + ->executeOne(); + + if (!$repository) { + throw new Exception(pht('No such repository "%s"!', $callsign)); + } + + $publisher->setRepositoryPHID($repository->getPHID()); + } + $this->publishDocumentation($args->getArg('clean'), $publisher); } diff --git a/src/applications/repository/storage/PhabricatorRepository.php b/src/applications/repository/storage/PhabricatorRepository.php --- a/src/applications/repository/storage/PhabricatorRepository.php +++ b/src/applications/repository/storage/PhabricatorRepository.php @@ -1198,6 +1198,12 @@ $cursor->delete(); } + $books = id(new DivinerLiveBook()) + ->loadAllWhere('repositoryPHID = %s', $this->getPHID()); + foreach ($books as $book) { + $book->delete(); + } + $conn_w = $this->establishConnection('w'); queryfx(