mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 06:42:42 +01:00
Update Slowvote to use sensible string constants for response visibility
Summary: Ref T13682. Migrate and update Slowvote to use API-friendly string constants for response visibility, not opaque integers. Test Plan: Created and edited slowvotes, changing response visibility. Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13682 Differential Revision: https://secure.phabricator.com/D21844
This commit is contained in:
parent
23094b4950
commit
9f075839a2
8 changed files with 57 additions and 8 deletions
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE {$NAMESPACE}_slowvote.slowvote_poll
|
||||
CHANGE responseVisibility
|
||||
responseVisibility VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT};
|
|
@ -0,0 +1,8 @@
|
|||
UPDATE {$NAMESPACE}_slowvote.slowvote_poll
|
||||
SET responseVisibility = 'visible' WHERE responseVisibility = '0';
|
||||
|
||||
UPDATE {$NAMESPACE}_slowvote.slowvote_poll
|
||||
SET responseVisibility = 'voters' WHERE responseVisibility = '1';
|
||||
|
||||
UPDATE {$NAMESPACE}_slowvote.slowvote_poll
|
||||
SET responseVisibility = 'owner' WHERE responseVisibility = '2';
|
|
@ -0,0 +1,23 @@
|
|||
UPDATE {$NAMESPACE}_slowvote.slowvote_transaction
|
||||
SET oldValue = '"visible"' WHERE
|
||||
transactionType = 'vote:responses' AND oldValue IN ('0', '"0"');
|
||||
|
||||
UPDATE {$NAMESPACE}_slowvote.slowvote_transaction
|
||||
SET newValue = '"visible"' WHERE
|
||||
transactionType = 'vote:responses' AND newValue IN ('0', '"0"');
|
||||
|
||||
UPDATE {$NAMESPACE}_slowvote.slowvote_transaction
|
||||
SET oldValue = '"voters"' WHERE
|
||||
transactionType = 'vote:responses' AND oldValue IN ('1', '"1"');
|
||||
|
||||
UPDATE {$NAMESPACE}_slowvote.slowvote_transaction
|
||||
SET newValue = '"voters"' WHERE
|
||||
transactionType = 'vote:responses' AND newValue IN ('1', '"1"');
|
||||
|
||||
UPDATE {$NAMESPACE}_slowvote.slowvote_transaction
|
||||
SET oldValue = '"owner"' WHERE
|
||||
transactionType = 'vote:responses' AND oldValue IN ('2', '"2"');
|
||||
|
||||
UPDATE {$NAMESPACE}_slowvote.slowvote_transaction
|
||||
SET newValue = '"owner"' WHERE
|
||||
transactionType = 'vote:responses' AND newValue IN ('2', '"2"');
|
|
@ -3,9 +3,9 @@
|
|||
final class SlowvotePollResponseVisibility
|
||||
extends Phobject {
|
||||
|
||||
const RESPONSES_VISIBLE = 0;
|
||||
const RESPONSES_VOTERS = 1;
|
||||
const RESPONSES_OWNER = 2;
|
||||
const RESPONSES_VISIBLE = 'visible';
|
||||
const RESPONSES_VOTERS = 'voters';
|
||||
const RESPONSES_OWNER = 'owner';
|
||||
|
||||
private $key;
|
||||
|
||||
|
@ -51,7 +51,7 @@ final class SlowvotePollResponseVisibility
|
|||
}
|
||||
|
||||
private function getProperty($key, $default = null) {
|
||||
$spec = idx(self::getMap(), $this->getKey());
|
||||
$spec = idx(self::getMap(), $this->getKey(), array());
|
||||
return idx($spec, $key, $default);
|
||||
}
|
||||
|
||||
|
|
|
@ -199,6 +199,17 @@ final class PhabricatorSlowvoteEditController
|
|||
$response_type_map = SlowvotePollResponseVisibility::getAll();
|
||||
$response_type_options = mpull($response_type_map, 'getNameForEdit');
|
||||
|
||||
$visibility = $poll->getResponseVisibility();
|
||||
if (!isset($response_type_options[$visibility])) {
|
||||
$visibility_object =
|
||||
SlowvotePollResponseVisibility::newResponseVisibilityObject(
|
||||
$visibility);
|
||||
|
||||
$response_type_options = array(
|
||||
$visibility => $visibility_object->getNameForEdit(),
|
||||
) + $response_type_options;
|
||||
}
|
||||
|
||||
if ($is_new) {
|
||||
$form->appendChild(
|
||||
id(new AphrontFormSelectControl())
|
||||
|
|
|
@ -53,7 +53,7 @@ final class PhabricatorSlowvotePoll
|
|||
self::CONFIG_AUX_PHID => true,
|
||||
self::CONFIG_COLUMN_SCHEMA => array(
|
||||
'question' => 'text255',
|
||||
'responseVisibility' => 'uint32',
|
||||
'responseVisibility' => 'text32',
|
||||
'shuffle' => 'bool',
|
||||
'method' => 'uint32',
|
||||
'description' => 'text',
|
||||
|
|
|
@ -75,12 +75,12 @@ final class SlowvoteEmbedView extends AphrontView {
|
|||
$description,
|
||||
);
|
||||
|
||||
$quip = pht('Voting improves cardiovascular endurance.');
|
||||
|
||||
$vis = $poll->getResponseVisibility();
|
||||
if ($this->areResultsVisible()) {
|
||||
if ($vis == SlowvotePollResponseVisibility::RESPONSES_OWNER) {
|
||||
$quip = pht('Only you can see the results.');
|
||||
} else {
|
||||
$quip = pht('Voting improves cardiovascular endurance.');
|
||||
}
|
||||
} else if ($vis == SlowvotePollResponseVisibility::RESPONSES_VOTERS) {
|
||||
$quip = pht('You must vote to see the results.');
|
||||
|
|
|
@ -6,7 +6,11 @@ final class PhabricatorSlowvoteResponsesTransaction
|
|||
const TRANSACTIONTYPE = 'vote:responses';
|
||||
|
||||
public function generateOldValue($object) {
|
||||
return $object->getResponseVisibility();
|
||||
return (string)$object->getResponseVisibility();
|
||||
}
|
||||
|
||||
public function generateNewValue($object, $value) {
|
||||
return (string)$value;
|
||||
}
|
||||
|
||||
public function applyInternalEffects($object, $value) {
|
||||
|
|
Loading…
Reference in a new issue