@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Re-implement calendar.invite transactions

Summary:
Fix T11339.
Now, old and new are both simple lists of phids, and the rendering should make sense.

Test Plan: Viewed existing transaction with all 3 states.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin

Maniphest Tasks: T11339

Differential Revision: https://secure.phabricator.com/D16311

authored by

Aviv Eyal and committed by
avivey
b6bf0f6a fc950140

+52 -23
+37
resources/sql/autopatches/20160720.calendar.invitetxn.php
··· 1 + <?php 2 + 3 + $table = new PhabricatorCalendarEventTransaction(); 4 + $conn_w = $table->establishConnection('w'); 5 + 6 + echo pht( 7 + "Restructuring calendar invite transactions...\n"); 8 + 9 + foreach (new LiskMigrationIterator($table) as $txn) { 10 + $type = PhabricatorCalendarEventInviteTransaction::TRANSACTIONTYPE; 11 + if ($txn->getTransactionType() != $type) { 12 + continue; 13 + } 14 + 15 + $old_value = array_keys($txn->getOldValue()); 16 + 17 + $orig_new = $txn->getNewValue(); 18 + $status_uninvited = 'uninvited'; 19 + foreach ($orig_new as $key => $status) { 20 + if ($status == $status_uninvited) { 21 + unset($orig_new[$key]); 22 + } 23 + } 24 + $new_value = array_keys($orig_new); 25 + 26 + queryfx( 27 + $conn_w, 28 + 'UPDATE %T SET '. 29 + 'oldValue = %s, newValue = %s'. 30 + 'WHERE id = %d', 31 + $table->getTableName(), 32 + phutil_json_encode($old_value), 33 + phutil_json_encode($new_value), 34 + $txn->getID()); 35 + } 36 + 37 + echo pht('Done.')."\n";
+15 -23
src/applications/calendar/xaction/PhabricatorCalendarEventInviteTransaction.php
··· 15 15 } 16 16 } 17 17 18 - return mpull($invitees, 'getStatus', 'getInviteePHID'); 18 + return array_values(mpull($invitees, 'getInviteePHID')); 19 19 } 20 20 21 - public function generateNewValue($object, $value) { 21 + private function generateChangeMap($object, $new_value) { 22 22 $status_invited = PhabricatorCalendarEventInvitee::STATUS_INVITED; 23 23 $status_uninvited = PhabricatorCalendarEventInvitee::STATUS_UNINVITED; 24 24 $status_attending = PhabricatorCalendarEventInvitee::STATUS_ATTENDING; 25 25 26 - $invitees = $this->generateOldValue($object); 26 + $old = $this->generateOldValue($object); 27 27 28 - $new = array_fuse($value); 28 + $add = array_diff($new_value, $old); 29 + $rem = array_diff($old, $new_value); 29 30 30 - $all = array_keys($invitees + $new); 31 31 $map = array(); 32 - foreach ($all as $phid) { 33 - $is_old = isset($invitees[$phid]); 34 - $is_new = isset($new[$phid]); 35 - 36 - if ($is_old && !$is_new) { 32 + foreach ($add as $phid) { 33 + $map[$phid] = $status_invited; 34 + } 35 + foreach ($rem as $phid) { 37 36 $map[$phid] = $status_uninvited; 38 - } else if (!$is_old && $is_new) { 39 - $map[$phid] = $status_invited; 40 - } else { 41 - $map[$phid] = $invitees[$phid]; 42 - } 43 37 } 44 38 45 39 // If we're creating this event and the actor is inviting themselves, ··· 55 49 } 56 50 57 51 public function applyExternalEffects($object, $value) { 58 - $phids = array_keys($value); 52 + $map = $this->generateChangeMap($object, $value); 53 + 59 54 $invitees = $object->getInvitees(); 60 55 $invitees = mpull($invitees, null, 'getInviteePHID'); 61 56 62 - foreach ($phids as $phid) { 57 + foreach ($map as $phid => $status) { 63 58 $invitee = idx($invitees, $phid); 64 59 if (!$invitee) { 65 60 $invitee = id(new PhabricatorCalendarEventInvitee()) ··· 68 63 ->setInviterPHID($this->getActingAsPHID()); 69 64 $invitees[] = $invitee; 70 65 } 71 - $invitee->setStatus($value[$phid]) 66 + $invitee->setStatus($status) 72 67 ->save(); 73 68 } 74 69 ··· 179 174 $old = $this->getOldValue(); 180 175 $new = $this->getNewValue(); 181 176 182 - $add = array_diff_key($new, $old); 183 - $rem = array_diff_key($old, $new); 184 - 185 - $add = array_keys($add); 186 - $rem = array_keys($rem); 177 + $add = array_diff($new, $old); 178 + $rem = array_diff($old, $new); 187 179 188 180 return array(array_fuse($add), array_fuse($rem)); 189 181 }