mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 13:30:55 +01:00
Update Slowvote poll status to use sensible string constants
Summary: Ref T13682. This prepares for modernizing Slowvote and exposing a more usable API. Test Plan: Ran migrations, opened and closed polls. Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13682 Differential Revision: https://secure.phabricator.com/D21848
This commit is contained in:
parent
c1887f0c1d
commit
809ae81752
12 changed files with 119 additions and 93 deletions
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE {$NAMESPACE}_slowvote.slowvote_poll
|
||||
CHANGE isClosed status VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT};
|
|
@ -0,0 +1,5 @@
|
|||
UPDATE {$NAMESPACE}_slowvote.slowvote_poll
|
||||
SET status = 'open' WHERE status = '0';
|
||||
|
||||
UPDATE {$NAMESPACE}_slowvote.slowvote_poll
|
||||
SET status = 'closed' WHERE status = '1';
|
|
@ -0,0 +1,19 @@
|
|||
UPDATE {$NAMESPACE}_slowvote.slowvote_transaction
|
||||
SET transactionType = 'vote:status'
|
||||
WHERE transactionType = 'vote:close';
|
||||
|
||||
UPDATE {$NAMESPACE}_slowvote.slowvote_transaction
|
||||
SET oldValue = '"open"' WHERE
|
||||
transactionType = 'vote:status' AND oldValue IN ('0', '"0"', 'false');
|
||||
|
||||
UPDATE {$NAMESPACE}_slowvote.slowvote_transaction
|
||||
SET newValue = '"open"' WHERE
|
||||
transactionType = 'vote:status' AND newValue IN ('0', '"0"', 'false');
|
||||
|
||||
UPDATE {$NAMESPACE}_slowvote.slowvote_transaction
|
||||
SET oldValue = '"closed"' WHERE
|
||||
transactionType = 'vote:status' AND oldValue IN ('1', '"1"', 'true');
|
||||
|
||||
UPDATE {$NAMESPACE}_slowvote.slowvote_transaction
|
||||
SET newValue = '"closed"' WHERE
|
||||
transactionType = 'vote:status' AND newValue IN ('1', '"1"', 'true');
|
|
@ -4833,7 +4833,6 @@ phutil_register_library_map(array(
|
|||
'PhabricatorSlowvoteApplication' => 'applications/slowvote/application/PhabricatorSlowvoteApplication.php',
|
||||
'PhabricatorSlowvoteChoice' => 'applications/slowvote/storage/PhabricatorSlowvoteChoice.php',
|
||||
'PhabricatorSlowvoteCloseController' => 'applications/slowvote/controller/PhabricatorSlowvoteCloseController.php',
|
||||
'PhabricatorSlowvoteCloseTransaction' => 'applications/slowvote/xaction/PhabricatorSlowvoteCloseTransaction.php',
|
||||
'PhabricatorSlowvoteCommentController' => 'applications/slowvote/controller/PhabricatorSlowvoteCommentController.php',
|
||||
'PhabricatorSlowvoteController' => 'applications/slowvote/controller/PhabricatorSlowvoteController.php',
|
||||
'PhabricatorSlowvoteDAO' => 'applications/slowvote/storage/PhabricatorSlowvoteDAO.php',
|
||||
|
@ -4854,6 +4853,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorSlowvoteSchemaSpec' => 'applications/slowvote/storage/PhabricatorSlowvoteSchemaSpec.php',
|
||||
'PhabricatorSlowvoteSearchEngine' => 'applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php',
|
||||
'PhabricatorSlowvoteShuffleTransaction' => 'applications/slowvote/xaction/PhabricatorSlowvoteShuffleTransaction.php',
|
||||
'PhabricatorSlowvoteStatusTransaction' => 'applications/slowvote/xaction/PhabricatorSlowvoteStatusTransaction.php',
|
||||
'PhabricatorSlowvoteTransaction' => 'applications/slowvote/storage/PhabricatorSlowvoteTransaction.php',
|
||||
'PhabricatorSlowvoteTransactionComment' => 'applications/slowvote/storage/PhabricatorSlowvoteTransactionComment.php',
|
||||
'PhabricatorSlowvoteTransactionQuery' => 'applications/slowvote/query/PhabricatorSlowvoteTransactionQuery.php',
|
||||
|
@ -11539,7 +11539,6 @@ phutil_register_library_map(array(
|
|||
'PhabricatorSlowvoteApplication' => 'PhabricatorApplication',
|
||||
'PhabricatorSlowvoteChoice' => 'PhabricatorSlowvoteDAO',
|
||||
'PhabricatorSlowvoteCloseController' => 'PhabricatorSlowvoteController',
|
||||
'PhabricatorSlowvoteCloseTransaction' => 'PhabricatorSlowvoteTransactionType',
|
||||
'PhabricatorSlowvoteCommentController' => 'PhabricatorSlowvoteController',
|
||||
'PhabricatorSlowvoteController' => 'PhabricatorController',
|
||||
'PhabricatorSlowvoteDAO' => 'PhabricatorLiskDAO',
|
||||
|
@ -11571,6 +11570,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorSlowvoteSchemaSpec' => 'PhabricatorConfigSchemaSpec',
|
||||
'PhabricatorSlowvoteSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'PhabricatorSlowvoteShuffleTransaction' => 'PhabricatorSlowvoteTransactionType',
|
||||
'PhabricatorSlowvoteStatusTransaction' => 'PhabricatorSlowvoteTransactionType',
|
||||
'PhabricatorSlowvoteTransaction' => 'PhabricatorModularTransaction',
|
||||
'PhabricatorSlowvoteTransactionComment' => 'PhabricatorApplicationTransactionComment',
|
||||
'PhabricatorSlowvoteTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
final class SlowvotePollStatus
|
||||
extends Phobject {
|
||||
|
||||
const STATUS_OPEN = 0;
|
||||
const STATUS_CLOSED = 1;
|
||||
const STATUS_OPEN = 'open';
|
||||
const STATUS_CLOSED = 'closed';
|
||||
|
||||
private $key;
|
||||
|
||||
|
@ -47,6 +47,10 @@ final class SlowvotePollStatus
|
|||
return $this->getProperty('header.tag.color');
|
||||
}
|
||||
|
||||
public function getTransactionIcon() {
|
||||
return $this->getProperty('transaction.icon');
|
||||
}
|
||||
|
||||
private function getProperty($key, $default = null) {
|
||||
$spec = idx(self::getMap(), $this->getKey(), array());
|
||||
return idx($spec, $key, $default);
|
||||
|
@ -58,11 +62,13 @@ final class SlowvotePollStatus
|
|||
'name' => pht('Open'),
|
||||
'header.tag.icon' => 'fa-square-o',
|
||||
'header.tag.color' => 'bluegrey',
|
||||
'transaction.icon' => 'fa-pencil',
|
||||
),
|
||||
self::STATUS_CLOSED => array(
|
||||
'name' => pht('Closed'),
|
||||
'header.tag.icon' => 'fa-ban',
|
||||
'header.tag.color' => 'indigo',
|
||||
'transaction.icon' => 'fa-ban',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ final class PhabricatorSlowvoteCloseController
|
|||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$close_uri = '/V'.$poll->getID();
|
||||
$close_uri = $poll->getURI();
|
||||
|
||||
if ($request->isFormPost()) {
|
||||
if ($poll->isClosed()) {
|
||||
|
@ -33,7 +33,7 @@ final class PhabricatorSlowvoteCloseController
|
|||
|
||||
$xactions[] = id(new PhabricatorSlowvoteTransaction())
|
||||
->setTransactionType(
|
||||
PhabricatorSlowvoteCloseTransaction::TRANSACTIONTYPE)
|
||||
PhabricatorSlowvoteStatusTransaction::TRANSACTIONTYPE)
|
||||
->setNewValue($new_status);
|
||||
|
||||
id(new PhabricatorSlowvoteEditor())
|
||||
|
|
|
@ -7,7 +7,7 @@ final class PhabricatorSlowvoteQuery
|
|||
private $phids;
|
||||
private $authorPHIDs;
|
||||
private $withVotesByViewer;
|
||||
private $isClosed;
|
||||
private $statuses;
|
||||
|
||||
private $needOptions;
|
||||
private $needChoices;
|
||||
|
@ -33,8 +33,8 @@ final class PhabricatorSlowvoteQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function withIsClosed($with_closed) {
|
||||
$this->isClosed = $with_closed;
|
||||
public function withStatuses(array $statuses) {
|
||||
$this->statuses = $statuses;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -137,12 +137,13 @@ final class PhabricatorSlowvoteQuery
|
|||
$this->authorPHIDs);
|
||||
}
|
||||
|
||||
if ($this->isClosed !== null) {
|
||||
if ($this->statuses !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'p.isClosed = %d',
|
||||
(int)$this->isClosed);
|
||||
'p.status IN (%Ls)',
|
||||
$this->statuses);
|
||||
}
|
||||
|
||||
return $where;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,14 +26,8 @@ final class PhabricatorSlowvoteSearchEngine
|
|||
$query->withAuthorPHIDs($map['authorPHIDs']);
|
||||
}
|
||||
|
||||
$statuses = $map['statuses'];
|
||||
if (count($statuses) == 1) {
|
||||
$status = head($statuses);
|
||||
if ($status == 'open') {
|
||||
$query->withIsClosed(false);
|
||||
} else {
|
||||
$query->withIsClosed(true);
|
||||
}
|
||||
if ($map['statuses']) {
|
||||
$query->withStatuses($map['statuses']);
|
||||
}
|
||||
|
||||
return $query;
|
||||
|
@ -41,6 +35,9 @@ final class PhabricatorSlowvoteSearchEngine
|
|||
|
||||
protected function buildCustomSearchFields() {
|
||||
|
||||
$status_options = SlowvotePollStatus::getAll();
|
||||
$status_options = mpull($status_options, 'getName');
|
||||
|
||||
return array(
|
||||
id(new PhabricatorUsersSearchField())
|
||||
->setKey('authorPHIDs')
|
||||
|
@ -61,11 +58,7 @@ final class PhabricatorSlowvoteSearchEngine
|
|||
id(new PhabricatorSearchCheckboxesField())
|
||||
->setKey('statuses')
|
||||
->setLabel(pht('Statuses'))
|
||||
->setOptions(
|
||||
array(
|
||||
'open' => pht('Open'),
|
||||
'closed' => pht('Closed'),
|
||||
)),
|
||||
->setOptions($status_options),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -137,9 +130,9 @@ final class PhabricatorSlowvoteSearchEngine
|
|||
$item = id(new PHUIObjectItemView())
|
||||
->setUser($viewer)
|
||||
->setObject($poll)
|
||||
->setObjectName('V'.$poll->getID())
|
||||
->setObjectName($poll->getMonogram())
|
||||
->setHeader($poll->getQuestion())
|
||||
->setHref('/V'.$poll->getID())
|
||||
->setHref($poll->getURI())
|
||||
->addIcon('none', $date_created);
|
||||
|
||||
if ($poll->isClosed()) {
|
||||
|
|
|
@ -20,7 +20,7 @@ final class PhabricatorSlowvotePoll
|
|||
protected $shuffle = 0;
|
||||
protected $method;
|
||||
protected $viewPolicy;
|
||||
protected $isClosed;
|
||||
protected $status;
|
||||
protected $spacePHID;
|
||||
|
||||
private $options = self::ATTACHABLE;
|
||||
|
@ -43,7 +43,7 @@ final class PhabricatorSlowvotePoll
|
|||
->setAuthorPHID($actor->getPHID())
|
||||
->setViewPolicy($view_policy)
|
||||
->setSpacePHID($actor->getDefaultSpacePHID())
|
||||
->setIsClosed(SlowvotePollStatus::STATUS_OPEN)
|
||||
->setStatus(SlowvotePollStatus::STATUS_OPEN)
|
||||
->setMethod($default_method)
|
||||
->setResponseVisibility($default_responses);
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ final class PhabricatorSlowvotePoll
|
|||
'shuffle' => 'bool',
|
||||
'method' => 'text32',
|
||||
'description' => 'text',
|
||||
'isClosed' => 'bool',
|
||||
'status' => 'text32',
|
||||
),
|
||||
self::CONFIG_KEY_SCHEMA => array(
|
||||
),
|
||||
|
@ -69,11 +69,11 @@ final class PhabricatorSlowvotePoll
|
|||
}
|
||||
|
||||
public function getStatusObject() {
|
||||
return SlowvotePollStatus::newStatusObject($this->getIsClosed());
|
||||
return SlowvotePollStatus::newStatusObject($this->getStatus());
|
||||
}
|
||||
|
||||
public function isClosed() {
|
||||
return ($this->getIsClosed() == SlowvotePollStatus::STATUS_CLOSED);
|
||||
return ($this->getStatus() == SlowvotePollStatus::STATUS_CLOSED);
|
||||
}
|
||||
|
||||
public function getOptions() {
|
||||
|
|
|
@ -30,7 +30,7 @@ final class PhabricatorSlowvoteTransaction
|
|||
case PhabricatorSlowvoteQuestionTransaction::TRANSACTIONTYPE:
|
||||
case PhabricatorSlowvoteDescriptionTransaction::TRANSACTIONTYPE:
|
||||
case PhabricatorSlowvoteShuffleTransaction::TRANSACTIONTYPE:
|
||||
case PhabricatorSlowvoteCloseTransaction::TRANSACTIONTYPE:
|
||||
case PhabricatorSlowvoteStatusTransaction::TRANSACTIONTYPE:
|
||||
$tags[] = self::MAILTAG_DETAILS;
|
||||
break;
|
||||
case PhabricatorSlowvoteResponsesTransaction::TRANSACTIONTYPE:
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorSlowvoteCloseTransaction
|
||||
extends PhabricatorSlowvoteTransactionType {
|
||||
|
||||
const TRANSACTIONTYPE = 'vote:close';
|
||||
|
||||
public function generateOldValue($object) {
|
||||
return (bool)$object->getIsClosed();
|
||||
}
|
||||
|
||||
public function generateNewValue($object, $value) {
|
||||
return (bool)$value;
|
||||
}
|
||||
|
||||
public function applyInternalEffects($object, $value) {
|
||||
$object->setIsClosed((int)$value);
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
$new = $this->getNewValue();
|
||||
|
||||
if ($new) {
|
||||
return pht(
|
||||
'%s closed this poll.',
|
||||
$this->renderAuthor());
|
||||
} else {
|
||||
return pht(
|
||||
'%s reopened this poll.',
|
||||
$this->renderAuthor());
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitleForFeed() {
|
||||
$new = $this->getNewValue();
|
||||
|
||||
if ($new) {
|
||||
return pht(
|
||||
'%s closed %s.',
|
||||
$this->renderAuthor(),
|
||||
$this->renderObject());
|
||||
} else {
|
||||
return pht(
|
||||
'%s reopened %s.',
|
||||
$this->renderAuthor(),
|
||||
$this->renderObject());
|
||||
}
|
||||
}
|
||||
|
||||
public function getIcon() {
|
||||
$new = $this->getNewValue();
|
||||
|
||||
if ($new) {
|
||||
return 'fa-ban';
|
||||
} else {
|
||||
return 'fa-pencil';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorSlowvoteStatusTransaction
|
||||
extends PhabricatorSlowvoteTransactionType {
|
||||
|
||||
const TRANSACTIONTYPE = 'vote:status';
|
||||
|
||||
public function generateOldValue($object) {
|
||||
return (string)$object->getStatus();
|
||||
}
|
||||
|
||||
public function generateNewValue($object, $value) {
|
||||
return (string)$value;
|
||||
}
|
||||
|
||||
public function applyInternalEffects($object, $value) {
|
||||
$object->setStatus($value);
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
$old_name = $this->getOldStatusObject()->getName();
|
||||
$new_name = $this->getNewStatusObject()->getName();
|
||||
|
||||
return pht(
|
||||
'%s changed the status of this poll from %s to %s.',
|
||||
$this->renderAuthor(),
|
||||
$this->renderValue($old_name),
|
||||
$this->renderValue($new_name));
|
||||
}
|
||||
|
||||
public function getTitleForFeed() {
|
||||
$old_name = $this->getOldStatusObject()->getName();
|
||||
$new_name = $this->getNewStatusObject()->getName();
|
||||
|
||||
|
||||
return pht(
|
||||
'%s changed the status of %s from %s to %s.',
|
||||
$this->renderAuthor(),
|
||||
$this->renderObject(),
|
||||
$this->renderValue($old_name),
|
||||
$this->renderValue($new_name));
|
||||
}
|
||||
|
||||
public function getIcon() {
|
||||
return $this->getNewStatusObject()->getTransactionIcon();
|
||||
}
|
||||
|
||||
private function getOldStatusObject() {
|
||||
return $this->newStatusObject($this->getOldValue());
|
||||
}
|
||||
|
||||
private function getNewStatusObject() {
|
||||
return $this->newStatusObject($this->getNewValue());
|
||||
}
|
||||
|
||||
private function newStatusObject($value) {
|
||||
return SlowvotePollStatus::newStatusObject($value);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue