Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14088222
D13256.id32372.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
13 KB
Referenced Files
None
Subscribers
None
D13256.id32372.diff
View Options
diff --git a/resources/sql/autopatches/20150620.diviner.status.sql b/resources/sql/autopatches/20150620.diviner.status.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20150620.diviner.status.sql
@@ -0,0 +1,2 @@
+ALTER TABLE {$NAMESPACE}_diviner.diviner_livebook
+ ADD COLUMN isArchived BOOL NOT NULL AFTER repositoryPHID;
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -648,6 +648,7 @@
'DivinerAtomSearchIndexer' => 'applications/diviner/search/DivinerAtomSearchIndexer.php',
'DivinerAtomizeWorkflow' => 'applications/diviner/workflow/DivinerAtomizeWorkflow.php',
'DivinerAtomizer' => 'applications/diviner/atomizer/DivinerAtomizer.php',
+ 'DivinerBookArchiveController' => 'applications/diviner/controller/DivinerBookArchiveController.php',
'DivinerBookController' => 'applications/diviner/controller/DivinerBookController.php',
'DivinerBookDatasource' => 'applications/diviner/typeahead/DivinerBookDatasource.php',
'DivinerBookEditController' => 'applications/diviner/controller/DivinerBookEditController.php',
@@ -4016,6 +4017,7 @@
'DivinerAtomSearchIndexer' => 'PhabricatorSearchDocumentIndexer',
'DivinerAtomizeWorkflow' => 'DivinerWorkflow',
'DivinerAtomizer' => 'Phobject',
+ 'DivinerBookArchiveController' => 'DivinerController',
'DivinerBookController' => 'DivinerController',
'DivinerBookDatasource' => 'PhabricatorTypeaheadDatasource',
'DivinerBookEditController' => 'DivinerController',
diff --git a/src/applications/diviner/application/PhabricatorDivinerApplication.php b/src/applications/diviner/application/PhabricatorDivinerApplication.php
--- a/src/applications/diviner/application/PhabricatorDivinerApplication.php
+++ b/src/applications/diviner/application/PhabricatorDivinerApplication.php
@@ -39,6 +39,7 @@
'find/' => 'DivinerFindController',
),
'/book/(?P<book>[^/]+)/' => 'DivinerBookController',
+ '/book/(?P<book>[^/]+)/archive/' => 'DivinerBookArchiveController',
'/book/(?P<book>[^/]+)/edit/' => 'DivinerBookEditController',
'/book/'.
'(?P<book>[^/]+)/'.
diff --git a/src/applications/diviner/controller/DivinerBookArchiveController.php b/src/applications/diviner/controller/DivinerBookArchiveController.php
new file mode 100644
--- /dev/null
+++ b/src/applications/diviner/controller/DivinerBookArchiveController.php
@@ -0,0 +1,64 @@
+<?php
+
+final class DivinerBookArchiveController extends DivinerController {
+
+ public function handleRequest(AphrontRequest $request) {
+ $viewer = $request->getViewer();
+
+ $book = id(new DivinerBookQuery())
+ ->setViewer($viewer)
+ ->requireCapabilities(
+ array(
+ PhabricatorPolicyCapability::CAN_VIEW,
+ PhabricatorPolicyCapability::CAN_EDIT,
+ ))
+ ->withNames(array($request->getURIData('book')))
+ ->executeOne();
+
+ if (!$book) {
+ return new Aphront404Response();
+ }
+
+ $view_uri = '/book/'.$book->getName().'/';
+
+ if ($request->isFormPost()) {
+ if ($book->getIsArchived()) {
+ $is_archived = false;
+ } else {
+ $is_archived = true;
+ }
+
+ $xactions = array();
+
+ $xactions[] = id(new DivinerLiveBookTransaction())
+ ->setTransactionType(DivinerLiveBookTransaction::TYPE_ARCHIVED)
+ ->setNewValue($is_archived);
+
+ id(new DivinerLiveBookEditor())
+ ->setActor($viewer)
+ ->setContentSourceFromRequest($request)
+ ->setContinueOnNoEffect(true)
+ ->setContinueOnMissingFields(true)
+ ->applyTransactions($book, $xactions);
+
+ return id(new AphrontRedirectResponse())->setURI($view_uri);
+ }
+
+ if ($book->getIsArchived()) {
+ $title = pht('Really activate book?');
+ $body = pht('This book will become active again.');
+ $button = pht('Activate Book');
+ } else {
+ $title = pht('Really archive book?');
+ $body = pht('This book will be moved to the archive.');
+ $button = pht('Archive Book');
+ }
+
+ return $this->newDialog()
+ ->setTitle($title)
+ ->appendChild($body)
+ ->addCancelButton($view_uri)
+ ->addSubmitButton($button);
+ }
+
+}
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
@@ -53,6 +53,12 @@
->setName($book->getRepository()->getMonogram()));
}
+ if ($book->getIsArchived()) {
+ $header->setStatus('fa-ban', 'red', pht('Archived'));
+ } else {
+ $header->setStatus('fa-check', 'bluegrey', pht('Active'));
+ }
+
$document = new PHUIDocumentView();
$document->setHeader($header);
$document->addClass('diviner-view');
@@ -136,6 +142,24 @@
->setHref('/book/'.$book->getName().'/edit/')
->setDisabled(!$can_edit));
+ if ($book->getIsArchived()) {
+ $action_view->addAction(
+ id(new PhabricatorActionView())
+ ->setName(pht('Activate Book'))
+ ->setIcon('fa-check')
+ ->setHref('/book/'.$book->getName().'/archive/')
+ ->setDisabled(!$can_edit)
+ ->setWorkflow(true));
+ } else {
+ $action_view->addAction(
+ id(new PhabricatorActionView())
+ ->setName(pht('Archive Book'))
+ ->setIcon('fa-ban')
+ ->setHref('/book/'.$book->getName().'/archive/')
+ ->setDisabled(!$can_edit)
+ ->setWorkflow(true));
+ }
+
return $action_view;
}
diff --git a/src/applications/diviner/controller/DivinerMainController.php b/src/applications/diviner/controller/DivinerMainController.php
--- a/src/applications/diviner/controller/DivinerMainController.php
+++ b/src/applications/diviner/controller/DivinerMainController.php
@@ -11,6 +11,7 @@
$books = id(new DivinerBookQuery())
->setViewer($viewer)
+ ->withIsArchived(false)
->execute();
$crumbs = $this->buildApplicationCrumbs();
diff --git a/src/applications/diviner/editor/DivinerLiveBookEditor.php b/src/applications/diviner/editor/DivinerLiveBookEditor.php
--- a/src/applications/diviner/editor/DivinerLiveBookEditor.php
+++ b/src/applications/diviner/editor/DivinerLiveBookEditor.php
@@ -17,7 +17,61 @@
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
+ $types[] = DivinerLiveBookTransaction::TYPE_ARCHIVED;
+
return $types;
}
+ protected function getCustomTransactionOldValue(
+ PhabricatorLiskDAO $object,
+ PhabricatorApplicationTransaction $xaction) {
+
+ switch ($xaction->getTransactionType()) {
+ case DivinerLiveBookTransaction::TYPE_ARCHIVED:
+ return $object->getIsArchived();
+ default:
+ return parent::getCustomTransactionOldValue($object, $xaction);
+ }
+ }
+
+ protected function getCustomTransactionNewValue(
+ PhabricatorLiskDAO $object,
+ PhabricatorApplicationTransaction $xaction) {
+
+ switch ($xaction->getTransactionType()) {
+ case DivinerLiveBookTransaction::TYPE_ARCHIVED:
+ return $xaction->getNewValue();
+ default:
+ return parent::getCustomTransactionNewValue($object, $xaction);
+ }
+ }
+
+ protected function applyCustomInternalTransaction(
+ PhabricatorLiskDAO $object,
+ PhabricatorApplicationTransaction $xaction) {
+
+ switch ($xaction->getTransactionType()) {
+ case DivinerLiveBookTransaction::TYPE_ARCHIVED:
+ $object->setIsArchived((int)$xaction->getNewValue());
+ return;
+ default:
+ return parent::applyCustomInternalTransaction($object, $xaction);
+ }
+ }
+
+ protected function applyCustomExternalTransaction(
+ PhabricatorLiskDAO $object,
+ PhabricatorApplicationTransaction $xaction) {
+
+ $old = $xaction->getOldValue();
+ $new = $xaction->getNewValue();
+
+ switch ($xaction->getTransactionType()) {
+ case DivinerLiveBookTransaction::TYPE_ARCHIVED:
+ return;
+ default:
+ return parent::applyCustomExternalTransaction($object, $xaction);
+ }
+ }
+
}
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
@@ -8,6 +8,7 @@
private $nameLike;
private $namePrefix;
private $repositoryPHIDs;
+ private $isArchived;
private $needProjectPHIDs;
private $needRepositories;
@@ -42,6 +43,11 @@
return $this;
}
+ public function withIsArchived($is_archived) {
+ $this->isArchived = $is_archived;
+ return $this;
+ }
+
public function needProjectPHIDs($need_phids) {
$this->needProjectPHIDs = $need_phids;
return $this;
@@ -161,6 +167,13 @@
$this->repositoryPHIDs);
}
+ if ($this->isArchived !== null) {
+ $where[] = qsprintf(
+ $conn_r,
+ 'isArchived = %d',
+ (int)$this->isArchived);
+ }
+
$where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where);
diff --git a/src/applications/diviner/search/DivinerBookSearchIndexer.php b/src/applications/diviner/search/DivinerBookSearchIndexer.php
--- a/src/applications/diviner/search/DivinerBookSearchIndexer.php
+++ b/src/applications/diviner/search/DivinerBookSearchIndexer.php
@@ -19,6 +19,14 @@
$book->getPreface());
$doc->addRelationship(
+ $book->isArchived()
+ ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED
+ : PhabricatorSearchRelationship::RELATIONSHIP_OPEN,
+ $book->getPHID(),
+ DivinerBookPHIDType::TYPECONST,
+ PhabricatorTime::getNow());
+
+ $doc->addRelationship(
PhabricatorSearchRelationship::RELATIONSHIP_REPOSITORY,
$book->getRepositoryPHID(),
PhabricatorRepositoryRepositoryPHIDType::TYPECONST,
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
@@ -9,6 +9,7 @@
protected $name;
protected $repositoryPHID;
+ protected $isArchived = false;
protected $viewPolicy;
protected $editPolicy;
protected $configurationData = array();
@@ -25,6 +26,7 @@
self::CONFIG_COLUMN_SCHEMA => array(
'name' => 'text64',
'repositoryPHID' => 'phid?',
+ 'isArchived' => 'bool',
),
self::CONFIG_KEY_SCHEMA => array(
'key_phid' => null,
diff --git a/src/applications/diviner/storage/DivinerLiveBookTransaction.php b/src/applications/diviner/storage/DivinerLiveBookTransaction.php
--- a/src/applications/diviner/storage/DivinerLiveBookTransaction.php
+++ b/src/applications/diviner/storage/DivinerLiveBookTransaction.php
@@ -3,6 +3,8 @@
final class DivinerLiveBookTransaction
extends PhabricatorApplicationTransaction {
+ const TYPE_ARCHIVED = 'diviner:book:archived';
+
public function getApplicationName() {
return 'diviner';
}
@@ -15,4 +17,86 @@
return null;
}
+ public function getColor() {
+ $old = $this->getOldValue();
+ $new = $this->getNewValue();
+
+ switch ($this->getTransactionType()) {
+ case self::TYPE_ARCHIVED:
+ if ($new) {
+ return 'red';
+ } else {
+ return 'green';
+ }
+ default:
+ return parent::getColor();
+ }
+ }
+
+ public function getIcon() {
+ $old = $this->getOldValue();
+ $new = $this->getNewValue();
+
+ switch ($this->getTransactionType()) {
+ case self::TYPE_ARCHIVED:
+ if ($new) {
+ return 'fa-ban';
+ } else {
+ return 'fa-check';
+ }
+ default:
+ return parent::getIcon();
+ }
+ }
+
+ public function getTitle() {
+ $old = $this->getOldValue();
+ $new = $this->getNewValue();
+ $author_handle = $this->renderHandleLink($this->getAuthorPHID());
+
+ switch ($this->getTransactionType()) {
+ case self::TYPE_ARCHIVED:
+ if ($new) {
+ return pht(
+ '%s archived this book.',
+ $author_handle);
+ } else {
+ return pht(
+ '%s activated this book.',
+ $author_handle);
+ }
+ break;
+
+ default:
+ return parent::getTitle();
+ }
+ }
+
+ public function getTitleForFeed() {
+ $author_phid = $this->getAuthorPHID();
+ $object_phid = $this->getObjectPHID();
+ $author_handle = $this->renderHandleLink($author_phid);
+ $object_handle = $this->renderHandleLink($object_phid);
+
+ $old = $this->getOldValue();
+ $new = $this->getNewValue();
+
+ switch ($this->getTransactionType()) {
+ case self::TYPE_ARCHIVED:
+ if ($new) {
+ return pht(
+ '%s archived %s.',
+ $author_handle,
+ $object_handle);
+ } else {
+ return pht(
+ '%s activated %s.',
+ $author_handle,
+ $object_handle);
+ }
+ default:
+ return parent::getTitleForFeed();
+ }
+ }
+
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 25, 2:06 AM (1 h, 28 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6784659
Default Alt Text
D13256.id32372.diff (13 KB)
Attached To
Mode
D13256: Allow books to be archived
Attached
Detach File
Event Timeline
Log In to Comment