Page MenuHomePhabricator

D14873.diff
No OneTemporary

D14873.diff

diff --git a/scripts/lipsum/manage_lipsum.php b/scripts/lipsum/manage_lipsum.php
--- a/scripts/lipsum/manage_lipsum.php
+++ b/scripts/lipsum/manage_lipsum.php
@@ -5,10 +5,10 @@
require_once $root.'/scripts/__init_script__.php';
$args = new PhutilArgumentParser($argv);
-$args->setTagline(pht('manage lipsum'));
+$args->setTagline(pht('synthetic data generator'));
$args->setSynopsis(<<<EOSYNOPSIS
**lipsum** __command__ [__options__]
- Manage Phabricator Test Data Generator.
+ Generate synthetic test data to make development easier.
EOSYNOPSIS
);
diff --git a/src/applications/differential/lipsum/PhabricatorDifferentialRevisionTestDataGenerator.php b/src/applications/differential/lipsum/PhabricatorDifferentialRevisionTestDataGenerator.php
--- a/src/applications/differential/lipsum/PhabricatorDifferentialRevisionTestDataGenerator.php
+++ b/src/applications/differential/lipsum/PhabricatorDifferentialRevisionTestDataGenerator.php
@@ -3,7 +3,11 @@
final class PhabricatorDifferentialRevisionTestDataGenerator
extends PhabricatorTestDataGenerator {
- public function generate() {
+ public function getGeneratorName() {
+ return pht('Differential Revisions');
+ }
+
+ public function generateObject() {
$author = $this->loadPhabrictorUser();
$revision = DifferentialRevision::initializeNewRevision($author);
diff --git a/src/applications/files/lipsum/PhabricatorFileTestDataGenerator.php b/src/applications/files/lipsum/PhabricatorFileTestDataGenerator.php
--- a/src/applications/files/lipsum/PhabricatorFileTestDataGenerator.php
+++ b/src/applications/files/lipsum/PhabricatorFileTestDataGenerator.php
@@ -3,7 +3,11 @@
final class PhabricatorFileTestDataGenerator
extends PhabricatorTestDataGenerator {
- public function generate() {
+ public function getGeneratorName() {
+ return pht('Files');
+ }
+
+ public function generateObject() {
$author_phid = $this->loadPhabrictorUserPHID();
$dimension = 1 << rand(5, 12);
$image = id(new PhabricatorLipsumMondrianArtist())
diff --git a/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php b/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php
--- a/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php
+++ b/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php
@@ -2,9 +2,8 @@
abstract class PhabricatorTestDataGenerator extends Phobject {
- public function generate() {
- return;
- }
+ abstract public function getGeneratorName();
+ abstract public function generateObject();
public function loadOneRandom($classname) {
try {
diff --git a/src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php b/src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php
--- a/src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php
+++ b/src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php
@@ -7,7 +7,7 @@
$this
->setName('generate')
->setExamples('**generate**')
- ->setSynopsis(pht('Generate some lipsum.'))
+ ->setSynopsis(pht('Generate synthetic test objects.'))
->setArguments(
array(
array(
@@ -18,77 +18,124 @@
}
public function execute(PhutilArgumentParser $args) {
- $console = PhutilConsole::getConsole();
+ $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));
+ }
- $supported_types = id(new PhutilClassMapQuery())
+ $all_generators = id(new PhutilClassMapQuery())
->setAncestorClass('PhabricatorTestDataGenerator')
->execute();
- $console->writeOut(
- "%s:\n\t%s\n",
- pht('These are the types of data you can generate'),
- implode("\n\t", array_keys($supported_types)));
+ $argv = $args->getArg('args');
+ $all = 'all';
- $prompt = pht('Are you sure you want to generate lots of test data?');
- if (!phutil_console_confirm($prompt, true)) {
- return;
+ 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;
}
- $argv = $args->getArg('args');
- if (count($argv) == 0 || (count($argv) == 1 && $argv[0] == 'all')) {
- $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 {
- $console->writeErr(
- "%s\n",
- pht(
- 'The type %s is not supported by the lipsum generator.',
- $arg));
+ $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;
}
}
- $this->infinitelyGenerate($new_supported_types);
+
+ if (!$match) {
+ throw new PhutilArgumentUsageException(
+ pht(
+ 'Argument "%s" does not match the name of any generators.',
+ $arg_original));
+ }
}
- $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)));
- }
+ echo tsprintf(
+ "**<bg:blue> %s </bg>** %s\n",
+ pht('GENERATORS'),
+ pht(
+ 'Selected generators: %s.',
+ implode(', ', mpull($generators, 'getGeneratorName'))));
- protected function infinitelyGenerate(array $supported_types) {
- $console = PhutilConsole::getConsole();
+ 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.'));
- if (count($supported_types) == 0) {
+ $prompt = pht('Are you sure you want to generate piles of garbage?');
+ if (!phutil_console_confirm($prompt, true)) {
return;
}
- $console->writeOut(
- "%s: %s\n",
- pht('GENERATING'),
- implode(', ', array_keys($supported_types)));
+
+ 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();
while (true) {
- $type = $supported_types[array_rand($supported_types)];
- $admin = $this->getViewer();
-
- $taskgen = newv($type, array());
- $object = $taskgen->generate();
- $handle = id(new PhabricatorHandleQuery())
- ->setViewer($admin)
- ->withPHIDs(array($object->getPHID()))
- ->executeOne();
-
- $console->writeOut(
- "%s: %s\n",
- pht('Generated %s', $handle->getTypeName()),
- $handle->getFullName());
-
- usleep(200000);
+ $generator = $generators[array_rand($generators)];
+
+ $object = $generator->generateObject();
+ $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);
}
}
diff --git a/src/applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php b/src/applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php
--- a/src/applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php
+++ b/src/applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php
@@ -3,7 +3,11 @@
final class PhabricatorManiphestTaskTestDataGenerator
extends PhabricatorTestDataGenerator {
- public function generate() {
+ public function getGeneratorName() {
+ return pht('Maniphest Tasks');
+ }
+
+ public function generateObject() {
$author_phid = $this->loadPhabrictorUserPHID();
$author = id(new PhabricatorUser())
->loadOneWhere('phid = %s', $author_phid);
diff --git a/src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php b/src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php
--- a/src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php
+++ b/src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php
@@ -3,13 +3,17 @@
final class PhabricatorPasteTestDataGenerator
extends PhabricatorTestDataGenerator {
+ public function getGeneratorName() {
+ return pht('Pastes');
+ }
+
// Better Support for this in the future
public $supportedLanguages = array(
'Java' => 'java',
'PHP' => 'php',
);
- public function generate() {
+ public function generateObject() {
$author = $this->loadPhabrictorUser();
$authorphid = $author->getPHID();
$language = $this->generateLanguage();
diff --git a/src/applications/people/lipsum/PhabricatorPeopleTestDataGenerator.php b/src/applications/people/lipsum/PhabricatorPeopleTestDataGenerator.php
--- a/src/applications/people/lipsum/PhabricatorPeopleTestDataGenerator.php
+++ b/src/applications/people/lipsum/PhabricatorPeopleTestDataGenerator.php
@@ -3,7 +3,11 @@
final class PhabricatorPeopleTestDataGenerator
extends PhabricatorTestDataGenerator {
- public function generate() {
+ public function getGeneratorName() {
+ return pht('User Accounts');
+ }
+
+ public function generateObject() {
while (true) {
try {
diff --git a/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php b/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php
--- a/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php
+++ b/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php
@@ -3,7 +3,11 @@
final class PhabricatorPholioMockTestDataGenerator
extends PhabricatorTestDataGenerator {
- public function generate() {
+ public function getGeneratorName() {
+ return pht('Pholio Mocks');
+ }
+
+ public function generateObject() {
$author_phid = $this->loadPhabrictorUserPHID();
$author = id(new PhabricatorUser())
->loadOneWhere('phid = %s', $author_phid);
diff --git a/src/applications/project/lipsum/PhabricatorProjectTestDataGenerator.php b/src/applications/project/lipsum/PhabricatorProjectTestDataGenerator.php
--- a/src/applications/project/lipsum/PhabricatorProjectTestDataGenerator.php
+++ b/src/applications/project/lipsum/PhabricatorProjectTestDataGenerator.php
@@ -5,7 +5,11 @@
private $xactions = array();
- public function generate() {
+ public function getGeneratorName() {
+ return pht('Projects');
+ }
+
+ public function generateObject() {
$title = $this->generateTitle();
$author = $this->loadPhabrictorUser();
$author_phid = $author->getPHID();

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 16, 5:01 AM (2 d, 1 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6714477
Default Alt Text
D14873.diff (12 KB)

Event Timeline