Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow users to drop .ics files on calendar views to import them
Summary: Ref T10747. When a user drops a ".ics" file or a bunch of ".ics" files into a calendar view, import the events. (Possibly we should just do this if you drop ".ics" files into any application, but we can look at that later.) Test Plan: Dropped some .ics files into calendar views, got imports. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10747 Differential Revision: https://secure.phabricator.com/D16722
- Loading branch information
epriestley
committed
Oct 18, 2016
1 parent
67cb277
commit f9f25c1
Showing
11 changed files
with
198 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/applications/calendar/controller/PhabricatorCalendarImportDropController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
final class PhabricatorCalendarImportDropController | ||
extends PhabricatorCalendarController { | ||
|
||
public function handleRequest(AphrontRequest $request) { | ||
$viewer = $request->getViewer(); | ||
|
||
if (!$request->validateCSRF()) { | ||
return new Aphront400Response(); | ||
} | ||
|
||
$cancel_uri = $this->getApplicationURI(); | ||
|
||
$ids = $request->getStrList('h'); | ||
if ($ids) { | ||
$files = id(new PhabricatorFileQuery()) | ||
->setViewer($viewer) | ||
->withIDs($ids) | ||
->setRaisePolicyExceptions(true) | ||
->execute(); | ||
} else { | ||
$files = array(); | ||
} | ||
|
||
if (!$files) { | ||
return $this->newDialog() | ||
->setTitle(pht('Nothing Uploaded')) | ||
->appendParagraph( | ||
pht( | ||
'Drag and drop .ics files to upload them and import them into '. | ||
'Calendar.')) | ||
->addCancelButton($cancel_uri, pht('Done')); | ||
} | ||
|
||
$engine = new PhabricatorCalendarICSImportEngine(); | ||
$imports = array(); | ||
foreach ($files as $file) { | ||
$import = PhabricatorCalendarImport::initializeNewCalendarImport( | ||
$viewer, | ||
clone $engine); | ||
|
||
$xactions = array(); | ||
$xactions[] = id(new PhabricatorCalendarImportTransaction()) | ||
->setTransactionType( | ||
PhabricatorCalendarImportICSFileTransaction::TRANSACTIONTYPE) | ||
->setNewValue($file->getPHID()); | ||
|
||
$editor = id(new PhabricatorCalendarImportEditor()) | ||
->setActor($viewer) | ||
->setContinueOnNoEffect(true) | ||
->setContinueOnMissingFields(true) | ||
->setContentSourceFromRequest($request); | ||
|
||
$editor->applyTransactions($import, $xactions); | ||
|
||
$imports[] = $import; | ||
} | ||
|
||
$import_phids = mpull($imports, 'getPHID'); | ||
$events = id(new PhabricatorCalendarEventQuery()) | ||
->setViewer($viewer) | ||
->withImportSourcePHIDs($import_phids) | ||
->execute(); | ||
|
||
if (count($events) == 1) { | ||
// The user imported exactly one event. This is consistent with dropping | ||
// a .ics file from an email; just take them to the event. | ||
$event = head($events); | ||
$next_uri = $event->getURI(); | ||
} else if (count($imports) > 1) { | ||
// The user imported multiple different files. Take them to a summary | ||
// list of generated import activity. | ||
$source_phids = implode(',', $import_phids); | ||
$next_uri = '/calendar/import/log/?importSourcePHIDs='.$source_phids; | ||
} else { | ||
// The user imported one file, which had zero or more than one event. | ||
// Take them to the import detail page. | ||
$import = head($imports); | ||
$next_uri = $import->getURI(); | ||
} | ||
|
||
return id(new AphrontRedirectResponse())->setURI($next_uri); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,6 +94,4 @@ public function getHeader() { | |
return $this->header; | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters