Skip to content

Commit 4bbb1d6

Browse files
epriestleydklawren
epriestley
authored andcommittedJun 22, 2022
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
1 parent d78a0d2 commit 4bbb1d6

12 files changed

+119
-93
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE {$NAMESPACE}_slowvote.slowvote_poll
2+
CHANGE isClosed status VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
UPDATE {$NAMESPACE}_slowvote.slowvote_poll
2+
SET status = 'open' WHERE status = '0';
3+
4+
UPDATE {$NAMESPACE}_slowvote.slowvote_poll
5+
SET status = 'closed' WHERE status = '1';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
UPDATE {$NAMESPACE}_slowvote.slowvote_transaction
2+
SET transactionType = 'vote:status'
3+
WHERE transactionType = 'vote:close';
4+
5+
UPDATE {$NAMESPACE}_slowvote.slowvote_transaction
6+
SET oldValue = '"open"' WHERE
7+
transactionType = 'vote:status' AND oldValue IN ('0', '"0"', 'false');
8+
9+
UPDATE {$NAMESPACE}_slowvote.slowvote_transaction
10+
SET newValue = '"open"' WHERE
11+
transactionType = 'vote:status' AND newValue IN ('0', '"0"', 'false');
12+
13+
UPDATE {$NAMESPACE}_slowvote.slowvote_transaction
14+
SET oldValue = '"closed"' WHERE
15+
transactionType = 'vote:status' AND oldValue IN ('1', '"1"', 'true');
16+
17+
UPDATE {$NAMESPACE}_slowvote.slowvote_transaction
18+
SET newValue = '"closed"' WHERE
19+
transactionType = 'vote:status' AND newValue IN ('1', '"1"', 'true');

‎src/__phutil_library_map__.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4833,7 +4833,6 @@
48334833
'PhabricatorSlowvoteApplication' => 'applications/slowvote/application/PhabricatorSlowvoteApplication.php',
48344834
'PhabricatorSlowvoteChoice' => 'applications/slowvote/storage/PhabricatorSlowvoteChoice.php',
48354835
'PhabricatorSlowvoteCloseController' => 'applications/slowvote/controller/PhabricatorSlowvoteCloseController.php',
4836-
'PhabricatorSlowvoteCloseTransaction' => 'applications/slowvote/xaction/PhabricatorSlowvoteCloseTransaction.php',
48374836
'PhabricatorSlowvoteCommentController' => 'applications/slowvote/controller/PhabricatorSlowvoteCommentController.php',
48384837
'PhabricatorSlowvoteController' => 'applications/slowvote/controller/PhabricatorSlowvoteController.php',
48394838
'PhabricatorSlowvoteDAO' => 'applications/slowvote/storage/PhabricatorSlowvoteDAO.php',
@@ -4854,6 +4853,7 @@
48544853
'PhabricatorSlowvoteSchemaSpec' => 'applications/slowvote/storage/PhabricatorSlowvoteSchemaSpec.php',
48554854
'PhabricatorSlowvoteSearchEngine' => 'applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php',
48564855
'PhabricatorSlowvoteShuffleTransaction' => 'applications/slowvote/xaction/PhabricatorSlowvoteShuffleTransaction.php',
4856+
'PhabricatorSlowvoteStatusTransaction' => 'applications/slowvote/xaction/PhabricatorSlowvoteStatusTransaction.php',
48574857
'PhabricatorSlowvoteTransaction' => 'applications/slowvote/storage/PhabricatorSlowvoteTransaction.php',
48584858
'PhabricatorSlowvoteTransactionComment' => 'applications/slowvote/storage/PhabricatorSlowvoteTransactionComment.php',
48594859
'PhabricatorSlowvoteTransactionQuery' => 'applications/slowvote/query/PhabricatorSlowvoteTransactionQuery.php',
@@ -11539,7 +11539,6 @@
1153911539
'PhabricatorSlowvoteApplication' => 'PhabricatorApplication',
1154011540
'PhabricatorSlowvoteChoice' => 'PhabricatorSlowvoteDAO',
1154111541
'PhabricatorSlowvoteCloseController' => 'PhabricatorSlowvoteController',
11542-
'PhabricatorSlowvoteCloseTransaction' => 'PhabricatorSlowvoteTransactionType',
1154311542
'PhabricatorSlowvoteCommentController' => 'PhabricatorSlowvoteController',
1154411543
'PhabricatorSlowvoteController' => 'PhabricatorController',
1154511544
'PhabricatorSlowvoteDAO' => 'PhabricatorLiskDAO',
@@ -11571,6 +11570,7 @@
1157111570
'PhabricatorSlowvoteSchemaSpec' => 'PhabricatorConfigSchemaSpec',
1157211571
'PhabricatorSlowvoteSearchEngine' => 'PhabricatorApplicationSearchEngine',
1157311572
'PhabricatorSlowvoteShuffleTransaction' => 'PhabricatorSlowvoteTransactionType',
11573+
'PhabricatorSlowvoteStatusTransaction' => 'PhabricatorSlowvoteTransactionType',
1157411574
'PhabricatorSlowvoteTransaction' => 'PhabricatorModularTransaction',
1157511575
'PhabricatorSlowvoteTransactionComment' => 'PhabricatorApplicationTransactionComment',
1157611576
'PhabricatorSlowvoteTransactionQuery' => 'PhabricatorApplicationTransactionQuery',

‎src/applications/slowvote/constants/SlowvotePollStatus.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
final class SlowvotePollStatus
44
extends Phobject {
55

6-
const STATUS_OPEN = 0;
7-
const STATUS_CLOSED = 1;
6+
const STATUS_OPEN = 'open';
7+
const STATUS_CLOSED = 'closed';
88

99
private $key;
1010

@@ -47,6 +47,10 @@ public function getHeaderTagColor() {
4747
return $this->getProperty('header.tag.color');
4848
}
4949

50+
public function getTransactionIcon() {
51+
return $this->getProperty('transaction.icon');
52+
}
53+
5054
private function getProperty($key, $default = null) {
5155
$spec = idx(self::getMap(), $this->getKey(), array());
5256
return idx($spec, $key, $default);
@@ -58,11 +62,13 @@ private static function getMap() {
5862
'name' => pht('Open'),
5963
'header.tag.icon' => 'fa-square-o',
6064
'header.tag.color' => 'bluegrey',
65+
'transaction.icon' => 'fa-pencil',
6166
),
6267
self::STATUS_CLOSED => array(
6368
'name' => pht('Closed'),
6469
'header.tag.icon' => 'fa-ban',
6570
'header.tag.color' => 'indigo',
71+
'transaction.icon' => 'fa-ban',
6672
),
6773
);
6874
}

‎src/applications/slowvote/controller/PhabricatorSlowvoteCloseController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function handleRequest(AphrontRequest $request) {
2020
return new Aphront404Response();
2121
}
2222

23-
$close_uri = '/V'.$poll->getID();
23+
$close_uri = $poll->getURI();
2424

2525
if ($request->isFormPost()) {
2626
if ($poll->isClosed()) {
@@ -33,7 +33,7 @@ public function handleRequest(AphrontRequest $request) {
3333

3434
$xactions[] = id(new PhabricatorSlowvoteTransaction())
3535
->setTransactionType(
36-
PhabricatorSlowvoteCloseTransaction::TRANSACTIONTYPE)
36+
PhabricatorSlowvoteStatusTransaction::TRANSACTIONTYPE)
3737
->setNewValue($new_status);
3838

3939
id(new PhabricatorSlowvoteEditor())

‎src/applications/slowvote/query/PhabricatorSlowvoteQuery.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ final class PhabricatorSlowvoteQuery
77
private $phids;
88
private $authorPHIDs;
99
private $withVotesByViewer;
10-
private $isClosed;
10+
private $statuses;
1111

1212
private $needOptions;
1313
private $needChoices;
@@ -33,8 +33,8 @@ public function withVotesByViewer($with_vote) {
3333
return $this;
3434
}
3535

36-
public function withIsClosed($with_closed) {
37-
$this->isClosed = $with_closed;
36+
public function withStatuses(array $statuses) {
37+
$this->statuses = $statuses;
3838
return $this;
3939
}
4040

@@ -137,12 +137,13 @@ protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
137137
$this->authorPHIDs);
138138
}
139139

140-
if ($this->isClosed !== null) {
140+
if ($this->statuses !== null) {
141141
$where[] = qsprintf(
142142
$conn,
143-
'p.isClosed = %d',
144-
(int)$this->isClosed);
143+
'p.status IN (%Ls)',
144+
$this->statuses);
145145
}
146+
146147
return $where;
147148
}
148149

‎src/applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php

+8-15
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,18 @@ protected function buildQueryFromParameters(array $map) {
2626
$query->withAuthorPHIDs($map['authorPHIDs']);
2727
}
2828

29-
$statuses = $map['statuses'];
30-
if (count($statuses) == 1) {
31-
$status = head($statuses);
32-
if ($status == 'open') {
33-
$query->withIsClosed(false);
34-
} else {
35-
$query->withIsClosed(true);
36-
}
29+
if ($map['statuses']) {
30+
$query->withStatuses($map['statuses']);
3731
}
3832

3933
return $query;
4034
}
4135

4236
protected function buildCustomSearchFields() {
4337

38+
$status_options = SlowvotePollStatus::getAll();
39+
$status_options = mpull($status_options, 'getName');
40+
4441
return array(
4542
id(new PhabricatorUsersSearchField())
4643
->setKey('authorPHIDs')
@@ -61,11 +58,7 @@ protected function buildCustomSearchFields() {
6158
id(new PhabricatorSearchCheckboxesField())
6259
->setKey('statuses')
6360
->setLabel(pht('Statuses'))
64-
->setOptions(
65-
array(
66-
'open' => pht('Open'),
67-
'closed' => pht('Closed'),
68-
)),
61+
->setOptions($status_options),
6962
);
7063
}
7164

@@ -137,9 +130,9 @@ protected function renderResultList(
137130
$item = id(new PHUIObjectItemView())
138131
->setUser($viewer)
139132
->setObject($poll)
140-
->setObjectName('V'.$poll->getID())
133+
->setObjectName($poll->getMonogram())
141134
->setHeader($poll->getQuestion())
142-
->setHref('/V'.$poll->getID())
135+
->setHref($poll->getURI())
143136
->addIcon('none', $date_created);
144137

145138
if ($poll->isClosed()) {

‎src/applications/slowvote/storage/PhabricatorSlowvotePoll.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ final class PhabricatorSlowvotePoll
2020
protected $shuffle = 0;
2121
protected $method;
2222
protected $viewPolicy;
23-
protected $isClosed;
23+
protected $status;
2424
protected $spacePHID;
2525

2626
private $options = self::ATTACHABLE;
@@ -43,7 +43,7 @@ public static function initializeNewPoll(PhabricatorUser $actor) {
4343
->setAuthorPHID($actor->getPHID())
4444
->setViewPolicy($view_policy)
4545
->setSpacePHID($actor->getDefaultSpacePHID())
46-
->setIsClosed(SlowvotePollStatus::STATUS_OPEN)
46+
->setStatus(SlowvotePollStatus::STATUS_OPEN)
4747
->setMethod($default_method)
4848
->setResponseVisibility($default_responses);
4949
}
@@ -57,7 +57,7 @@ protected function getConfiguration() {
5757
'shuffle' => 'bool',
5858
'method' => 'text32',
5959
'description' => 'text',
60-
'isClosed' => 'bool',
60+
'status' => 'text32',
6161
),
6262
self::CONFIG_KEY_SCHEMA => array(
6363
),
@@ -69,11 +69,11 @@ public function getPHIDType() {
6969
}
7070

7171
public function getStatusObject() {
72-
return SlowvotePollStatus::newStatusObject($this->getIsClosed());
72+
return SlowvotePollStatus::newStatusObject($this->getStatus());
7373
}
7474

7575
public function isClosed() {
76-
return ($this->getIsClosed() == SlowvotePollStatus::STATUS_CLOSED);
76+
return ($this->getStatus() == SlowvotePollStatus::STATUS_CLOSED);
7777
}
7878

7979
public function getOptions() {

‎src/applications/slowvote/storage/PhabricatorSlowvoteTransaction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function getMailTags() {
3030
case PhabricatorSlowvoteQuestionTransaction::TRANSACTIONTYPE:
3131
case PhabricatorSlowvoteDescriptionTransaction::TRANSACTIONTYPE:
3232
case PhabricatorSlowvoteShuffleTransaction::TRANSACTIONTYPE:
33-
case PhabricatorSlowvoteCloseTransaction::TRANSACTIONTYPE:
33+
case PhabricatorSlowvoteStatusTransaction::TRANSACTIONTYPE:
3434
$tags[] = self::MAILTAG_DETAILS;
3535
break;
3636
case PhabricatorSlowvoteResponsesTransaction::TRANSACTIONTYPE:

‎src/applications/slowvote/xaction/PhabricatorSlowvoteCloseTransaction.php

-60
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
final class PhabricatorSlowvoteStatusTransaction
4+
extends PhabricatorSlowvoteTransactionType {
5+
6+
const TRANSACTIONTYPE = 'vote:status';
7+
8+
public function generateOldValue($object) {
9+
return (string)$object->getStatus();
10+
}
11+
12+
public function generateNewValue($object, $value) {
13+
return (string)$value;
14+
}
15+
16+
public function applyInternalEffects($object, $value) {
17+
$object->setStatus($value);
18+
}
19+
20+
public function getTitle() {
21+
$old_name = $this->getOldStatusObject()->getName();
22+
$new_name = $this->getNewStatusObject()->getName();
23+
24+
return pht(
25+
'%s changed the status of this poll from %s to %s.',
26+
$this->renderAuthor(),
27+
$this->renderValue($old_name),
28+
$this->renderValue($new_name));
29+
}
30+
31+
public function getTitleForFeed() {
32+
$old_name = $this->getOldStatusObject()->getName();
33+
$new_name = $this->getNewStatusObject()->getName();
34+
35+
36+
return pht(
37+
'%s changed the status of %s from %s to %s.',
38+
$this->renderAuthor(),
39+
$this->renderObject(),
40+
$this->renderValue($old_name),
41+
$this->renderValue($new_name));
42+
}
43+
44+
public function getIcon() {
45+
return $this->getNewStatusObject()->getTransactionIcon();
46+
}
47+
48+
private function getOldStatusObject() {
49+
return $this->newStatusObject($this->getOldValue());
50+
}
51+
52+
private function getNewStatusObject() {
53+
return $this->newStatusObject($this->getNewValue());
54+
}
55+
56+
private function newStatusObject($value) {
57+
return SlowvotePollStatus::newStatusObject($value);
58+
}
59+
60+
}

0 commit comments

Comments
 (0)
Failed to load comments.