diff --git a/resources/sql/autopatches/20140205.cal.2.phid-col.sql b/resources/sql/autopatches/20140205.cal.2.phid-col.sql new file mode 100644 index 0000000000..3f1e10e423 --- /dev/null +++ b/resources/sql/autopatches/20140205.cal.2.phid-col.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_calendar.calendar_event + ADD phid VARCHAR(64) NOT NULL COLLATE utf8_bin AFTER id; diff --git a/resources/sql/autopatches/20140205.cal.3.phid-mig.php b/resources/sql/autopatches/20140205.cal.3.phid-mig.php new file mode 100644 index 0000000000..6ba4ff7c5c --- /dev/null +++ b/resources/sql/autopatches/20140205.cal.3.phid-mig.php @@ -0,0 +1,22 @@ +establishConnection('w'); + +echo "Assigning PHIDs to events...\n"; +foreach (new LiskMigrationIterator($table) as $event) { + $id = $event->getID(); + + echo "Updating event {$id}...\n"; + if ($event->getPHID()) { + continue; + } + + queryfx( + $conn_w, + 'UPDATE %T SET phid = %s WHERE id = %d', + $table->getTableName(), + $table->generatePHID(), + $id); +} +echo "Done.\n"; diff --git a/resources/sql/autopatches/20140205.cal.4.phid-key.sql b/resources/sql/autopatches/20140205.cal.4.phid-key.sql new file mode 100644 index 0000000000..cde0e10b78 --- /dev/null +++ b/resources/sql/autopatches/20140205.cal.4.phid-key.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_calendar.calendar_event + ADD UNIQUE KEY `key_phid` (phid); diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 0b57178ab0..5895d53628 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1271,6 +1271,7 @@ phutil_register_library_map(array( 'PhabricatorCalendarEventViewController' => 'applications/calendar/controller/PhabricatorCalendarEventViewController.php', 'PhabricatorCalendarHoliday' => 'applications/calendar/storage/PhabricatorCalendarHoliday.php', 'PhabricatorCalendarHolidayTestCase' => 'applications/calendar/storage/__tests__/PhabricatorCalendarHolidayTestCase.php', + 'PhabricatorCalendarPHIDTypeEvent' => 'applications/calendar/phid/PhabricatorCalendarPHIDTypeEvent.php', 'PhabricatorCampfireProtocolAdapter' => 'infrastructure/daemon/bot/adapter/PhabricatorCampfireProtocolAdapter.php', 'PhabricatorChangeParserTestCase' => 'applications/repository/worker/__tests__/PhabricatorChangeParserTestCase.php', 'PhabricatorChangesetResponse' => 'infrastructure/diff/PhabricatorChangesetResponse.php', @@ -3920,6 +3921,7 @@ phutil_register_library_map(array( 'PhabricatorCalendarEventViewController' => 'PhabricatorDashboardController', 'PhabricatorCalendarHoliday' => 'PhabricatorCalendarDAO', 'PhabricatorCalendarHolidayTestCase' => 'PhabricatorTestCase', + 'PhabricatorCalendarPHIDTypeEvent' => 'PhabricatorPHIDType', 'PhabricatorCampfireProtocolAdapter' => 'PhabricatorBotBaseStreamingProtocolAdapter', 'PhabricatorChangeParserTestCase' => 'PhabricatorWorkingCopyTestCase', 'PhabricatorChangesetResponse' => 'AphrontProxyResponse', diff --git a/src/applications/calendar/phid/PhabricatorCalendarPHIDTypeEvent.php b/src/applications/calendar/phid/PhabricatorCalendarPHIDTypeEvent.php new file mode 100644 index 0000000000..0fb7c9d086 --- /dev/null +++ b/src/applications/calendar/phid/PhabricatorCalendarPHIDTypeEvent.php @@ -0,0 +1,41 @@ +withPHIDs($phids); + } + + public function loadHandles( + PhabricatorHandleQuery $query, + array $handles, + array $objects) { + + foreach ($handles as $phid => $handle) { + $event = $objects[$phid]; + + $id = $event->getID(); + + $handle->setName(pht('Event %d', $id)); + } + } + +} diff --git a/src/applications/calendar/query/PhabricatorCalendarEventQuery.php b/src/applications/calendar/query/PhabricatorCalendarEventQuery.php index 7cb373d583..76d99b941b 100644 --- a/src/applications/calendar/query/PhabricatorCalendarEventQuery.php +++ b/src/applications/calendar/query/PhabricatorCalendarEventQuery.php @@ -4,6 +4,7 @@ final class PhabricatorCalendarEventQuery extends PhabricatorCursorPagedPolicyAwareQuery { private $ids; + private $phids; private $rangeBegin; private $rangeEnd; private $invitedPHIDs; @@ -14,6 +15,11 @@ final class PhabricatorCalendarEventQuery return $this; } + public function withPHIDs(array $phids) { + $this->phids = $phids; + return $this; + } + public function withDateRange($begin, $end) { $this->rangeBegin = $begin; $this->rangeEnd = $end; @@ -55,6 +61,13 @@ final class PhabricatorCalendarEventQuery $this->ids); } + if ($this->phids) { + $where[] = qsprintf( + $conn_r, + 'phid IN (%Ls)', + $this->phids); + } + if ($this->rangeBegin) { $where[] = qsprintf( $conn_r, diff --git a/src/applications/calendar/storage/PhabricatorCalendarEvent.php b/src/applications/calendar/storage/PhabricatorCalendarEvent.php index e925a3a89a..db9af33530 100644 --- a/src/applications/calendar/storage/PhabricatorCalendarEvent.php +++ b/src/applications/calendar/storage/PhabricatorCalendarEvent.php @@ -34,6 +34,17 @@ final class PhabricatorCalendarEvent return $options[$this->status]; } + public function getConfiguration() { + return array( + self::CONFIG_AUX_PHID => true, + ) + parent::getConfiguration(); + } + + public function generatePHID() { + return PhabricatorPHID::generateNewPHID( + PhabricatorCalendarPHIDTypeEvent::TYPECONST); + } + public function getTerseSummary(PhabricatorUser $viewer) { $until = phabricator_date($this->dateTo, $viewer); if ($this->status == PhabricatorCalendarEvent::STATUS_SPORADIC) {