Differential D14463 Diff 35378 src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDestroyWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDestroyWorkflow.php
| Show All 14 Lines | $this | ||||
| 'help' => pht( | 'help' => pht( | ||||
| 'Restrict **destroy** operations to databases created '. | 'Restrict **destroy** operations to databases created '. | ||||
| 'by %s test fixtures.', | 'by %s test fixtures.', | ||||
| 'PhabricatorTestCase'), | 'PhabricatorTestCase'), | ||||
| ), | ), | ||||
| )); | )); | ||||
| } | } | ||||
| public function execute(PhutilArgumentParser $args) { | public function didExecute(PhutilArgumentParser $args) { | ||||
| $is_dry = $args->getArg('dryrun'); | $console = PhutilConsole::getConsole(); | ||||
| $is_force = $args->getArg('force'); | |||||
| if (!$is_dry && !$is_force) { | if (!$this->isDryRun() && !$this->isForce()) { | ||||
| echo phutil_console_wrap( | $console->writeOut( | ||||
| phutil_console_wrap( | |||||
| pht( | pht( | ||||
| 'Are you completely sure you really want to permanently destroy all '. | 'Are you completely sure you really want to permanently destroy '. | ||||
| 'storage for Phabricator data? This operation can not be undone and '. | 'all storage for Phabricator data? This operation can not be '. | ||||
| 'your data will not be recoverable if you proceed.')); | 'undone and your data will not be recoverable if you proceed.'))); | ||||
| if (!phutil_console_confirm(pht('Permanently destroy all data?'))) { | if (!phutil_console_confirm(pht('Permanently destroy all data?'))) { | ||||
| echo pht('Cancelled.')."\n"; | $console->writeOut("%s\n", pht('Cancelled.')); | ||||
| exit(1); | exit(1); | ||||
| } | } | ||||
| if (!phutil_console_confirm(pht('Really destroy all data forever?'))) { | if (!phutil_console_confirm(pht('Really destroy all data forever?'))) { | ||||
| echo pht('Cancelled.')."\n"; | $console->writeOut("%s\n", pht('Cancelled.')); | ||||
| exit(1); | exit(1); | ||||
| } | } | ||||
| } | } | ||||
| $api = $this->getAPI(); | $api = $this->getAPI(); | ||||
| $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'); | ||||
| } | } | ||||
| foreach ($databases as $database) { | foreach ($databases as $database) { | ||||
| if ($is_dry) { | if ($this->isDryRun()) { | ||||
| echo pht("DRYRUN: Would drop database '%s'.", $database)."\n"; | $console->writeOut( | ||||
| "%s\n", | |||||
| pht("DRYRUN: Would drop database '%s'.", $database)); | |||||
| } else { | } else { | ||||
| echo pht("Dropping database '%s'...", $database)."\n"; | $console->writeOut( | ||||
| "%s\n", | |||||
| pht("Dropping database '%s'...", $database)); | |||||
| queryfx( | queryfx( | ||||
| $api->getConn(null), | $api->getConn(null), | ||||
| 'DROP DATABASE IF EXISTS %T', | 'DROP DATABASE IF EXISTS %T', | ||||
| $database); | $database); | ||||
| } | } | ||||
| } | } | ||||
| if (!$is_dry) { | if (!$this->isDryRun()) { | ||||
| echo pht('Storage was destroyed.')."\n"; | $console->writeOut("%s\n", pht('Storage was destroyed.')); | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| } | } | ||||