1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 06:42:42 +01:00

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
This commit is contained in:
epriestley 2017-08-01 08:48:39 -07:00
parent 03423c632c
commit ab018e1b49
7 changed files with 160 additions and 2 deletions

View file

@ -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',

View file

@ -0,0 +1,23 @@
<?php
final class PhabricatorRepositoryDestructibleCodex
extends PhabricatorDestructibleCodex {
public function getDestructionNotes() {
$repository = $this->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;
}
}

View file

@ -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 )----------------------------------------- */

View file

@ -0,0 +1,66 @@
<?php
abstract class PhabricatorDestructibleCodex
extends Phobject {
private $viewer;
private $object;
public function getDestructionNotes() {
return array();
}
final public function setViewer(PhabricatorUser $viewer) {
$this->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;
}
}

View file

@ -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) {

View file

@ -0,0 +1,18 @@
<?php
interface PhabricatorDestructibleCodexInterface {
public function newDestructibleCodex();
}
// TEMPLATE IMPLEMENTATION /////////////////////////////////////////////////////
/* -( PhabricatorDestructibleCodexInterface )------------------------------ */
/*
public function newDestructibleCodex() {
return new <<...>>DestructibleCodex();
}
*/

View file

@ -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;
}