diff --git a/resources/sql/autopatches/20220525.slowvote.03.response-type.sql b/resources/sql/autopatches/20220525.slowvote.03.response-type.sql new file mode 100644 --- /dev/null +++ b/resources/sql/autopatches/20220525.slowvote.03.response-type.sql @@ -0,0 +1,3 @@ +ALTER TABLE {$NAMESPACE}_slowvote.slowvote_poll + CHANGE responseVisibility + responseVisibility VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT}; diff --git a/resources/sql/autopatches/20220525.slowvote.04.response-value.sql b/resources/sql/autopatches/20220525.slowvote.04.response-value.sql new file mode 100644 --- /dev/null +++ b/resources/sql/autopatches/20220525.slowvote.04.response-value.sql @@ -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'; diff --git a/resources/sql/autopatches/20220525.slowvote.05.response-xactions.sql b/resources/sql/autopatches/20220525.slowvote.05.response-xactions.sql new file mode 100644 --- /dev/null +++ b/resources/sql/autopatches/20220525.slowvote.05.response-xactions.sql @@ -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"'); diff --git a/src/applications/slowvote/constants/SlowvotePollResponseVisibility.php b/src/applications/slowvote/constants/SlowvotePollResponseVisibility.php --- a/src/applications/slowvote/constants/SlowvotePollResponseVisibility.php +++ b/src/applications/slowvote/constants/SlowvotePollResponseVisibility.php @@ -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 @@ } private function getProperty($key, $default = null) { - $spec = idx(self::getMap(), $this->getKey()); + $spec = idx(self::getMap(), $this->getKey(), array()); return idx($spec, $key, $default); } diff --git a/src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php b/src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php --- a/src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php +++ b/src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php @@ -199,6 +199,17 @@ $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()) diff --git a/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php b/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php --- a/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php +++ b/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php @@ -53,7 +53,7 @@ self::CONFIG_AUX_PHID => true, self::CONFIG_COLUMN_SCHEMA => array( 'question' => 'text255', - 'responseVisibility' => 'uint32', + 'responseVisibility' => 'text32', 'shuffle' => 'bool', 'method' => 'uint32', 'description' => 'text', diff --git a/src/applications/slowvote/view/SlowvoteEmbedView.php b/src/applications/slowvote/view/SlowvoteEmbedView.php --- a/src/applications/slowvote/view/SlowvoteEmbedView.php +++ b/src/applications/slowvote/view/SlowvoteEmbedView.php @@ -75,12 +75,12 @@ $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.'); diff --git a/src/applications/slowvote/xaction/PhabricatorSlowvoteResponsesTransaction.php b/src/applications/slowvote/xaction/PhabricatorSlowvoteResponsesTransaction.php --- a/src/applications/slowvote/xaction/PhabricatorSlowvoteResponsesTransaction.php +++ b/src/applications/slowvote/xaction/PhabricatorSlowvoteResponsesTransaction.php @@ -6,7 +6,11 @@ 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) {