Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15375069
D13070.id31535.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Referenced Files
None
Subscribers
None
D13070.id31535.diff
View Options
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 repositoryPHID varbinary(64) NOT NULL 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
@@ -19,6 +19,7 @@
$book = id(new DivinerBookQuery())
->setViewer($viewer)
->withNames(array($this->bookName))
+ ->needRepositories(true)
->executeOne();
if (!$book) {
@@ -38,6 +39,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,9 @@
private $ids;
private $phids;
private $names;
+ private $repositoryPHIDs;
+
+ private $needRepositories;
public function withIDs(array $ids) {
$this->ids = $ids;
@@ -21,6 +24,16 @@
return $this;
}
+ public function withRepositoryPHIDs(array $repository_phids) {
+ $this->repositoryPHIDs = $repository_phids;
+ return $this;
+ }
+
+ public function needRepositories($need_repositories) {
+ $this->needRepositories = $need_repositories;
+ return $this;
+ }
+
protected function loadPage() {
$table = new DivinerLiveBook();
$conn_r = $table->establishConnection('r');
@@ -33,7 +46,15 @@
$this->buildOrderClause($conn_r),
$this->buildLimitClause($conn_r));
- return $table->loadAllFromArray($data);
+ $books = $table->loadAllFromArray($data);
+
+ if ($books) {
+ if ($this->needRepositories) {
+ $this->loadRepositories($books);
+ }
+ }
+
+ return $books;
}
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
@@ -60,6 +81,13 @@
$this->names);
}
+ if ($this->repositoryPHIDs) {
+ $where[] = qsprintf(
+ $conn_r,
+ 'repositoryPHID IN (%Ls)',
+ $this->repositoryPHIDs);
+ }
+
$where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where);
@@ -69,4 +97,26 @@
return 'PhabricatorDivinerApplication';
}
+ /**
+ * @task internal
+ */
+ private function loadRepositories(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 $book) {
+ $repository = idx($repos, $book->getRepositoryPHID());
+
+ if ($repository) {
+ $book->attachRepository($repository);
+ }
+ }
+
+ }
+
}
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);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Mar 13, 9:31 PM (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7633286
Default Alt Text
D13070.id31535.diff (8 KB)
Attached To
Mode
D13070: Add repositories to Diviner
Attached
Detach File
Event Timeline
Log In to Comment