mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-17 20:32:41 +01:00
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
This commit is contained in:
parent
fc950140b4
commit
b6bf0f6a3b
2 changed files with 52 additions and 23 deletions
37
resources/sql/autopatches/20160720.calendar.invitetxn.php
Normal file
37
resources/sql/autopatches/20160720.calendar.invitetxn.php
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$table = new PhabricatorCalendarEventTransaction();
|
||||||
|
$conn_w = $table->establishConnection('w');
|
||||||
|
|
||||||
|
echo pht(
|
||||||
|
"Restructuring calendar invite transactions...\n");
|
||||||
|
|
||||||
|
foreach (new LiskMigrationIterator($table) as $txn) {
|
||||||
|
$type = PhabricatorCalendarEventInviteTransaction::TRANSACTIONTYPE;
|
||||||
|
if ($txn->getTransactionType() != $type) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$old_value = array_keys($txn->getOldValue());
|
||||||
|
|
||||||
|
$orig_new = $txn->getNewValue();
|
||||||
|
$status_uninvited = 'uninvited';
|
||||||
|
foreach ($orig_new as $key => $status) {
|
||||||
|
if ($status == $status_uninvited) {
|
||||||
|
unset($orig_new[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$new_value = array_keys($orig_new);
|
||||||
|
|
||||||
|
queryfx(
|
||||||
|
$conn_w,
|
||||||
|
'UPDATE %T SET '.
|
||||||
|
'oldValue = %s, newValue = %s'.
|
||||||
|
'WHERE id = %d',
|
||||||
|
$table->getTableName(),
|
||||||
|
phutil_json_encode($old_value),
|
||||||
|
phutil_json_encode($new_value),
|
||||||
|
$txn->getID());
|
||||||
|
}
|
||||||
|
|
||||||
|
echo pht('Done.')."\n";
|
|
@ -15,31 +15,25 @@ final class PhabricatorCalendarEventInviteTransaction
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return mpull($invitees, 'getStatus', 'getInviteePHID');
|
return array_values(mpull($invitees, 'getInviteePHID'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateNewValue($object, $value) {
|
private function generateChangeMap($object, $new_value) {
|
||||||
$status_invited = PhabricatorCalendarEventInvitee::STATUS_INVITED;
|
$status_invited = PhabricatorCalendarEventInvitee::STATUS_INVITED;
|
||||||
$status_uninvited = PhabricatorCalendarEventInvitee::STATUS_UNINVITED;
|
$status_uninvited = PhabricatorCalendarEventInvitee::STATUS_UNINVITED;
|
||||||
$status_attending = PhabricatorCalendarEventInvitee::STATUS_ATTENDING;
|
$status_attending = PhabricatorCalendarEventInvitee::STATUS_ATTENDING;
|
||||||
|
|
||||||
$invitees = $this->generateOldValue($object);
|
$old = $this->generateOldValue($object);
|
||||||
|
|
||||||
$new = array_fuse($value);
|
$add = array_diff($new_value, $old);
|
||||||
|
$rem = array_diff($old, $new_value);
|
||||||
|
|
||||||
$all = array_keys($invitees + $new);
|
|
||||||
$map = array();
|
$map = array();
|
||||||
foreach ($all as $phid) {
|
foreach ($add as $phid) {
|
||||||
$is_old = isset($invitees[$phid]);
|
|
||||||
$is_new = isset($new[$phid]);
|
|
||||||
|
|
||||||
if ($is_old && !$is_new) {
|
|
||||||
$map[$phid] = $status_uninvited;
|
|
||||||
} else if (!$is_old && $is_new) {
|
|
||||||
$map[$phid] = $status_invited;
|
$map[$phid] = $status_invited;
|
||||||
} else {
|
|
||||||
$map[$phid] = $invitees[$phid];
|
|
||||||
}
|
}
|
||||||
|
foreach ($rem as $phid) {
|
||||||
|
$map[$phid] = $status_uninvited;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're creating this event and the actor is inviting themselves,
|
// If we're creating this event and the actor is inviting themselves,
|
||||||
|
@ -55,11 +49,12 @@ final class PhabricatorCalendarEventInviteTransaction
|
||||||
}
|
}
|
||||||
|
|
||||||
public function applyExternalEffects($object, $value) {
|
public function applyExternalEffects($object, $value) {
|
||||||
$phids = array_keys($value);
|
$map = $this->generateChangeMap($object, $value);
|
||||||
|
|
||||||
$invitees = $object->getInvitees();
|
$invitees = $object->getInvitees();
|
||||||
$invitees = mpull($invitees, null, 'getInviteePHID');
|
$invitees = mpull($invitees, null, 'getInviteePHID');
|
||||||
|
|
||||||
foreach ($phids as $phid) {
|
foreach ($map as $phid => $status) {
|
||||||
$invitee = idx($invitees, $phid);
|
$invitee = idx($invitees, $phid);
|
||||||
if (!$invitee) {
|
if (!$invitee) {
|
||||||
$invitee = id(new PhabricatorCalendarEventInvitee())
|
$invitee = id(new PhabricatorCalendarEventInvitee())
|
||||||
|
@ -68,7 +63,7 @@ final class PhabricatorCalendarEventInviteTransaction
|
||||||
->setInviterPHID($this->getActingAsPHID());
|
->setInviterPHID($this->getActingAsPHID());
|
||||||
$invitees[] = $invitee;
|
$invitees[] = $invitee;
|
||||||
}
|
}
|
||||||
$invitee->setStatus($value[$phid])
|
$invitee->setStatus($status)
|
||||||
->save();
|
->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,11 +174,8 @@ final class PhabricatorCalendarEventInviteTransaction
|
||||||
$old = $this->getOldValue();
|
$old = $this->getOldValue();
|
||||||
$new = $this->getNewValue();
|
$new = $this->getNewValue();
|
||||||
|
|
||||||
$add = array_diff_key($new, $old);
|
$add = array_diff($new, $old);
|
||||||
$rem = array_diff_key($old, $new);
|
$rem = array_diff($old, $new);
|
||||||
|
|
||||||
$add = array_keys($add);
|
|
||||||
$rem = array_keys($rem);
|
|
||||||
|
|
||||||
return array(array_fuse($add), array_fuse($rem));
|
return array(array_fuse($add), array_fuse($rem));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue