mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-25 08:12:40 +01:00
b902005bed
Summary: Ref T603. Killing this class is cool because the classes that replace it are policy-aware. Tried to keep my wits about me as I did this and fixed a few random things along the way. (Ones I remember right now are pulling a query outside of a foreach loop in Releeph and fixing the text in UIExample to note that the ace of hearts if "a powerful" card and not the "most powerful" card (Q of spades gets that honor IMO)) Test Plan: tested the first few changes (execute, executeOne X handle, object) then got real mechanical / careful with the other changes. Reviewers: epriestley Reviewed By: epriestley CC: Korvin, aran, FacebookPOC Maniphest Tasks: T603 Differential Revision: https://secure.phabricator.com/D6941
83 lines
2.6 KiB
PHP
83 lines
2.6 KiB
PHP
<?php
|
|
|
|
final class PhabricatorLipsumGenerateWorkflow
|
|
extends PhabricatorLipsumManagementWorkflow {
|
|
|
|
protected function didConstruct() {
|
|
$this
|
|
->setName('generate')
|
|
->setExamples('**generate** __key__')
|
|
->setSynopsis('Generate some lipsum.')
|
|
->setArguments(
|
|
array(
|
|
array(
|
|
'name' => 'args',
|
|
'wildcard' => true,
|
|
),
|
|
));
|
|
}
|
|
|
|
public function execute(PhutilArgumentParser $args) {
|
|
$supported_types = id(new PhutilSymbolLoader())
|
|
->setAncestorClass('PhabricatorTestDataGenerator')
|
|
->loadObjects();
|
|
echo "These are the types of data you can generate:\n";
|
|
foreach (array_keys($supported_types) as $typetmp) {
|
|
echo "\t".$typetmp."\n";
|
|
}
|
|
echo "\n";
|
|
$prompt = "Are you sure you want to generate lots of test data?";
|
|
if (!phutil_console_confirm($prompt, $default_no = true)) {
|
|
return;
|
|
}
|
|
$argv = $args->getArg('args');
|
|
if (count($argv) == 0 ||
|
|
(count($argv) == 1 && $argv[0] == "all")) {
|
|
$this->infinitelyGenerate($supported_types);
|
|
} else {
|
|
$new_supported_types = array();
|
|
for ($i = 0; $i < count($argv);$i++) {
|
|
$arg = $argv[$i];
|
|
if (array_key_exists($arg, $supported_types)) {
|
|
$new_supported_types[$arg] = $supported_types[$arg];
|
|
} else {
|
|
echo "The type ".$arg." is not supported by the lipsum generator.\n";
|
|
}
|
|
}
|
|
$this->infinitelyGenerate($new_supported_types);
|
|
}
|
|
echo "None of the input types were supported.\n";
|
|
echo "The supported types are:\n";
|
|
echo implode("\n", array_keys($supported_types));
|
|
}
|
|
|
|
protected function infinitelyGenerate(array $supported_types) {
|
|
if (count($supported_types) == 0) {
|
|
echo "None of the input types were supported.\n";
|
|
return;
|
|
}
|
|
echo "GENERATING: ";
|
|
echo strtoupper(implode(" , ", array_keys($supported_types)));
|
|
echo "\n";
|
|
while (true) {
|
|
$type = $supported_types[array_rand($supported_types)];
|
|
$admin = PhabricatorUser::getOmnipotentUser();
|
|
try {
|
|
$taskgen = newv($type, array());
|
|
$object = $taskgen->generate();
|
|
$handle = id(new PhabricatorHandleQuery())
|
|
->setViewer($admin)
|
|
->withPHIDs(array($object->getPHID()))
|
|
->executeOne();
|
|
echo "Generated ".$handle->getTypeName().": ".
|
|
$handle->getFullName()."\n";
|
|
} catch (PhutilMissingSymbolException $ex) {
|
|
throw new PhutilArgumentUsageException(
|
|
"Cannot generate content of type ".$type.
|
|
" because the class does not exist.");
|
|
}
|
|
usleep(200000);
|
|
}
|
|
}
|
|
|
|
}
|