@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Improve bin/lipsum UX

Summary: Ref T9156. This makes the UX a little more modern/standard/safe.

Test Plan:
```
epriestley@orbital ~/dev/phabricator $ ./bin/lipsum generate
Choose which type or types of test data you want to generate, or select "all".

- Differential Revisions
- Files
- Maniphest Tasks
- Pastes
- Pholio Mocks
- Projects
- User Accounts
```

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9156

Differential Revision: https://secure.phabricator.com/D14873

+138 -64
+2 -2
scripts/lipsum/manage_lipsum.php
··· 5 5 require_once $root.'/scripts/__init_script__.php'; 6 6 7 7 $args = new PhutilArgumentParser($argv); 8 - $args->setTagline(pht('manage lipsum')); 8 + $args->setTagline(pht('synthetic data generator')); 9 9 $args->setSynopsis(<<<EOSYNOPSIS 10 10 **lipsum** __command__ [__options__] 11 - Manage Phabricator Test Data Generator. 11 + Generate synthetic test data to make development easier. 12 12 13 13 EOSYNOPSIS 14 14 );
+5 -1
src/applications/differential/lipsum/PhabricatorDifferentialRevisionTestDataGenerator.php
··· 3 3 final class PhabricatorDifferentialRevisionTestDataGenerator 4 4 extends PhabricatorTestDataGenerator { 5 5 6 - public function generate() { 6 + public function getGeneratorName() { 7 + return pht('Differential Revisions'); 8 + } 9 + 10 + public function generateObject() { 7 11 $author = $this->loadPhabrictorUser(); 8 12 9 13 $revision = DifferentialRevision::initializeNewRevision($author);
+5 -1
src/applications/files/lipsum/PhabricatorFileTestDataGenerator.php
··· 3 3 final class PhabricatorFileTestDataGenerator 4 4 extends PhabricatorTestDataGenerator { 5 5 6 - public function generate() { 6 + public function getGeneratorName() { 7 + return pht('Files'); 8 + } 9 + 10 + public function generateObject() { 7 11 $author_phid = $this->loadPhabrictorUserPHID(); 8 12 $dimension = 1 << rand(5, 12); 9 13 $image = id(new PhabricatorLipsumMondrianArtist())
+2 -3
src/applications/lipsum/generator/PhabricatorTestDataGenerator.php
··· 2 2 3 3 abstract class PhabricatorTestDataGenerator extends Phobject { 4 4 5 - public function generate() { 6 - return; 7 - } 5 + abstract public function getGeneratorName(); 6 + abstract public function generateObject(); 8 7 9 8 public function loadOneRandom($classname) { 10 9 try {
+99 -52
src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php
··· 7 7 $this 8 8 ->setName('generate') 9 9 ->setExamples('**generate**') 10 - ->setSynopsis(pht('Generate some lipsum.')) 10 + ->setSynopsis(pht('Generate synthetic test objects.')) 11 11 ->setArguments( 12 12 array( 13 13 array( ··· 18 18 } 19 19 20 20 public function execute(PhutilArgumentParser $args) { 21 - $console = PhutilConsole::getConsole(); 21 + $config_key = 'phabricator.developer-mode'; 22 + if (!PhabricatorEnv::getEnvConfig($config_key)) { 23 + throw new PhutilArgumentUsageException( 24 + pht( 25 + 'lipsum is a development and testing tool and may only be run '. 26 + 'on installs in developer mode. Enable "%s" in your configuration '. 27 + 'to enable lipsum.', 28 + $config_key)); 29 + } 22 30 23 - $supported_types = id(new PhutilClassMapQuery()) 31 + $all_generators = id(new PhutilClassMapQuery()) 24 32 ->setAncestorClass('PhabricatorTestDataGenerator') 25 33 ->execute(); 26 34 27 - $console->writeOut( 28 - "%s:\n\t%s\n", 29 - pht('These are the types of data you can generate'), 30 - implode("\n\t", array_keys($supported_types))); 35 + $argv = $args->getArg('args'); 36 + $all = 'all'; 31 37 32 - $prompt = pht('Are you sure you want to generate lots of test data?'); 33 - if (!phutil_console_confirm($prompt, true)) { 34 - return; 38 + if (!$argv) { 39 + $names = mpull($all_generators, 'getGeneratorName'); 40 + sort($names); 41 + 42 + $list = id(new PhutilConsoleList()) 43 + ->setWrap(false) 44 + ->addItems($names); 45 + 46 + id(new PhutilConsoleBlock()) 47 + ->addParagraph( 48 + pht( 49 + 'Choose which type or types of test data you want to generate, '. 50 + 'or select "%s".', 51 + $all)) 52 + ->addList($list) 53 + ->draw(); 54 + 55 + return 0; 35 56 } 36 57 37 - $argv = $args->getArg('args'); 38 - if (count($argv) == 0 || (count($argv) == 1 && $argv[0] == 'all')) { 39 - $this->infinitelyGenerate($supported_types); 40 - } else { 41 - $new_supported_types = array(); 42 - for ($i = 0; $i < count($argv); $i++) { 43 - $arg = $argv[$i]; 44 - if (array_key_exists($arg, $supported_types)) { 45 - $new_supported_types[$arg] = $supported_types[$arg]; 46 - } else { 47 - $console->writeErr( 48 - "%s\n", 49 - pht( 50 - 'The type %s is not supported by the lipsum generator.', 51 - $arg)); 58 + $generators = array(); 59 + foreach ($argv as $arg_original) { 60 + $arg = phutil_utf8_strtolower($arg_original); 61 + 62 + $match = false; 63 + foreach ($all_generators as $generator) { 64 + $name = phutil_utf8_strtolower($generator->getGeneratorName()); 65 + 66 + if ($arg == $all) { 67 + $generators[] = $generator; 68 + $match = true; 69 + break; 70 + } 71 + 72 + if (strpos($name, $arg) !== false) { 73 + $generators[] = $generator; 74 + $match = true; 75 + break; 52 76 } 53 77 } 54 - $this->infinitelyGenerate($new_supported_types); 78 + 79 + if (!$match) { 80 + throw new PhutilArgumentUsageException( 81 + pht( 82 + 'Argument "%s" does not match the name of any generators.', 83 + $arg_original)); 84 + } 55 85 } 56 86 57 - $console->writeOut( 58 - "%s\n%s:\n%s\n", 59 - pht('None of the input types were supported.'), 60 - pht('The supported types are'), 61 - implode("\n", array_keys($supported_types))); 62 - } 87 + echo tsprintf( 88 + "**<bg:blue> %s </bg>** %s\n", 89 + pht('GENERATORS'), 90 + pht( 91 + 'Selected generators: %s.', 92 + implode(', ', mpull($generators, 'getGeneratorName')))); 63 93 64 - protected function infinitelyGenerate(array $supported_types) { 65 - $console = PhutilConsole::getConsole(); 94 + echo tsprintf( 95 + "**<bg:yellow> %s </bg>** %s\n", 96 + pht('WARNING'), 97 + pht( 98 + 'This command generates synthetic test data, including user '. 99 + 'accounts. It is intended for use in development environments '. 100 + 'so you can test features more easily. There is no easy way to '. 101 + 'delete this data or undo the effects of this command. If you run '. 102 + 'it in a production environment, it will pollute your data with '. 103 + 'large amounts of meaningless garbage that you can not get rid of.')); 66 104 67 - if (count($supported_types) == 0) { 105 + $prompt = pht('Are you sure you want to generate piles of garbage?'); 106 + if (!phutil_console_confirm($prompt, true)) { 68 107 return; 69 108 } 70 - $console->writeOut( 71 - "%s: %s\n", 72 - pht('GENERATING'), 73 - implode(', ', array_keys($supported_types))); 109 + 110 + echo tsprintf( 111 + "**<bg:green> %s </bg>** %s\n", 112 + pht('LIPSUM'), 113 + pht( 114 + 'Generating synthetic test objects forever. '. 115 + 'Use ^C to stop when satisfied.')); 116 + 117 + $this->generate($generators); 118 + } 119 + 120 + protected function generate(array $generators) { 121 + $viewer = $this->getViewer(); 74 122 75 123 while (true) { 76 - $type = $supported_types[array_rand($supported_types)]; 77 - $admin = $this->getViewer(); 124 + $generator = $generators[array_rand($generators)]; 125 + 126 + $object = $generator->generateObject(); 127 + $object_phid = $object->getPHID(); 78 128 79 - $taskgen = newv($type, array()); 80 - $object = $taskgen->generate(); 81 - $handle = id(new PhabricatorHandleQuery()) 82 - ->setViewer($admin) 83 - ->withPHIDs(array($object->getPHID())) 84 - ->executeOne(); 129 + $handles = $viewer->loadHandles(array($object_phid)); 85 130 86 - $console->writeOut( 87 - "%s: %s\n", 88 - pht('Generated %s', $handle->getTypeName()), 89 - $handle->getFullName()); 131 + echo tsprintf( 132 + "%s\n", 133 + pht( 134 + 'Generated "%s": %s', 135 + $handles[$object_phid]->getTypeName(), 136 + $handles[$object_phid]->getFullName())); 90 137 91 - usleep(200000); 138 + sleep(1); 92 139 } 93 140 } 94 141
+5 -1
src/applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php
··· 3 3 final class PhabricatorManiphestTaskTestDataGenerator 4 4 extends PhabricatorTestDataGenerator { 5 5 6 - public function generate() { 6 + public function getGeneratorName() { 7 + return pht('Maniphest Tasks'); 8 + } 9 + 10 + public function generateObject() { 7 11 $author_phid = $this->loadPhabrictorUserPHID(); 8 12 $author = id(new PhabricatorUser()) 9 13 ->loadOneWhere('phid = %s', $author_phid);
+5 -1
src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php
··· 3 3 final class PhabricatorPasteTestDataGenerator 4 4 extends PhabricatorTestDataGenerator { 5 5 6 + public function getGeneratorName() { 7 + return pht('Pastes'); 8 + } 9 + 6 10 // Better Support for this in the future 7 11 public $supportedLanguages = array( 8 12 'Java' => 'java', 9 13 'PHP' => 'php', 10 14 ); 11 15 12 - public function generate() { 16 + public function generateObject() { 13 17 $author = $this->loadPhabrictorUser(); 14 18 $authorphid = $author->getPHID(); 15 19 $language = $this->generateLanguage();
+5 -1
src/applications/people/lipsum/PhabricatorPeopleTestDataGenerator.php
··· 3 3 final class PhabricatorPeopleTestDataGenerator 4 4 extends PhabricatorTestDataGenerator { 5 5 6 - public function generate() { 6 + public function getGeneratorName() { 7 + return pht('User Accounts'); 8 + } 9 + 10 + public function generateObject() { 7 11 8 12 while (true) { 9 13 try {
+5 -1
src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php
··· 3 3 final class PhabricatorPholioMockTestDataGenerator 4 4 extends PhabricatorTestDataGenerator { 5 5 6 - public function generate() { 6 + public function getGeneratorName() { 7 + return pht('Pholio Mocks'); 8 + } 9 + 10 + public function generateObject() { 7 11 $author_phid = $this->loadPhabrictorUserPHID(); 8 12 $author = id(new PhabricatorUser()) 9 13 ->loadOneWhere('phid = %s', $author_phid);
+5 -1
src/applications/project/lipsum/PhabricatorProjectTestDataGenerator.php
··· 5 5 6 6 private $xactions = array(); 7 7 8 - public function generate() { 8 + public function getGeneratorName() { 9 + return pht('Projects'); 10 + } 11 + 12 + public function generateObject() { 9 13 $title = $this->generateTitle(); 10 14 $author = $this->loadPhabrictorUser(); 11 15 $author_phid = $author->getPHID();