3 final class PhabricatorLipsumGenerateWorkflow
4 extends PhabricatorLipsumManagementWorkflow
{
6 protected function didConstruct() {
9 ->setExamples('**generate**')
10 ->setSynopsis(pht('Generate synthetic test objects.'))
17 'Generate objects without prompting for confirmation.'),
22 'Generate objects as quickly as possible.'),
31 public function execute(PhutilArgumentParser
$args) {
32 $config_key = 'phabricator.developer-mode';
33 if (!PhabricatorEnv
::getEnvConfig($config_key)) {
34 throw new PhutilArgumentUsageException(
36 'lipsum is a development and testing tool and may only be run '.
37 'on installs in developer mode. Enable "%s" in your configuration '.
42 $all_generators = id(new PhutilClassMapQuery())
43 ->setAncestorClass('PhabricatorTestDataGenerator')
44 ->setUniqueMethod('getGeneratorKey')
47 $argv = $args->getArg('args');
48 $is_force = $args->getArg('force');
49 $is_quickly = $args->getArg('quickly');
53 if (isset($all_generators[$all])) {
56 'A lipsum generator is registered with key "%s". This key is '.
62 ksort($all_generators);
65 foreach ($all_generators as $generator) {
68 $generator->getGeneratorKey(),
69 $generator->getGeneratorName());
72 $list = id(new PhutilConsoleList())
76 id(new PhutilConsoleBlock())
79 'Choose which type or types of test data you want to generate, '.
88 $generators = array();
89 foreach ($argv as $arg_original) {
90 $arg = phutil_utf8_strtolower($arg_original);
93 $matches = $all_generators;
96 foreach ($all_generators as $generator) {
97 $name = phutil_utf8_strtolower($generator->getGeneratorKey());
99 // If there's an exact match, select just that generator.
101 $matches = array($generator);
105 // If there's a partial match, match that generator but continue.
106 if (strpos($name, $arg) !== false) {
107 $matches[] = $generator;
112 throw new PhutilArgumentUsageException(
114 'Argument "%s" does not match the name of any generators.',
118 if (count($matches) > 1) {
119 throw new PhutilArgumentUsageException(
121 'Argument "%s" is ambiguous, and matches multiple '.
124 implode(', ', mpull($matches, 'getGeneratorName'))));
128 foreach ($matches as $match) {
129 $generators[] = $match;
133 $generators = mpull($generators, null, 'getGeneratorKey');
136 "**<bg:blue> %s </bg>** %s\n",
139 'Selected generators: %s.',
140 implode(', ', mpull($generators, 'getGeneratorName'))));
144 "**<bg:yellow> %s </bg>** %s\n",
147 'This command generates synthetic test data, including user '.
148 'accounts. It is intended for use in development environments so '.
149 'you can test features more easily. There is no easy way to delete '.
150 'this data or undo the effects of this command. If you run it in a '.
151 'production environment, it will pollute your data with large '.
152 'amounts of meaningless garbage that you can not get rid of.'));
154 $prompt = pht('Are you sure you want to generate piles of garbage?');
155 if (!phutil_console_confirm($prompt, true)) {
161 "**<bg:green> %s </bg>** %s\n",
164 'Generating synthetic test objects forever. '.
165 'Use ^C to stop when satisfied.'));
167 $this->generate($generators, $is_quickly);
170 protected function generate(array $generators, $is_quickly) {
171 $viewer = $this->getViewer();
173 foreach ($generators as $generator) {
174 $generator->setViewer($this->getViewer());
178 $generator = $generators[array_rand($generators)];
181 $object = $generator->generateObject();
182 } catch (Exception
$ex) {
184 "**<bg:yellow> %s </bg>** %s\n",
187 'Generator ("%s") was unable to generate an object.',
188 $generator->getGeneratorName()));
197 if (is_string($object)) {
198 $object_phid = $object;
200 $object_phid = $object->getPHID();
203 $handles = $viewer->loadHandles(array($object_phid));
208 'Generated "%s": %s',
209 $handles[$object_phid]->getTypeName(),
210 $handles[$object_phid]->getFullName()));