Differential D21745 Diff 51841 src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDumpWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDumpWorkflow.php
Show All 38 Lines | $this | ||||
'rebuild indexes after performing a restore.'), | 'rebuild indexes after performing a restore.'), | ||||
), | ), | ||||
array( | array( | ||||
'name' => 'overwrite', | 'name' => 'overwrite', | ||||
'help' => pht( | 'help' => pht( | ||||
'With __--output__, overwrite the output file if it already '. | 'With __--output__, overwrite the output file if it already '. | ||||
'exists.'), | 'exists.'), | ||||
), | ), | ||||
array( | |||||
'name' => 'database', | |||||
'param' => 'database-name', | |||||
'help' => pht( | |||||
'Dump only tables in the named database (or databases, if '. | |||||
'the flag is repeated). Specify database names without the '. | |||||
'namespace prefix (that is: use "differential", not '. | |||||
'"phabricator_differential").'), | |||||
'repeat' => true, | |||||
), | |||||
)); | )); | ||||
} | } | ||||
protected function isReadOnlyWorkflow() { | protected function isReadOnlyWorkflow() { | ||||
return true; | return true; | ||||
} | } | ||||
public function didExecute(PhutilArgumentParser $args) { | public function didExecute(PhutilArgumentParser $args) { | ||||
$output_file = $args->getArg('output'); | $output_file = $args->getArg('output'); | ||||
$is_compress = $args->getArg('compress'); | $is_compress = $args->getArg('compress'); | ||||
$is_overwrite = $args->getArg('overwrite'); | $is_overwrite = $args->getArg('overwrite'); | ||||
$is_noindex = $args->getArg('no-indexes'); | $is_noindex = $args->getArg('no-indexes'); | ||||
$is_replica = $args->getArg('for-replica'); | $is_replica = $args->getArg('for-replica'); | ||||
$database_filter = $args->getArg('database'); | |||||
if ($is_compress) { | if ($is_compress) { | ||||
if ($output_file === null) { | if ($output_file === null) { | ||||
throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
pht( | pht( | ||||
'The "--compress" flag can only be used alongside "--output".')); | 'The "--compress" flag can only be used alongside "--output".')); | ||||
} | } | ||||
if (!function_exists('gzopen')) { | if (!function_exists('gzopen')) { | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | $schemata_query = id(new PhabricatorConfigSchemaQuery()) | ||||
->setRefs(array($ref)); | ->setRefs(array($ref)); | ||||
$actual_map = $schemata_query->loadActualSchemata(); | $actual_map = $schemata_query->loadActualSchemata(); | ||||
$expect_map = $schemata_query->loadExpectedSchemata(); | $expect_map = $schemata_query->loadExpectedSchemata(); | ||||
$schemata = $actual_map[$ref_key]; | $schemata = $actual_map[$ref_key]; | ||||
$expect = $expect_map[$ref_key]; | $expect = $expect_map[$ref_key]; | ||||
if ($database_filter) { | |||||
$internal_names = array(); | |||||
$expect_databases = $expect->getDatabases(); | |||||
foreach ($expect_databases as $expect_database) { | |||||
$database_name = $expect_database->getName(); | |||||
$internal_name = $api->getInternalDatabaseName($database_name); | |||||
if ($internal_name !== null) { | |||||
$internal_names[$internal_name] = $database_name; | |||||
} | |||||
} | |||||
ksort($internal_names); | |||||
$seen = array(); | |||||
foreach ($database_filter as $filter) { | |||||
if (!isset($internal_names[$filter])) { | |||||
throw new PhutilArgumentUsageException( | |||||
pht( | |||||
'Database "%s" is unknown. This script can only dump '. | |||||
'databases known to the current version of Phabricator. '. | |||||
'Valid databases are: %s.', | |||||
$filter, | |||||
implode(', ', array_keys($internal_names)))); | |||||
} | |||||
if (isset($seen[$filter])) { | |||||
throw new PhutilArgumentUsageException( | |||||
pht( | |||||
'Database "%s" is specified more than once. Specify each '. | |||||
'database at most once.', | |||||
$filter)); | |||||
} | |||||
$seen[$filter] = true; | |||||
} | |||||
$dump_databases = array_select_keys($internal_names, $database_filter); | |||||
$dump_databases = array_fuse($dump_databases); | |||||
} else { | |||||
$dump_databases = array_keys($schemata->getDatabases()); | |||||
$dump_databases = array_fuse($dump_databases); | |||||
} | |||||
$with_caches = $is_replica; | $with_caches = $is_replica; | ||||
$with_indexes = !$is_noindex; | $with_indexes = !$is_noindex; | ||||
$targets = array(); | $targets = array(); | ||||
foreach ($schemata->getDatabases() as $database_name => $database) { | foreach ($schemata->getDatabases() as $database_name => $database) { | ||||
if (!isset($dump_databases[$database_name])) { | |||||
continue; | |||||
} | |||||
$expect_database = $expect->getDatabase($database_name); | $expect_database = $expect->getDatabase($database_name); | ||||
foreach ($database->getTables() as $table_name => $table) { | foreach ($database->getTables() as $table_name => $table) { | ||||
// NOTE: It's possible for us to find tables in these database which | // NOTE: It's possible for us to find tables in these database which | ||||
// we don't expect to be there. For example, an older version of | // we don't expect to be there. For example, an older version of | ||||
// Phabricator may have had a table that was later dropped. We assume | // Phabricator may have had a table that was later dropped. We assume | ||||
// these are data tables and always dump them, erring on the side of | // these are data tables and always dump them, erring on the side of | ||||
// caution. | // caution. | ||||
▲ Show 20 Lines • Show All 236 Lines • Show Last 20 Lines |