mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-18 11:30:55 +01:00
Add an explicit "Reload Import" action to imports
Summary: Ref T10747. This makes development/debugging/testing easier and moves us closer to triggered imports (e.g., keep in sync with Google once per day). Test Plan: - Reloaded an event import. - Edited an event in Google Calendar, reloaded, got updated event. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10747 Differential Revision: https://secure.phabricator.com/D16747
This commit is contained in:
parent
c21a71f024
commit
f4a3887b6b
11 changed files with 130 additions and 7 deletions
|
@ -2137,6 +2137,8 @@ phutil_register_library_map(array(
|
|||
'PhabricatorCalendarImportOrphanLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportOrphanLogType.php',
|
||||
'PhabricatorCalendarImportPHIDType' => 'applications/calendar/phid/PhabricatorCalendarImportPHIDType.php',
|
||||
'PhabricatorCalendarImportQuery' => 'applications/calendar/query/PhabricatorCalendarImportQuery.php',
|
||||
'PhabricatorCalendarImportReloadController' => 'applications/calendar/controller/PhabricatorCalendarImportReloadController.php',
|
||||
'PhabricatorCalendarImportReloadTransaction' => 'applications/calendar/xaction/PhabricatorCalendarImportReloadTransaction.php',
|
||||
'PhabricatorCalendarImportSearchEngine' => 'applications/calendar/query/PhabricatorCalendarImportSearchEngine.php',
|
||||
'PhabricatorCalendarImportTransaction' => 'applications/calendar/storage/PhabricatorCalendarImportTransaction.php',
|
||||
'PhabricatorCalendarImportTransactionQuery' => 'applications/calendar/query/PhabricatorCalendarImportTransactionQuery.php',
|
||||
|
@ -6982,6 +6984,8 @@ phutil_register_library_map(array(
|
|||
'PhabricatorCalendarImportOrphanLogType' => 'PhabricatorCalendarImportLogType',
|
||||
'PhabricatorCalendarImportPHIDType' => 'PhabricatorPHIDType',
|
||||
'PhabricatorCalendarImportQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorCalendarImportReloadController' => 'PhabricatorCalendarController',
|
||||
'PhabricatorCalendarImportReloadTransaction' => 'PhabricatorCalendarImportTransactionType',
|
||||
'PhabricatorCalendarImportSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'PhabricatorCalendarImportTransaction' => 'PhabricatorModularTransaction',
|
||||
'PhabricatorCalendarImportTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||
|
|
|
@ -85,6 +85,8 @@ final class PhabricatorCalendarApplication extends PhabricatorApplication {
|
|||
=> 'PhabricatorCalendarImportDisableController',
|
||||
'delete/(?P<id>[1-9]\d*)/'
|
||||
=> 'PhabricatorCalendarImportDeleteController',
|
||||
'reload/(?P<id>[1-9]\d*)/'
|
||||
=> 'PhabricatorCalendarImportReloadController',
|
||||
'drop/'
|
||||
=> 'PhabricatorCalendarImportDropController',
|
||||
'log/' => array(
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorCalendarImportReloadController
|
||||
extends PhabricatorCalendarController {
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
|
||||
$import = id(new PhabricatorCalendarImportQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($request->getURIData('id')))
|
||||
->requireCapabilities(
|
||||
array(
|
||||
PhabricatorPolicyCapability::CAN_VIEW,
|
||||
PhabricatorPolicyCapability::CAN_EDIT,
|
||||
))
|
||||
->executeOne();
|
||||
if (!$import) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$import_uri = $import->getURI();
|
||||
|
||||
if ($request->isFormPost()) {
|
||||
$xactions = array();
|
||||
$xactions[] = id(new PhabricatorCalendarImportTransaction())
|
||||
->setTransactionType(
|
||||
PhabricatorCalendarImportReloadTransaction::TRANSACTIONTYPE)
|
||||
->setNewValue(true);
|
||||
|
||||
$editor = id(new PhabricatorCalendarImportEditor())
|
||||
->setActor($viewer)
|
||||
->setContinueOnNoEffect(true)
|
||||
->setContinueOnMissingFields(true)
|
||||
->setContentSourceFromRequest($request);
|
||||
|
||||
$editor->applyTransactions($import, $xactions);
|
||||
|
||||
return id(new AphrontRedirectResponse())->setURI($import_uri);
|
||||
}
|
||||
|
||||
return $this->newDialog()
|
||||
->setTitle(pht('Reload Events'))
|
||||
->appendParagraph(
|
||||
pht(
|
||||
'Reload this source? Events imported from this source will '.
|
||||
'be updated.'))
|
||||
->addCancelButton($import_uri)
|
||||
->addSubmitButton(pht('Reload Events'));
|
||||
}
|
||||
|
||||
}
|
|
@ -105,6 +105,17 @@ final class PhabricatorCalendarImportViewController
|
|||
->setWorkflow(!$can_edit)
|
||||
->setHref($edit_uri));
|
||||
|
||||
$reload_uri = "import/reload/{$id}/";
|
||||
$reload_uri = $this->getApplicationURI($reload_uri);
|
||||
|
||||
$curtain->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
->setName(pht('Reload Import'))
|
||||
->setIcon('fa-refresh')
|
||||
->setDisabled(!$can_edit)
|
||||
->setWorkflow(true)
|
||||
->setHref($reload_uri));
|
||||
|
||||
$disable_uri = "import/disable/{$id}/";
|
||||
$disable_uri = $this->getApplicationURI($disable_uri);
|
||||
if ($import->getIsDisabled()) {
|
||||
|
@ -123,7 +134,6 @@ final class PhabricatorCalendarImportViewController
|
|||
->setWorkflow(true)
|
||||
->setHref($disable_uri));
|
||||
|
||||
|
||||
if ($can_edit) {
|
||||
$can_delete = $engine->canDeleteAnyEvents($viewer, $import);
|
||||
} else {
|
||||
|
|
|
@ -101,6 +101,26 @@ final class PhabricatorCalendarImportEditEngine
|
|||
->setConduitDescription(pht('Disable or restore the import.'))
|
||||
->setConduitTypeDescription(pht('True to cancel the import.'))
|
||||
->setValue($object->getIsDisabled()),
|
||||
id(new PhabricatorBoolEditField())
|
||||
->setKey('delete')
|
||||
->setLabel(pht('Delete Imported Events'))
|
||||
->setDescription(pht('Delete all events from this source.'))
|
||||
->setTransactionType(
|
||||
PhabricatorCalendarImportDisableTransaction::TRANSACTIONTYPE)
|
||||
->setIsConduitOnly(true)
|
||||
->setConduitDescription(pht('Disable or restore the import.'))
|
||||
->setConduitTypeDescription(pht('True to delete imported events.'))
|
||||
->setValue(false),
|
||||
id(new PhabricatorBoolEditField())
|
||||
->setKey('reload')
|
||||
->setLabel(pht('Reload Import'))
|
||||
->setDescription(pht('Reload events imported from this source.'))
|
||||
->setTransactionType(
|
||||
PhabricatorCalendarImportDisableTransaction::TRANSACTIONTYPE)
|
||||
->setIsConduitOnly(true)
|
||||
->setConduitDescription(pht('Disable or restore the import.'))
|
||||
->setConduitTypeDescription(pht('True to reload the import.'))
|
||||
->setValue(false),
|
||||
);
|
||||
|
||||
$import_engine = $object->getEngine();
|
||||
|
|
|
@ -28,11 +28,23 @@ final class PhabricatorCalendarImportEditor
|
|||
PhabricatorLiskDAO $object,
|
||||
array $xactions) {
|
||||
|
||||
if ($this->getIsNewObject()) {
|
||||
$type_reload = PhabricatorCalendarImportReloadTransaction::TRANSACTIONTYPE;
|
||||
|
||||
// We import events when you create a source, or if you later reload it
|
||||
// explicitly.
|
||||
$should_reload = $this->getIsNewObject();
|
||||
foreach ($xactions as $xaction) {
|
||||
if ($xaction->getTransactionType() == $type_reload) {
|
||||
$should_reload = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($should_reload) {
|
||||
$actor = $this->getActor();
|
||||
|
||||
$import_engine = $object->getEngine();
|
||||
$import_engine->didCreateImport($actor, $object);
|
||||
$import_engine->importEventsFromSource($actor, $object);
|
||||
}
|
||||
|
||||
return $xactions;
|
||||
|
|
|
@ -59,7 +59,7 @@ final class PhabricatorCalendarICSFileImportEngine
|
|||
}
|
||||
}
|
||||
|
||||
public function didCreateImport(
|
||||
public function importEventsFromSource(
|
||||
PhabricatorUser $viewer,
|
||||
PhabricatorCalendarImport $import) {
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ final class PhabricatorCalendarICSURIImportEngine
|
|||
return pht('ICS URI');
|
||||
}
|
||||
|
||||
public function didCreateImport(
|
||||
public function importEventsFromSource(
|
||||
PhabricatorUser $viewer,
|
||||
PhabricatorCalendarImport $import) {
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ abstract class PhabricatorCalendarImportEngine
|
|||
|
||||
abstract public function getDisplayName(PhabricatorCalendarImport $import);
|
||||
|
||||
abstract public function didCreateImport(
|
||||
abstract public function importEventsFromSource(
|
||||
PhabricatorUser $viewer,
|
||||
PhabricatorCalendarImport $import);
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ final class PhabricatorCalendarImportUpdateLogType
|
|||
public function getDisplayIcon(
|
||||
PhabricatorUser $viewer,
|
||||
PhabricatorCalendarImportLog $log) {
|
||||
return 'fa-upload';
|
||||
return 'fa-calendar';
|
||||
}
|
||||
|
||||
public function getDisplayColor(
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorCalendarImportReloadTransaction
|
||||
extends PhabricatorCalendarImportTransactionType {
|
||||
|
||||
const TRANSACTIONTYPE = 'calendar.import.reload';
|
||||
|
||||
public function generateOldValue($object) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function applyExternalEffects($object, $value) {
|
||||
// NOTE: This transaction does nothing directly; instead, the Editor
|
||||
// reacts to it and performs the reload.
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
return pht(
|
||||
'%s reloaded this event source.',
|
||||
$this->renderAuthor());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue