Differential D20784 Diff 49558 src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDestroyWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDestroyWorkflow.php
Show All 15 Lines | $this | ||||
'Restrict **destroy** operations to databases created '. | 'Restrict **destroy** operations to databases created '. | ||||
'by %s test fixtures.', | 'by %s test fixtures.', | ||||
'PhabricatorTestCase'), | 'PhabricatorTestCase'), | ||||
), | ), | ||||
)); | )); | ||||
} | } | ||||
public function didExecute(PhutilArgumentParser $args) { | public function didExecute(PhutilArgumentParser $args) { | ||||
$console = PhutilConsole::getConsole(); | $api = $this->getSingleAPI(); | ||||
$host_display = $api->getDisplayName(); | |||||
if (!$this->isDryRun() && !$this->isForce()) { | if (!$this->isDryRun() && !$this->isForce()) { | ||||
if ($args->getArg('unittest-fixtures')) { | if ($args->getArg('unittest-fixtures')) { | ||||
$console->writeOut( | $warning = pht( | ||||
phutil_console_wrap( | |||||
pht( | |||||
'Are you completely sure you really want to destroy all unit '. | 'Are you completely sure you really want to destroy all unit '. | ||||
'test fixure data? This operation can not be undone.'))); | 'test fixure data on host "%s"? This operation can not be undone.', | ||||
$host_display); | |||||
echo tsprintf( | |||||
'%B', | |||||
id(new PhutilConsoleBlock()) | |||||
->addParagraph($warning) | |||||
->drawConsoleString()); | |||||
if (!phutil_console_confirm(pht('Destroy all unit test data?'))) { | if (!phutil_console_confirm(pht('Destroy all unit test data?'))) { | ||||
$console->writeOut("%s\n", pht('Cancelled.')); | $this->logFail( | ||||
pht('CANCELLED'), | |||||
pht('User cancelled operation.')); | |||||
exit(1); | exit(1); | ||||
} | } | ||||
} else { | } else { | ||||
$console->writeOut( | $warning = pht( | ||||
phutil_console_wrap( | |||||
pht( | |||||
'Are you completely sure you really want to permanently destroy '. | 'Are you completely sure you really want to permanently destroy '. | ||||
'all storage for Phabricator data? This operation can not be '. | 'all storage for Phabricator data on host "%s"? This operation '. | ||||
'undone and your data will not be recoverable if you proceed.'))); | 'can not be undone and your data will not be recoverable if '. | ||||
'you proceed.', | |||||
$host_display); | |||||
echo tsprintf( | |||||
'%B', | |||||
id(new PhutilConsoleBlock()) | |||||
->addParagraph($warning) | |||||
->drawConsoleString()); | |||||
if (!phutil_console_confirm(pht('Permanently destroy all data?'))) { | if (!phutil_console_confirm(pht('Permanently destroy all data?'))) { | ||||
$console->writeOut("%s\n", pht('Cancelled.')); | $this->logFail( | ||||
pht('CANCELLED'), | |||||
pht('User cancelled operation.')); | |||||
exit(1); | exit(1); | ||||
} | } | ||||
if (!phutil_console_confirm(pht('Really destroy all data forever?'))) { | if (!phutil_console_confirm(pht('Really destroy all data forever?'))) { | ||||
$console->writeOut("%s\n", pht('Cancelled.')); | $this->logFail( | ||||
pht('CANCELLED'), | |||||
pht('User cancelled operation.')); | |||||
exit(1); | exit(1); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
$apis = $this->getMasterAPIs(); | |||||
foreach ($apis as $api) { | |||||
$patches = $this->getPatches(); | $patches = $this->getPatches(); | ||||
if ($args->getArg('unittest-fixtures')) { | if ($args->getArg('unittest-fixtures')) { | ||||
$conn = $api->getConn(null); | $conn = $api->getConn(null); | ||||
$databases = queryfx_all( | $databases = queryfx_all( | ||||
$conn, | $conn, | ||||
'SELECT DISTINCT(TABLE_SCHEMA) AS db '. | 'SELECT DISTINCT(TABLE_SCHEMA) AS db '. | ||||
'FROM INFORMATION_SCHEMA.TABLES '. | 'FROM INFORMATION_SCHEMA.TABLES '. | ||||
'WHERE TABLE_SCHEMA LIKE %>', | 'WHERE TABLE_SCHEMA LIKE %>', | ||||
PhabricatorTestCase::NAMESPACE_PREFIX); | PhabricatorTestCase::NAMESPACE_PREFIX); | ||||
$databases = ipull($databases, 'db'); | $databases = ipull($databases, 'db'); | ||||
} else { | } else { | ||||
$databases = $api->getDatabaseList($patches); | $databases = $api->getDatabaseList($patches); | ||||
$databases[] = $api->getDatabaseName('meta_data'); | $databases[] = $api->getDatabaseName('meta_data'); | ||||
// These are legacy databases that were dropped long ago. See T2237. | // These are legacy databases that were dropped long ago. See T2237. | ||||
$databases[] = $api->getDatabaseName('phid'); | $databases[] = $api->getDatabaseName('phid'); | ||||
$databases[] = $api->getDatabaseName('directory'); | $databases[] = $api->getDatabaseName('directory'); | ||||
} | } | ||||
asort($databases); | |||||
foreach ($databases as $database) { | foreach ($databases as $database) { | ||||
if ($this->isDryRun()) { | if ($this->isDryRun()) { | ||||
$console->writeOut( | $this->logInfo( | ||||
"%s\n", | pht('DRY RUN'), | ||||
pht("DRYRUN: Would drop database '%s'.", $database)); | pht( | ||||
'Would drop database "%s" on host "%s".', | |||||
$database, | |||||
$host_display)); | |||||
} else { | } else { | ||||
$console->writeOut( | $this->logWarn( | ||||
"%s\n", | pht('DESTROY'), | ||||
pht("Dropping database '%s'...", $database)); | pht( | ||||
'Dropping database "%s" on host "%s"...', | |||||
$database, | |||||
$host_display)); | |||||
queryfx( | queryfx( | ||||
$api->getConn(null), | $api->getConn(null), | ||||
'DROP DATABASE IF EXISTS %T', | 'DROP DATABASE IF EXISTS %T', | ||||
$database); | $database); | ||||
} | } | ||||
} | } | ||||
if (!$this->isDryRun()) { | if (!$this->isDryRun()) { | ||||
$console->writeOut( | $this->logOkay( | ||||
"%s\n", | pht('DONE'), | ||||
pht( | pht( | ||||
'Storage on "%s" was destroyed.', | 'Storage on "%s" was destroyed.', | ||||
$api->getRef()->getRefKey())); | $host_display)); | ||||
} | |||||
} | } | ||||
return 0; | return 0; | ||||
} | } | ||||
} | } |