@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.

Allow events from a particular import source to be bulk-deleted

Summary:
Ref T10747. If you accidentally import the wrong thing, you can clean up the big mess you made.

These imported events are read-only so it's OK to destroy them completely (vs disable/hide/archive).

Test Plan: Destroyed some imported events.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10747

Differential Revision: https://secure.phabricator.com/D16720

+132 -1
+4
src/__phutil_library_map__.php
··· 2105 2105 'PhabricatorCalendarIconSet' => 'applications/calendar/icon/PhabricatorCalendarIconSet.php', 2106 2106 'PhabricatorCalendarImport' => 'applications/calendar/storage/PhabricatorCalendarImport.php', 2107 2107 'PhabricatorCalendarImportDefaultLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportDefaultLogType.php', 2108 + 'PhabricatorCalendarImportDeleteController' => 'applications/calendar/controller/PhabricatorCalendarImportDeleteController.php', 2109 + 'PhabricatorCalendarImportDeleteTransaction' => 'applications/calendar/xaction/PhabricatorCalendarImportDeleteTransaction.php', 2108 2110 'PhabricatorCalendarImportDisableController' => 'applications/calendar/controller/PhabricatorCalendarImportDisableController.php', 2109 2111 'PhabricatorCalendarImportDisableTransaction' => 'applications/calendar/xaction/PhabricatorCalendarImportDisableTransaction.php', 2110 2112 'PhabricatorCalendarImportDuplicateLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportDuplicateLogType.php', ··· 6937 6939 'PhabricatorDestructibleInterface', 6938 6940 ), 6939 6941 'PhabricatorCalendarImportDefaultLogType' => 'PhabricatorCalendarImportLogType', 6942 + 'PhabricatorCalendarImportDeleteController' => 'PhabricatorCalendarController', 6943 + 'PhabricatorCalendarImportDeleteTransaction' => 'PhabricatorCalendarImportTransactionType', 6940 6944 'PhabricatorCalendarImportDisableController' => 'PhabricatorCalendarController', 6941 6945 'PhabricatorCalendarImportDisableTransaction' => 'PhabricatorCalendarImportTransactionType', 6942 6946 'PhabricatorCalendarImportDuplicateLogType' => 'PhabricatorCalendarImportLogType',
+2
src/applications/calendar/application/PhabricatorCalendarApplication.php
··· 83 83 => 'PhabricatorCalendarImportViewController', 84 84 'disable/(?P<id>[1-9]\d*)/' 85 85 => 'PhabricatorCalendarImportDisableController', 86 + 'delete/(?P<id>[1-9]\d*)/' 87 + => 'PhabricatorCalendarImportDeleteController', 86 88 'log/' => array( 87 89 $this->getQueryRoutePattern() 88 90 => 'PhabricatorCalendarImportLogListController',
+64
src/applications/calendar/controller/PhabricatorCalendarImportDeleteController.php
··· 1 + <?php 2 + 3 + final class PhabricatorCalendarImportDeleteController 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 + $engine = $import->getEngine(); 25 + if (!$engine->canDeleteAnyEvents($viewer, $import)) { 26 + return $this->newDialog() 27 + ->setTitle(pht('No Imported Events')) 28 + ->appendParagraph( 29 + pht( 30 + 'No events from this source currently exist. They may have '. 31 + 'failed to import, have been updated by another source, or '. 32 + 'already have been deleted.')) 33 + ->addCancelButton($import_uri, pht('Done')); 34 + } 35 + 36 + if ($request->isFormPost()) { 37 + $xactions = array(); 38 + $xactions[] = id(new PhabricatorCalendarImportTransaction()) 39 + ->setTransactionType( 40 + PhabricatorCalendarImportDeleteTransaction::TRANSACTIONTYPE) 41 + ->setNewValue(true); 42 + 43 + $editor = id(new PhabricatorCalendarImportEditor()) 44 + ->setActor($viewer) 45 + ->setContinueOnNoEffect(true) 46 + ->setContinueOnMissingFields(true) 47 + ->setContentSourceFromRequest($request); 48 + 49 + $editor->applyTransactions($import, $xactions); 50 + 51 + return id(new AphrontRedirectResponse())->setURI($import_uri); 52 + } 53 + 54 + return $this->newDialog() 55 + ->setTitle(pht('Delete Imported Events')) 56 + ->appendParagraph( 57 + pht( 58 + 'Delete all the events that were imported from this source? '. 59 + 'This action can not be undone.')) 60 + ->addCancelButton($import_uri) 61 + ->addSubmitButton(pht('Delete Events')); 62 + } 63 + 64 + }
+18
src/applications/calendar/controller/PhabricatorCalendarImportViewController.php
··· 123 123 ->setWorkflow(true) 124 124 ->setHref($disable_uri)); 125 125 126 + 127 + if ($can_edit) { 128 + $can_delete = $engine->canDeleteAnyEvents($viewer, $import); 129 + } else { 130 + $can_delete = false; 131 + } 132 + 133 + $delete_uri = "import/delete/{$id}/"; 134 + $delete_uri = $this->getApplicationURI($delete_uri); 135 + 136 + $curtain->addAction( 137 + id(new PhabricatorActionView()) 138 + ->setName(pht('Delete Imported Events')) 139 + ->setIcon('fa-times') 140 + ->setDisabled(!$can_delete) 141 + ->setWorkflow(true) 142 + ->setHref($delete_uri)); 143 + 126 144 return $curtain; 127 145 } 128 146
+13
src/applications/calendar/import/PhabricatorCalendarImportEngine.php
··· 398 398 return $event; 399 399 } 400 400 401 + public function canDeleteAnyEvents( 402 + PhabricatorUser $viewer, 403 + PhabricatorCalendarImport $import) { 404 + 405 + $any_event = id(new PhabricatorCalendarEventQuery()) 406 + ->setViewer($viewer) 407 + ->withImportSourcePHIDs(array($import->getPHID())) 408 + ->setLimit(1) 409 + ->execute(); 410 + 411 + return (bool)$any_event; 412 + } 413 + 401 414 }
+1 -1
src/applications/calendar/view/PhabricatorCalendarImportLogView.php
··· 60 60 pht('Source'), 61 61 null, 62 62 pht('Type'), 63 - pht('Mesage'), 63 + pht('Message'), 64 64 pht('Date'), 65 65 )) 66 66 ->setColumnVisibility(
+30
src/applications/calendar/xaction/PhabricatorCalendarImportDeleteTransaction.php
··· 1 + <?php 2 + 3 + final class PhabricatorCalendarImportDeleteTransaction 4 + extends PhabricatorCalendarImportTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'calendar.import.delete'; 7 + 8 + public function generateOldValue($object) { 9 + return false; 10 + } 11 + 12 + public function applyExternalEffects($object, $value) { 13 + $events = id(new PhabricatorCalendarEventQuery()) 14 + ->setViewer($this->getActor()) 15 + ->withImportSourcePHIDs(array($object->getPHID())) 16 + ->execute(); 17 + 18 + $engine = new PhabricatorDestructionEngine(); 19 + foreach ($events as $event) { 20 + $engine->destroyObject($event); 21 + } 22 + } 23 + 24 + public function getTitle() { 25 + return pht( 26 + '%s deleted imported events from this source.', 27 + $this->renderAuthor()); 28 + } 29 + 30 + }