2013-04-12 23:07:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorLipsumGenerateWorkflow
|
|
|
|
extends PhabricatorLipsumManagementWorkflow {
|
|
|
|
|
|
|
|
protected function didConstruct() {
|
|
|
|
$this
|
|
|
|
->setName('generate')
|
2014-03-08 20:43:50 +01:00
|
|
|
->setExamples('**generate**')
|
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";
|
2014-06-09 20:36:49 +02:00
|
|
|
$prompt = 'Are you sure you want to generate lots of test data?';
|
2013-04-29 21:14:50 +02:00
|
|
|
if (!phutil_console_confirm($prompt, $default_no = true)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$argv = $args->getArg('args');
|
|
|
|
if (count($argv) == 0 ||
|
2014-06-09 20:36:49 +02:00
|
|
|
(count($argv) == 1 && $argv[0] == 'all')) {
|
2013-04-29 21:14:50 +02:00
|
|
|
$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;
|
|
|
|
}
|
2014-06-09 20:36:49 +02:00
|
|
|
echo 'GENERATING: ';
|
|
|
|
echo strtoupper(implode(' , ', array_keys($supported_types)));
|
2013-04-29 21:14:50 +02:00
|
|
|
echo "\n";
|
|
|
|
while (true) {
|
|
|
|
$type = $supported_types[array_rand($supported_types)];
|
2013-12-27 22:15:40 +01:00
|
|
|
$admin = $this->getViewer();
|
2014-03-08 20:43:50 +01:00
|
|
|
|
|
|
|
$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";
|
|
|
|
|
2013-04-29 21:14:50 +02:00
|
|
|
usleep(200000);
|
|
|
|
}
|
2013-04-12 23:07:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|