Path: blob/master/src/applications/differential/xaction/DifferentialRevisionVoidTransaction.php
12256 views
<?php12/**3* This is an internal transaction type used to void reviews.4*5* For example, "Request Review" voids any open accepts, so they no longer6* act as current accepts.7*/8final class DifferentialRevisionVoidTransaction9extends DifferentialRevisionTransactionType {1011const TRANSACTIONTYPE = 'differential.revision.void';1213public function generateOldValue($object) {14return false;15}1617public function generateNewValue($object, $value) {18$reviewers = id(new DifferentialReviewer())->loadAllWhere(19'revisionPHID = %s20AND voidedPHID IS NULL21AND reviewerStatus IN (%Ls)',22$object->getPHID(),23$value);2425$must_downgrade = $this->getMetadataValue('void.force', array());26$must_downgrade = array_fuse($must_downgrade);2728$default = PhabricatorEnv::getEnvConfig('differential.sticky-accept');29foreach ($reviewers as $key => $reviewer) {30$status = $reviewer->getReviewerStatus();3132// If this void is forced, always downgrade. For example, this happens33// when an author chooses "Request Review": existing reviews are always34// voided, even if they're sticky.35if (isset($must_downgrade[$status])) {36continue;37}3839// Otherwise, if this is a sticky accept, don't void it. Accepts may be40// explicitly sticky or unsticky, or they'll use the default value if41// no value is specified.42$is_sticky = $reviewer->getOption('sticky');43$is_sticky = coalesce($is_sticky, $default);4445if ($status === DifferentialReviewerStatus::STATUS_ACCEPTED) {46if ($is_sticky) {47unset($reviewers[$key]);48continue;49}50}51}525354return mpull($reviewers, 'getReviewerPHID');55}5657public function getTransactionHasEffect($object, $old, $new) {58return (bool)$new;59}6061public function applyExternalEffects($object, $value) {62$table = new DifferentialReviewer();63$table_name = $table->getTableName();64$conn = $table->establishConnection('w');6566queryfx(67$conn,68'UPDATE %T SET voidedPHID = %s69WHERE revisionPHID = %s70AND voidedPHID IS NULL71AND reviewerPHID IN (%Ls)',72$table_name,73$this->getActingAsPHID(),74$object->getPHID(),75$value);76}7778public function shouldHide() {79// This is an internal transaction, so don't show it in feeds or80// transaction logs.81return true;82}8384private function getVoidableStatuses() {85return array(86DifferentialReviewerStatus::STATUS_ACCEPTED,87DifferentialReviewerStatus::STATUS_REJECTED,88);89}9091}929394