diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index f8c3833025..7ee198dcb7 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1089,6 +1089,7 @@ phutil_register_library_map(array( 'PhabricatorMainMenuSearchView' => 'view/page/menu/PhabricatorMainMenuSearchView.php', 'PhabricatorMainMenuView' => 'view/page/menu/PhabricatorMainMenuView.php', 'PhabricatorManiphestConfigOptions' => 'applications/maniphest/config/PhabricatorManiphestConfigOptions.php', + 'PhabricatorManiphestTaskTestDataGenerator' => 'applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php', 'PhabricatorMarkupCache' => 'applications/cache/storage/PhabricatorMarkupCache.php', 'PhabricatorMarkupEngine' => 'infrastructure/markup/PhabricatorMarkupEngine.php', 'PhabricatorMarkupInterface' => 'infrastructure/markup/PhabricatorMarkupInterface.php', @@ -2793,6 +2794,7 @@ phutil_register_library_map(array( 'PhabricatorMainMenuSearchView' => 'AphrontView', 'PhabricatorMainMenuView' => 'AphrontView', 'PhabricatorManiphestConfigOptions' => 'PhabricatorApplicationConfigOptions', + 'PhabricatorManiphestTaskTestDataGenerator' => 'PhabricatorTestDataGenerator', 'PhabricatorMarkupCache' => 'PhabricatorCacheDAO', 'PhabricatorMenuItemView' => 'AphrontTagView', 'PhabricatorMenuView' => 'AphrontTagView', diff --git a/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php b/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php index 6ee22c1bfe..814919e23c 100644 --- a/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php +++ b/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php @@ -6,4 +6,14 @@ abstract class PhabricatorTestDataGenerator { return; } + public function loadOneRandom($classname) { + try { + return newv($classname, array()) + ->loadOneWhere("1 = 1 ORDER BY RAND() LIMIT 1"); + } catch (PhutilMissingSymbolException $ex) { + throw new PhutilMissingSymbolException( + "Unable to load symbol ".$classname.": this class does not exit."); + } + } + } diff --git a/src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php b/src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php index 27a7bb2a8a..a7f50ec647 100644 --- a/src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php +++ b/src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php @@ -19,12 +19,25 @@ final class PhabricatorLipsumGenerateWorkflow public function execute(PhutilArgumentParser $args) { $admin = PhabricatorUser::getOmnipotentUser(); - $peoplegen = new PhabricatorPeopleTestDataGenerator(); - $object = $peoplegen->generate(); + // $peoplegen = new PhabricatorPeopleTestDataGenerator(); + // $object = $peoplegen->generate(); + // $handle = PhabricatorObjectHandleData::loadOneHandle($object->getPHID(), + // $admin); + // echo "Generated ".$handle->getFullName()."\n"; + + $taskgen = new PhabricatorManiphestTaskTestDataGenerator(); + $object = $taskgen->generate(); $handle = PhabricatorObjectHandleData::loadOneHandle($object->getPHID(), $admin); echo "Generated ".$handle->getFullName()."\n"; echo "\nRequested data has been generated."; + + // $taskgen = new PhabricatorRevisionTestDataGenerator(); + // $object = $taskgen->generate(); + // $handle = PhabricatorObjectHandleData::loadOneHandle($object->getPHID(), + // $admin); + // echo "Generated ".$handle->getFullName()."\n"; + // echo "\nRequested data has been generated."; } } diff --git a/src/applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php b/src/applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php new file mode 100644 index 0000000000..313bcfc9a6 --- /dev/null +++ b/src/applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php @@ -0,0 +1,64 @@ +setStatus($this->generateTaskStatus()) + ->setPriority($this->generateTaskPriority()) + ->setSubPriority($this->generateTaskSubPriority()) + ->setAuthorPHID($this->loadAuthorPHID()) + ->setTitle($this->generateTitle()) + ->setDescription($this->generateDescription()) + ->setOwnerPHID($this->loadOwnerPHID()) + ->save(); + } + + private function loadPhabrictorUserPHID() { + return $this->loadOneRandom("PhabricatorUser")->getPHID(); + } + + public function loadAuthorPHID() { + return $this->loadPhabrictorUserPHID(); + } + + public function loadOwnerPHID() { + if (rand(0, 3) == 0) { + return null; + } else { + return $this->loadPhabrictorUserPHID(); + } + } + + public function generateTitle() { + return id(new PhutilLipsumContextFreeGrammar()) + ->generate(); + } + + public function generateDescription() { + return id(new PhutilLipsumContextFreeGrammar()) + ->generateSeveral(rand(30, 40)); + } + + public function generateTaskPriority() { + return array_rand(ManiphestTaskPriority::getTaskPriorityMap()); + } + + public function generateTaskSubPriority() { + return rand(2 << 16, 2 << 32); + } + + public function generateTaskStatus() { + $statuses = array_keys(ManiphestTaskStatus::getTaskStatusMap()); + // Make sure 4/5th of all generated Tasks are open + $random = rand(0, 4); + if ($random != 0) { + return ManiphestTaskStatus::STATUS_OPEN; + } else { + return array_rand($statuses); + } + } + + +} diff --git a/src/applications/people/lipsum/PhabricatorPeopleTestDataGenerator.php b/src/applications/people/lipsum/PhabricatorPeopleTestDataGenerator.php index d489abf2a3..03faf81ac3 100644 --- a/src/applications/people/lipsum/PhabricatorPeopleTestDataGenerator.php +++ b/src/applications/people/lipsum/PhabricatorPeopleTestDataGenerator.php @@ -39,6 +39,7 @@ final class PhabricatorPeopleTestDataGenerator protected function generateUsername($random_real_name) { $name = strtolower($random_real_name); $name = preg_replace('/[^a-z]/s' , ' ', $name); + $name = preg_replace('/\s+/', ' ', $name); $words = explode(" ", $name); $random = rand(0, 4); $reduced = "";