Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F436670
PhabricatorCalendarImportDropController.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
PhabricatorCalendarImportDropController.php
View Options
<?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
PhabricatorCalendarICSFileImportEngine
();
$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
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, May 4, 12:07 AM (1 d, 12 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
62823
Default Alt Text
PhabricatorCalendarImportDropController.php (2 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment