Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15380024
D16311.id39231.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D16311.id39231.diff
View Options
diff --git a/resources/sql/autopatches/20160720.calendar.invitetxn.php b/resources/sql/autopatches/20160720.calendar.invitetxn.php
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20160720.calendar.invitetxn.php
@@ -0,0 +1,43 @@
+<?php
+
+$table = new PhabricatorCalendarEventTransaction();
+$conn_w = $table->establishConnection('w');
+
+echo pht(
+ "Restructring calendar invite transactions...\n");
+
+foreach (new LiskMigrationIterator($table) as $txn) {
+ $type = PhabricatorCalendarEventInviteTransaction::TRANSACTIONTYPE;
+ if ($txn->getTransactionType() != $type) {
+ continue;
+ }
+
+ $old_value = update_old_value($txn->getOldValue());
+
+ $new_value = update_new_value($txn->getNewValue());
+
+ queryfx(
+ $conn_w,
+ 'UPDATE %T SET '.
+ 'oldValue = %s, newValue = %s'.
+ 'WHERE id = %d',
+ $table->getTableName(),
+ json_encode($old_value),
+ json_encode($new_value),
+ $txn->getID());
+}
+
+echo pht('Done.')."\n";
+
+function update_old_value($orig_old) {
+ return array_keys($orig_old);
+}
+function update_new_value($orig_new) {
+ $status_uninvited = 'uninvited';
+ foreach ($orig_new as $key => $status) {
+ if ($status == $status_uninvited) {
+ unset($orig_new[$key]);
+ }
+ }
+ return array_keys($orig_new);
+}
diff --git a/src/applications/calendar/xaction/PhabricatorCalendarEventInviteTransaction.php b/src/applications/calendar/xaction/PhabricatorCalendarEventInviteTransaction.php
--- a/src/applications/calendar/xaction/PhabricatorCalendarEventInviteTransaction.php
+++ b/src/applications/calendar/xaction/PhabricatorCalendarEventInviteTransaction.php
@@ -15,31 +15,25 @@
}
}
- 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_uninvited = PhabricatorCalendarEventInvitee::STATUS_UNINVITED;
$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();
- foreach ($all 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) {
+ foreach ($add as $phid) {
$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,
@@ -55,11 +49,12 @@
}
public function applyExternalEffects($object, $value) {
- $phids = array_keys($value);
+ $map = $this->generateChangeMap($object, $value);
+
$invitees = $object->getInvitees();
$invitees = mpull($invitees, null, 'getInviteePHID');
- foreach ($phids as $phid) {
+ foreach ($map as $phid => $status) {
$invitee = idx($invitees, $phid);
if (!$invitee) {
$invitee = id(new PhabricatorCalendarEventInvitee())
@@ -68,7 +63,7 @@
->setInviterPHID($this->getActingAsPHID());
$invitees[] = $invitee;
}
- $invitee->setStatus($value[$phid])
+ $invitee->setStatus($status)
->save();
}
@@ -179,11 +174,8 @@
$old = $this->getOldValue();
$new = $this->getNewValue();
- $add = array_diff_key($new, $old);
- $rem = array_diff_key($old, $new);
-
- $add = array_keys($add);
- $rem = array_keys($rem);
+ $add = array_diff($new, $old);
+ $rem = array_diff($old, $new);
return array(array_fuse($add), array_fuse($rem));
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Mar 15, 12:57 AM (1 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7678755
Default Alt Text
D16311.id39231.diff (3 KB)
Attached To
Mode
D16311: Re-implement calendar.invite transactions
Attached
Detach File
Event Timeline
Log In to Comment