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-12-24 13:49:25 +01:00
|
|
|
->setSynopsis(pht('Generate synthetic test objects.'))
|
2013-04-12 23:07:15 +02:00
|
|
|
->setArguments(
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'name' => 'args',
|
|
|
|
'wildcard' => true,
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(PhutilArgumentParser $args) {
|
2015-12-24 13:49:25 +01:00
|
|
|
$config_key = 'phabricator.developer-mode';
|
|
|
|
if (!PhabricatorEnv::getEnvConfig($config_key)) {
|
|
|
|
throw new PhutilArgumentUsageException(
|
|
|
|
pht(
|
|
|
|
'lipsum is a development and testing tool and may only be run '.
|
|
|
|
'on installs in developer mode. Enable "%s" in your configuration '.
|
|
|
|
'to enable lipsum.',
|
|
|
|
$config_key));
|
|
|
|
}
|
2015-02-28 23:41:52 +01:00
|
|
|
|
2015-12-24 13:49:25 +01:00
|
|
|
$all_generators = id(new PhutilClassMapQuery())
|
2013-04-29 21:14:50 +02:00
|
|
|
->setAncestorClass('PhabricatorTestDataGenerator')
|
2015-08-13 23:49:00 +02:00
|
|
|
->execute();
|
2015-02-28 23:41:52 +01:00
|
|
|
|
2015-12-24 13:49:25 +01:00
|
|
|
$argv = $args->getArg('args');
|
|
|
|
$all = 'all';
|
2015-02-28 23:41:52 +01:00
|
|
|
|
2015-12-24 13:49:25 +01:00
|
|
|
if (!$argv) {
|
|
|
|
$names = mpull($all_generators, 'getGeneratorName');
|
|
|
|
sort($names);
|
|
|
|
|
|
|
|
$list = id(new PhutilConsoleList())
|
|
|
|
->setWrap(false)
|
|
|
|
->addItems($names);
|
|
|
|
|
|
|
|
id(new PhutilConsoleBlock())
|
|
|
|
->addParagraph(
|
|
|
|
pht(
|
|
|
|
'Choose which type or types of test data you want to generate, '.
|
|
|
|
'or select "%s".',
|
|
|
|
$all))
|
|
|
|
->addList($list)
|
|
|
|
->draw();
|
|
|
|
|
|
|
|
return 0;
|
2013-04-29 21:14:50 +02:00
|
|
|
}
|
2015-02-28 23:41:52 +01:00
|
|
|
|
2015-12-24 13:49:25 +01:00
|
|
|
$generators = array();
|
|
|
|
foreach ($argv as $arg_original) {
|
|
|
|
$arg = phutil_utf8_strtolower($arg_original);
|
|
|
|
|
|
|
|
$match = false;
|
|
|
|
foreach ($all_generators as $generator) {
|
|
|
|
$name = phutil_utf8_strtolower($generator->getGeneratorName());
|
|
|
|
|
|
|
|
if ($arg == $all) {
|
|
|
|
$generators[] = $generator;
|
|
|
|
$match = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strpos($name, $arg) !== false) {
|
|
|
|
$generators[] = $generator;
|
|
|
|
$match = true;
|
|
|
|
break;
|
2013-04-29 21:14:50 +02:00
|
|
|
}
|
|
|
|
}
|
2015-12-24 13:49:25 +01:00
|
|
|
|
|
|
|
if (!$match) {
|
|
|
|
throw new PhutilArgumentUsageException(
|
|
|
|
pht(
|
|
|
|
'Argument "%s" does not match the name of any generators.',
|
|
|
|
$arg_original));
|
|
|
|
}
|
2013-04-29 21:14:50 +02:00
|
|
|
}
|
2015-02-28 23:41:52 +01:00
|
|
|
|
2015-12-24 13:49:25 +01:00
|
|
|
echo tsprintf(
|
|
|
|
"**<bg:blue> %s </bg>** %s\n",
|
|
|
|
pht('GENERATORS'),
|
|
|
|
pht(
|
|
|
|
'Selected generators: %s.',
|
|
|
|
implode(', ', mpull($generators, 'getGeneratorName'))));
|
2013-04-25 03:17:30 +02:00
|
|
|
|
2015-12-24 13:49:25 +01:00
|
|
|
echo tsprintf(
|
|
|
|
"**<bg:yellow> %s </bg>** %s\n",
|
|
|
|
pht('WARNING'),
|
|
|
|
pht(
|
|
|
|
'This command generates synthetic test data, including user '.
|
|
|
|
'accounts. It is intended for use in development environments '.
|
|
|
|
'so you can test features more easily. There is no easy way to '.
|
|
|
|
'delete this data or undo the effects of this command. If you run '.
|
|
|
|
'it in a production environment, it will pollute your data with '.
|
|
|
|
'large amounts of meaningless garbage that you can not get rid of.'));
|
2015-02-28 23:41:52 +01:00
|
|
|
|
2015-12-24 13:49:25 +01:00
|
|
|
$prompt = pht('Are you sure you want to generate piles of garbage?');
|
|
|
|
if (!phutil_console_confirm($prompt, true)) {
|
2013-04-29 21:14:50 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-12-24 13:49:25 +01:00
|
|
|
|
|
|
|
echo tsprintf(
|
|
|
|
"**<bg:green> %s </bg>** %s\n",
|
|
|
|
pht('LIPSUM'),
|
|
|
|
pht(
|
|
|
|
'Generating synthetic test objects forever. '.
|
|
|
|
'Use ^C to stop when satisfied.'));
|
|
|
|
|
|
|
|
$this->generate($generators);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function generate(array $generators) {
|
|
|
|
$viewer = $this->getViewer();
|
2015-02-28 23:41:52 +01:00
|
|
|
|
2015-12-24 14:29:57 +01:00
|
|
|
foreach ($generators as $generator) {
|
|
|
|
$generator->setViewer($this->getViewer());
|
|
|
|
}
|
|
|
|
|
2013-04-29 21:14:50 +02:00
|
|
|
while (true) {
|
2015-12-24 13:49:25 +01:00
|
|
|
$generator = $generators[array_rand($generators)];
|
|
|
|
|
2015-12-24 14:29:57 +01:00
|
|
|
try {
|
|
|
|
$object = $generator->generateObject();
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
echo tsprintf(
|
|
|
|
"**<bg:yellow> %s </bg>** %s\n",
|
|
|
|
pht('OOPS'),
|
|
|
|
pht(
|
|
|
|
'Generator ("%s") was unable to generate an object.',
|
|
|
|
$generator->getGeneratorName()));
|
|
|
|
|
|
|
|
echo tsprintf(
|
|
|
|
"%B\n",
|
|
|
|
$ex->getMessage());
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-12-24 13:49:25 +01:00
|
|
|
$object_phid = $object->getPHID();
|
|
|
|
|
|
|
|
$handles = $viewer->loadHandles(array($object_phid));
|
|
|
|
|
|
|
|
echo tsprintf(
|
|
|
|
"%s\n",
|
|
|
|
pht(
|
|
|
|
'Generated "%s": %s',
|
|
|
|
$handles[$object_phid]->getTypeName(),
|
|
|
|
$handles[$object_phid]->getFullName()));
|
|
|
|
|
|
|
|
sleep(1);
|
2013-04-29 21:14:50 +02:00
|
|
|
}
|
2013-04-12 23:07:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|