From ab018e1b49d52025c69aa359061fd3f34f417eda Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 1 Aug 2017 08:48:39 -0700 Subject: [PATCH] When destorying a repository, print a notification about removing the working copy Summary: Fixes T12946. `bin/remove destroy` does not remove working copies: it's more dangerous than usual, and we can't do it in the general (clustered) case. Print a notification message after destroying a repository. Test Plan: - Destroyed a repository, got a hint about the working copy. - Destroyed a task, things worked normally. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12946 Differential Revision: https://secure.phabricator.com/D18313 --- src/__phutil_library_map__.php | 6 ++ ...PhabricatorRepositoryDestructibleCodex.php | 23 +++++++ .../storage/PhabricatorRepository.php | 9 +++ .../codex/PhabricatorDestructibleCodex.php | 66 +++++++++++++++++++ .../engine/PhabricatorDestructionEngine.php | 23 +++++++ .../PhabricatorDestructibleCodexInterface.php | 18 +++++ ...PhabricatorSystemRemoveDestroyWorkflow.php | 17 ++++- 7 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 src/applications/repository/codex/PhabricatorRepositoryDestructibleCodex.php create mode 100644 src/applications/system/codex/PhabricatorDestructibleCodex.php create mode 100644 src/applications/system/interface/PhabricatorDestructibleCodexInterface.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 6427e95432..afaccaacf9 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2642,6 +2642,8 @@ phutil_register_library_map(array( 'PhabricatorDefaultSyntaxStyle' => 'infrastructure/syntax/PhabricatorDefaultSyntaxStyle.php', 'PhabricatorDesktopNotificationsSetting' => 'applications/settings/setting/PhabricatorDesktopNotificationsSetting.php', 'PhabricatorDesktopNotificationsSettingsPanel' => 'applications/settings/panel/PhabricatorDesktopNotificationsSettingsPanel.php', + 'PhabricatorDestructibleCodex' => 'applications/system/codex/PhabricatorDestructibleCodex.php', + 'PhabricatorDestructibleCodexInterface' => 'applications/system/interface/PhabricatorDestructibleCodexInterface.php', 'PhabricatorDestructibleInterface' => 'applications/system/interface/PhabricatorDestructibleInterface.php', 'PhabricatorDestructionEngine' => 'applications/system/engine/PhabricatorDestructionEngine.php', 'PhabricatorDestructionEngineExtension' => 'applications/system/engine/PhabricatorDestructionEngineExtension.php', @@ -3780,6 +3782,7 @@ phutil_register_library_map(array( 'PhabricatorRepositoryCommitTestCase' => 'applications/repository/storage/__tests__/PhabricatorRepositoryCommitTestCase.php', 'PhabricatorRepositoryConfigOptions' => 'applications/repository/config/PhabricatorRepositoryConfigOptions.php', 'PhabricatorRepositoryDAO' => 'applications/repository/storage/PhabricatorRepositoryDAO.php', + 'PhabricatorRepositoryDestructibleCodex' => 'applications/repository/codex/PhabricatorRepositoryDestructibleCodex.php', 'PhabricatorRepositoryDiscoveryEngine' => 'applications/repository/engine/PhabricatorRepositoryDiscoveryEngine.php', 'PhabricatorRepositoryEditor' => 'applications/repository/editor/PhabricatorRepositoryEditor.php', 'PhabricatorRepositoryEngine' => 'applications/repository/engine/PhabricatorRepositoryEngine.php', @@ -7937,6 +7940,7 @@ phutil_register_library_map(array( 'PhabricatorDefaultSyntaxStyle' => 'PhabricatorSyntaxStyle', 'PhabricatorDesktopNotificationsSetting' => 'PhabricatorInternalSetting', 'PhabricatorDesktopNotificationsSettingsPanel' => 'PhabricatorSettingsPanel', + 'PhabricatorDestructibleCodex' => 'Phobject', 'PhabricatorDestructionEngine' => 'Phobject', 'PhabricatorDestructionEngineExtension' => 'Phobject', 'PhabricatorDestructionEngineExtensionModule' => 'PhabricatorConfigModule', @@ -9241,6 +9245,7 @@ phutil_register_library_map(array( 'PhabricatorFlaggableInterface', 'PhabricatorMarkupInterface', 'PhabricatorDestructibleInterface', + 'PhabricatorDestructibleCodexInterface', 'PhabricatorProjectInterface', 'PhabricatorSpacesInterface', 'PhabricatorConduitResultInterface', @@ -9283,6 +9288,7 @@ phutil_register_library_map(array( 'PhabricatorRepositoryCommitTestCase' => 'PhabricatorTestCase', 'PhabricatorRepositoryConfigOptions' => 'PhabricatorApplicationConfigOptions', 'PhabricatorRepositoryDAO' => 'PhabricatorLiskDAO', + 'PhabricatorRepositoryDestructibleCodex' => 'PhabricatorDestructibleCodex', 'PhabricatorRepositoryDiscoveryEngine' => 'PhabricatorRepositoryEngine', 'PhabricatorRepositoryEditor' => 'PhabricatorApplicationTransactionEditor', 'PhabricatorRepositoryEngine' => 'Phobject', diff --git a/src/applications/repository/codex/PhabricatorRepositoryDestructibleCodex.php b/src/applications/repository/codex/PhabricatorRepositoryDestructibleCodex.php new file mode 100644 index 0000000000..eaa5cf4a77 --- /dev/null +++ b/src/applications/repository/codex/PhabricatorRepositoryDestructibleCodex.php @@ -0,0 +1,23 @@ +getObject(); + + $notes = array(); + + if ($repository->hasLocalWorkingCopy()) { + $notes[] = pht( + 'Database records for repository "%s" were destroyed, but this '. + 'script does not remove working copies on disk. If you also want to '. + 'destroy the repository working copy, manually remove "%s".', + $repository->getDisplayName(), + $repository->getLocalPath()); + } + + return $notes; + } + +} diff --git a/src/applications/repository/storage/PhabricatorRepository.php b/src/applications/repository/storage/PhabricatorRepository.php index eb6608eb57..b660ff9aa7 100644 --- a/src/applications/repository/storage/PhabricatorRepository.php +++ b/src/applications/repository/storage/PhabricatorRepository.php @@ -12,6 +12,7 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO PhabricatorFlaggableInterface, PhabricatorMarkupInterface, PhabricatorDestructibleInterface, + PhabricatorDestructibleCodexInterface, PhabricatorProjectInterface, PhabricatorSpacesInterface, PhabricatorConduitResultInterface, @@ -2557,6 +2558,14 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO } +/* -( PhabricatorDestructibleCodexInterface )------------------------------ */ + + + public function newDestructibleCodex() { + return new PhabricatorRepositoryDestructibleCodex(); + } + + /* -( PhabricatorSpacesInterface )----------------------------------------- */ diff --git a/src/applications/system/codex/PhabricatorDestructibleCodex.php b/src/applications/system/codex/PhabricatorDestructibleCodex.php new file mode 100644 index 0000000000..1c37907c34 --- /dev/null +++ b/src/applications/system/codex/PhabricatorDestructibleCodex.php @@ -0,0 +1,66 @@ +viewer = $viewer; + return $this; + } + + final public function getViewer() { + return $this->viewer; + } + + final public function setObject( + PhabricatorDestructibleCodexInterface $object) { + $this->object = $object; + return $this; + } + + final public function getObject() { + return $this->object; + } + + final public static function newFromObject( + PhabricatorDestructibleCodexInterface $object, + PhabricatorUser $viewer) { + + if (!($object instanceof PhabricatorDestructibleInterface)) { + throw new Exception( + pht( + 'Object (of class "%s") implements interface "%s", but must also '. + 'implement interface "%s".', + get_class($object), + 'PhabricatorDestructibleCodexInterface', + 'PhabricatorDestructibleInterface')); + } + + $codex = $object->newDestructibleCodex(); + if (!($codex instanceof PhabricatorDestructibleCodex)) { + throw new Exception( + pht( + 'Object (of class "%s") implements interface "%s", but defines '. + 'method "%s" incorrectly: this method must return an object of '. + 'class "%s".', + get_class($object), + 'PhabricatorDestructibleCodexInterface', + 'newDestructibleCodex()', + __CLASS__)); + } + + $codex + ->setObject($object) + ->setViewer($viewer); + + return $codex; + } + +} diff --git a/src/applications/system/engine/PhabricatorDestructionEngine.php b/src/applications/system/engine/PhabricatorDestructionEngine.php index f8e5be2ccc..336df57756 100644 --- a/src/applications/system/engine/PhabricatorDestructionEngine.php +++ b/src/applications/system/engine/PhabricatorDestructionEngine.php @@ -3,6 +3,17 @@ final class PhabricatorDestructionEngine extends Phobject { private $rootLogID; + private $collectNotes; + private $notes = array(); + + public function setCollectNotes($collect_notes) { + $this->collectNotes = $collect_notes; + return $this; + } + + public function getNotes() { + return $this->notes; + } public function getViewer() { return PhabricatorUser::getOmnipotentUser(); @@ -36,6 +47,18 @@ final class PhabricatorDestructionEngine extends Phobject { $this->rootLogID = $log->getID(); } + if ($this->collectNotes) { + if ($object instanceof PhabricatorDestructibleCodexInterface) { + $codex = PhabricatorDestructibleCodex::newFromObject( + $object, + $this->getViewer()); + + foreach ($codex->getDestructionNotes() as $note) { + $this->notes[] = $note; + } + } + } + $object->destroyObjectPermanently($this); if ($object_phid) { diff --git a/src/applications/system/interface/PhabricatorDestructibleCodexInterface.php b/src/applications/system/interface/PhabricatorDestructibleCodexInterface.php new file mode 100644 index 0000000000..3725990ee6 --- /dev/null +++ b/src/applications/system/interface/PhabricatorDestructibleCodexInterface.php @@ -0,0 +1,18 @@ +>DestructibleCodex(); + } + +*/ diff --git a/src/applications/system/management/PhabricatorSystemRemoveDestroyWorkflow.php b/src/applications/system/management/PhabricatorSystemRemoveDestroyWorkflow.php index 4e9d745540..bd6b4e361a 100644 --- a/src/applications/system/management/PhabricatorSystemRemoveDestroyWorkflow.php +++ b/src/applications/system/management/PhabricatorSystemRemoveDestroyWorkflow.php @@ -145,6 +145,7 @@ EOBANNER; $console->writeOut("%s\n", pht('Destroying objects...')); + $notes = array(); foreach ($named_objects as $object_name => $object) { $console->writeOut( pht( @@ -152,8 +153,14 @@ EOBANNER; get_class($object), $object_name)); - id(new PhabricatorDestructionEngine()) - ->destroyObject($object); + $engine = id(new PhabricatorDestructionEngine()) + ->setCollectNotes(true); + + $engine->destroyObject($object); + + foreach ($engine->getNotes() as $note) { + $notes[] = $note; + } } $console->writeOut( @@ -162,6 +169,12 @@ EOBANNER; 'Permanently destroyed %s object(s).', phutil_count($named_objects))); + if ($notes) { + id(new PhutilConsoleList()) + ->addItems($notes) + ->draw(); + } + return 0; }