@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+130 -7
+4
src/__phutil_library_map__.php
··· 2137 2137 'PhabricatorCalendarImportOrphanLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportOrphanLogType.php', 2138 2138 'PhabricatorCalendarImportPHIDType' => 'applications/calendar/phid/PhabricatorCalendarImportPHIDType.php', 2139 2139 'PhabricatorCalendarImportQuery' => 'applications/calendar/query/PhabricatorCalendarImportQuery.php', 2140 + 'PhabricatorCalendarImportReloadController' => 'applications/calendar/controller/PhabricatorCalendarImportReloadController.php', 2141 + 'PhabricatorCalendarImportReloadTransaction' => 'applications/calendar/xaction/PhabricatorCalendarImportReloadTransaction.php', 2140 2142 'PhabricatorCalendarImportSearchEngine' => 'applications/calendar/query/PhabricatorCalendarImportSearchEngine.php', 2141 2143 'PhabricatorCalendarImportTransaction' => 'applications/calendar/storage/PhabricatorCalendarImportTransaction.php', 2142 2144 'PhabricatorCalendarImportTransactionQuery' => 'applications/calendar/query/PhabricatorCalendarImportTransactionQuery.php', ··· 6982 6984 'PhabricatorCalendarImportOrphanLogType' => 'PhabricatorCalendarImportLogType', 6983 6985 'PhabricatorCalendarImportPHIDType' => 'PhabricatorPHIDType', 6984 6986 'PhabricatorCalendarImportQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 6987 + 'PhabricatorCalendarImportReloadController' => 'PhabricatorCalendarController', 6988 + 'PhabricatorCalendarImportReloadTransaction' => 'PhabricatorCalendarImportTransactionType', 6985 6989 'PhabricatorCalendarImportSearchEngine' => 'PhabricatorApplicationSearchEngine', 6986 6990 'PhabricatorCalendarImportTransaction' => 'PhabricatorModularTransaction', 6987 6991 'PhabricatorCalendarImportTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
+2
src/applications/calendar/application/PhabricatorCalendarApplication.php
··· 85 85 => 'PhabricatorCalendarImportDisableController', 86 86 'delete/(?P<id>[1-9]\d*)/' 87 87 => 'PhabricatorCalendarImportDeleteController', 88 + 'reload/(?P<id>[1-9]\d*)/' 89 + => 'PhabricatorCalendarImportReloadController', 88 90 'drop/' 89 91 => 'PhabricatorCalendarImportDropController', 90 92 'log/' => array(
+52
src/applications/calendar/controller/PhabricatorCalendarImportReloadController.php
··· 1 + <?php 2 + 3 + final class PhabricatorCalendarImportReloadController 4 + extends PhabricatorCalendarController { 5 + 6 + public function handleRequest(AphrontRequest $request) { 7 + $viewer = $request->getViewer(); 8 + 9 + $import = id(new PhabricatorCalendarImportQuery()) 10 + ->setViewer($viewer) 11 + ->withIDs(array($request->getURIData('id'))) 12 + ->requireCapabilities( 13 + array( 14 + PhabricatorPolicyCapability::CAN_VIEW, 15 + PhabricatorPolicyCapability::CAN_EDIT, 16 + )) 17 + ->executeOne(); 18 + if (!$import) { 19 + return new Aphront404Response(); 20 + } 21 + 22 + $import_uri = $import->getURI(); 23 + 24 + if ($request->isFormPost()) { 25 + $xactions = array(); 26 + $xactions[] = id(new PhabricatorCalendarImportTransaction()) 27 + ->setTransactionType( 28 + PhabricatorCalendarImportReloadTransaction::TRANSACTIONTYPE) 29 + ->setNewValue(true); 30 + 31 + $editor = id(new PhabricatorCalendarImportEditor()) 32 + ->setActor($viewer) 33 + ->setContinueOnNoEffect(true) 34 + ->setContinueOnMissingFields(true) 35 + ->setContentSourceFromRequest($request); 36 + 37 + $editor->applyTransactions($import, $xactions); 38 + 39 + return id(new AphrontRedirectResponse())->setURI($import_uri); 40 + } 41 + 42 + return $this->newDialog() 43 + ->setTitle(pht('Reload Events')) 44 + ->appendParagraph( 45 + pht( 46 + 'Reload this source? Events imported from this source will '. 47 + 'be updated.')) 48 + ->addCancelButton($import_uri) 49 + ->addSubmitButton(pht('Reload Events')); 50 + } 51 + 52 + }
+11 -1
src/applications/calendar/controller/PhabricatorCalendarImportViewController.php
··· 105 105 ->setWorkflow(!$can_edit) 106 106 ->setHref($edit_uri)); 107 107 108 + $reload_uri = "import/reload/{$id}/"; 109 + $reload_uri = $this->getApplicationURI($reload_uri); 110 + 111 + $curtain->addAction( 112 + id(new PhabricatorActionView()) 113 + ->setName(pht('Reload Import')) 114 + ->setIcon('fa-refresh') 115 + ->setDisabled(!$can_edit) 116 + ->setWorkflow(true) 117 + ->setHref($reload_uri)); 118 + 108 119 $disable_uri = "import/disable/{$id}/"; 109 120 $disable_uri = $this->getApplicationURI($disable_uri); 110 121 if ($import->getIsDisabled()) { ··· 122 133 ->setDisabled(!$can_disable) 123 134 ->setWorkflow(true) 124 135 ->setHref($disable_uri)); 125 - 126 136 127 137 if ($can_edit) { 128 138 $can_delete = $engine->canDeleteAnyEvents($viewer, $import);
+20
src/applications/calendar/editor/PhabricatorCalendarImportEditEngine.php
··· 101 101 ->setConduitDescription(pht('Disable or restore the import.')) 102 102 ->setConduitTypeDescription(pht('True to cancel the import.')) 103 103 ->setValue($object->getIsDisabled()), 104 + id(new PhabricatorBoolEditField()) 105 + ->setKey('delete') 106 + ->setLabel(pht('Delete Imported Events')) 107 + ->setDescription(pht('Delete all events from this source.')) 108 + ->setTransactionType( 109 + PhabricatorCalendarImportDisableTransaction::TRANSACTIONTYPE) 110 + ->setIsConduitOnly(true) 111 + ->setConduitDescription(pht('Disable or restore the import.')) 112 + ->setConduitTypeDescription(pht('True to delete imported events.')) 113 + ->setValue(false), 114 + id(new PhabricatorBoolEditField()) 115 + ->setKey('reload') 116 + ->setLabel(pht('Reload Import')) 117 + ->setDescription(pht('Reload events imported from this source.')) 118 + ->setTransactionType( 119 + PhabricatorCalendarImportDisableTransaction::TRANSACTIONTYPE) 120 + ->setIsConduitOnly(true) 121 + ->setConduitDescription(pht('Disable or restore the import.')) 122 + ->setConduitTypeDescription(pht('True to reload the import.')) 123 + ->setValue(false), 104 124 ); 105 125 106 126 $import_engine = $object->getEngine();
+14 -2
src/applications/calendar/editor/PhabricatorCalendarImportEditor.php
··· 28 28 PhabricatorLiskDAO $object, 29 29 array $xactions) { 30 30 31 - if ($this->getIsNewObject()) { 31 + $type_reload = PhabricatorCalendarImportReloadTransaction::TRANSACTIONTYPE; 32 + 33 + // We import events when you create a source, or if you later reload it 34 + // explicitly. 35 + $should_reload = $this->getIsNewObject(); 36 + foreach ($xactions as $xaction) { 37 + if ($xaction->getTransactionType() == $type_reload) { 38 + $should_reload = true; 39 + break; 40 + } 41 + } 42 + 43 + if ($should_reload) { 32 44 $actor = $this->getActor(); 33 45 34 46 $import_engine = $object->getEngine(); 35 - $import_engine->didCreateImport($actor, $object); 47 + $import_engine->importEventsFromSource($actor, $object); 36 48 } 37 49 38 50 return $xactions;
+1 -1
src/applications/calendar/import/PhabricatorCalendarICSFileImportEngine.php
··· 59 59 } 60 60 } 61 61 62 - public function didCreateImport( 62 + public function importEventsFromSource( 63 63 PhabricatorUser $viewer, 64 64 PhabricatorCalendarImport $import) { 65 65
+1 -1
src/applications/calendar/import/PhabricatorCalendarICSURIImportEngine.php
··· 71 71 return pht('ICS URI'); 72 72 } 73 73 74 - public function didCreateImport( 74 + public function importEventsFromSource( 75 75 PhabricatorUser $viewer, 76 76 PhabricatorCalendarImport $import) { 77 77
+1 -1
src/applications/calendar/import/PhabricatorCalendarImportEngine.php
··· 25 25 26 26 abstract public function getDisplayName(PhabricatorCalendarImport $import); 27 27 28 - abstract public function didCreateImport( 28 + abstract public function importEventsFromSource( 29 29 PhabricatorUser $viewer, 30 30 PhabricatorCalendarImport $import); 31 31
+1 -1
src/applications/calendar/importlog/PhabricatorCalendarImportUpdateLogType.php
··· 26 26 public function getDisplayIcon( 27 27 PhabricatorUser $viewer, 28 28 PhabricatorCalendarImportLog $log) { 29 - return 'fa-upload'; 29 + return 'fa-calendar'; 30 30 } 31 31 32 32 public function getDisplayColor(
+23
src/applications/calendar/xaction/PhabricatorCalendarImportReloadTransaction.php
··· 1 + <?php 2 + 3 + final class PhabricatorCalendarImportReloadTransaction 4 + extends PhabricatorCalendarImportTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'calendar.import.reload'; 7 + 8 + public function generateOldValue($object) { 9 + return false; 10 + } 11 + 12 + public function applyExternalEffects($object, $value) { 13 + // NOTE: This transaction does nothing directly; instead, the Editor 14 + // reacts to it and performs the reload. 15 + } 16 + 17 + public function getTitle() { 18 + return pht( 19 + '%s reloaded this event source.', 20 + $this->renderAuthor()); 21 + } 22 + 23 + }