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**')
|
2015-02-28 23:41:52 +01:00
|
|
|
->setSynopsis(pht('Generate some lipsum.'))
|
2013-04-12 23:07:15 +02:00
|
|
|
->setArguments(
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'name' => 'args',
|
|
|
|
'wildcard' => true,
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(PhutilArgumentParser $args) {
|
2015-02-28 23:41:52 +01:00
|
|
|
$console = PhutilConsole::getConsole();
|
|
|
|
|
2013-04-29 21:14:50 +02:00
|
|
|
$supported_types = id(new PhutilSymbolLoader())
|
|
|
|
->setAncestorClass('PhabricatorTestDataGenerator')
|
|
|
|
->loadObjects();
|
2015-02-28 23:41:52 +01:00
|
|
|
|
|
|
|
$console->writeOut(
|
|
|
|
"%s:\n\t%s\n",
|
|
|
|
pht('These are the types of data you can generate'),
|
|
|
|
implode("\n\t", array_keys($supported_types)));
|
|
|
|
|
|
|
|
$prompt = pht('Are you sure you want to generate lots of test data?');
|
|
|
|
if (!phutil_console_confirm($prompt, true)) {
|
2013-04-29 21:14:50 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-02-28 23:41:52 +01:00
|
|
|
|
2013-04-29 21:14:50 +02:00
|
|
|
$argv = $args->getArg('args');
|
2015-02-28 23:41:52 +01:00
|
|
|
if (count($argv) == 0 || (count($argv) == 1 && $argv[0] == 'all')) {
|
2013-04-29 21:14:50 +02:00
|
|
|
$this->infinitelyGenerate($supported_types);
|
|
|
|
} else {
|
|
|
|
$new_supported_types = array();
|
2015-02-28 23:41:52 +01:00
|
|
|
for ($i = 0; $i < count($argv); $i++) {
|
2013-04-29 21:14:50 +02:00
|
|
|
$arg = $argv[$i];
|
|
|
|
if (array_key_exists($arg, $supported_types)) {
|
2015-02-28 23:41:52 +01:00
|
|
|
$new_supported_types[$arg] = $supported_types[$arg];
|
2013-04-29 21:14:50 +02:00
|
|
|
} else {
|
2015-02-28 23:41:52 +01:00
|
|
|
$console->writeErr(
|
|
|
|
"%s\n",
|
|
|
|
pht(
|
|
|
|
'The type %s is not supported by the lipsum generator.',
|
|
|
|
$arg));
|
2013-04-29 21:14:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->infinitelyGenerate($new_supported_types);
|
|
|
|
}
|
2015-02-28 23:41:52 +01:00
|
|
|
|
|
|
|
$console->writeOut(
|
|
|
|
"%s\n%s:\n%s\n",
|
|
|
|
pht('None of the input types were supported.'),
|
|
|
|
pht('The supported types are'),
|
|
|
|
implode("\n", array_keys($supported_types)));
|
2013-04-29 21:14:50 +02:00
|
|
|
}
|
2013-04-25 03:17:30 +02:00
|
|
|
|
2013-04-29 21:14:50 +02:00
|
|
|
protected function infinitelyGenerate(array $supported_types) {
|
2015-02-28 23:41:52 +01:00
|
|
|
$console = PhutilConsole::getConsole();
|
|
|
|
|
2013-04-29 21:14:50 +02:00
|
|
|
if (count($supported_types) == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2015-02-28 23:41:52 +01:00
|
|
|
$console->writeOut(
|
|
|
|
"%s: %s\n",
|
|
|
|
pht('GENERATING'),
|
|
|
|
implode(', ', array_keys($supported_types)));
|
|
|
|
|
2013-04-29 21:14:50 +02:00
|
|
|
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();
|
2015-02-28 23:41:52 +01:00
|
|
|
|
|
|
|
$console->writeOut(
|
|
|
|
"%s: %s\n",
|
|
|
|
pht('Generated %s', $handle->getTypeName()),
|
|
|
|
$handle->getFullName());
|
2014-03-08 20:43:50 +01:00
|
|
|
|
2013-04-29 21:14:50 +02:00
|
|
|
usleep(200000);
|
|
|
|
}
|
2013-04-12 23:07:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|