2013-04-12 23:07:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorLipsumGenerateWorkflow
|
|
|
|
extends PhabricatorLipsumManagementWorkflow {
|
|
|
|
|
|
|
|
protected function didConstruct() {
|
|
|
|
$this
|
|
|
|
->setName('generate')
|
2013-04-29 21:14:50 +02:00
|
|
|
->setExamples('**generate** __key__')
|
2013-04-15 04:09:20 +02:00
|
|
|
->setSynopsis('Generate some lipsum.')
|
2013-04-12 23:07:15 +02:00
|
|
|
->setArguments(
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'name' => 'args',
|
|
|
|
'wildcard' => true,
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(PhutilArgumentParser $args) {
|
2013-04-29 21:14:50 +02:00
|
|
|
$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";
|
2013-04-29 21:10:53 +02:00
|
|
|
}
|
2013-04-29 21:14:50 +02:00
|
|
|
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));
|
|
|
|
}
|
2013-04-25 03:17:30 +02:00
|
|
|
|
2013-04-29 21:14:50 +02:00
|
|
|
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)];
|
2013-12-27 22:15:40 +01:00
|
|
|
$admin = $this->getViewer();
|
2013-04-29 21:14:50 +02:00
|
|
|
try {
|
|
|
|
$taskgen = newv($type, array());
|
|
|
|
$object = $taskgen->generate();
|
2013-09-11 21:27:28 +02:00
|
|
|
$handle = id(new PhabricatorHandleQuery())
|
|
|
|
->setViewer($admin)
|
|
|
|
->withPHIDs(array($object->getPHID()))
|
|
|
|
->executeOne();
|
2013-04-29 21:14:50 +02:00
|
|
|
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);
|
|
|
|
}
|
2013-04-12 23:07:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|