From 3b8ccb0b78eef427b56f8233188f3bb7fcf8e168 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 27 Feb 2017 05:10:25 -0800 Subject: [PATCH] Add "--force" and "--quickly" flags to `bin/lipsum` Summary: Ref T12319. - Lipsum can trash an install by creating a lot of junk that's hard to get rid of, so we're cautious about letting you run it. Add a `--force` flag if you're sure you know what you're doing. This makes the edit/test cycle a bit easier when actually writing Lipsum generators. - Lipsum normally sleeps for a second before creating objects, to give users more control over how much stuff they create and limit the amount of damage caused by mistakes. Sometimes, you want to generate a LOT of stuff because you want to reproduce a performance/scale issue (like T12319). Add a `--quickly` flag to generate objects as fast as possible. - When loading random users (used as authors, assignees, etc), also load user settings so we can `ConduitCall` with them. - Allow generators to return a PHID instead of an actual object (more convenient for Conduit-based generators). Test Plan: - With next change, ran `lipsum generate badges --force --quickly`. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12319 Differential Revision: https://secure.phabricator.com/D17421 --- .../PhabricatorTestDataGenerator.php | 2 +- .../PhabricatorLipsumGenerateWorkflow.php | 58 +++++++++++++------ 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php b/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php index 731bb0ccac..077a2765b5 100644 --- a/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php +++ b/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php @@ -45,6 +45,7 @@ abstract class PhabricatorTestDataGenerator extends Phobject { $user = id(new PhabricatorPeopleQuery()) ->setViewer($viewer) ->withPHIDs(array($user_phid)) + ->needUserSettings(true) ->executeOne(); } @@ -115,5 +116,4 @@ abstract class PhabricatorTestDataGenerator extends Phobject { return $this->loadOneRandom('PhabricatorUser'); } - } diff --git a/src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php b/src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php index 46ea9b6bae..24301640ed 100644 --- a/src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php +++ b/src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php @@ -10,6 +10,17 @@ final class PhabricatorLipsumGenerateWorkflow ->setSynopsis(pht('Generate synthetic test objects.')) ->setArguments( array( + array( + 'name' => 'force', + 'short' => 'f', + 'help' => pht( + 'Generate objects without prompting for confirmation.'), + ), + array( + 'name' => 'quickly', + 'help' => pht( + 'Generate objects as quickly as possible.'), + ), array( 'name' => 'args', 'wildcard' => true, @@ -34,6 +45,9 @@ final class PhabricatorLipsumGenerateWorkflow ->execute(); $argv = $args->getArg('args'); + $is_force = $args->getArg('force'); + $is_quickly = $args->getArg('quickly'); + $all = 'all'; if (isset($all_generators[$all])) { @@ -125,20 +139,22 @@ final class PhabricatorLipsumGenerateWorkflow 'Selected generators: %s.', implode(', ', mpull($generators, 'getGeneratorName')))); - echo tsprintf( - "** %s ** %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.')); - - $prompt = pht('Are you sure you want to generate piles of garbage?'); - if (!phutil_console_confirm($prompt, true)) { - return; + if (!$is_force) { + echo tsprintf( + "** %s ** %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.')); + + $prompt = pht('Are you sure you want to generate piles of garbage?'); + if (!phutil_console_confirm($prompt, true)) { + return; + } } echo tsprintf( @@ -148,10 +164,10 @@ final class PhabricatorLipsumGenerateWorkflow 'Generating synthetic test objects forever. '. 'Use ^C to stop when satisfied.')); - $this->generate($generators); + $this->generate($generators, $is_quickly); } - protected function generate(array $generators) { + protected function generate(array $generators, $is_quickly) { $viewer = $this->getViewer(); foreach ($generators as $generator) { @@ -178,7 +194,11 @@ final class PhabricatorLipsumGenerateWorkflow continue; } - $object_phid = $object->getPHID(); + if (is_string($object)) { + $object_phid = $object; + } else { + $object_phid = $object->getPHID(); + } $handles = $viewer->loadHandles(array($object_phid)); @@ -189,7 +209,9 @@ final class PhabricatorLipsumGenerateWorkflow $handles[$object_phid]->getTypeName(), $handles[$object_phid]->getFullName())); - sleep(1); + if (!$is_quickly) { + sleep(1); + } } } -- 2.51.2