@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 lispum generation of pastes

Summary: Fixes T8482, or something. I can't actually repro that but I think it should be fixed either here or earlier

Test Plan:
```
$ ./bin/lipsum generate paste
GENERATORS Selected generators: Pastes.
WARNING 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.

Are you sure you want to generate piles of garbage? [y/N] y

LIPSUM Generating synthetic test objects forever. Use ^C to stop when satisfied.
Generated "Paste": P223 forgotten_memory_disks_backup.java
Generated "Paste": P224 backup_disk_tables_and_administrate_backup_memory_account.java
Generated "Paste": P225 sync_backup_disk_and_undo_memory.php
Generated "Paste": P226 administrate_memory_shard_helper.php
Generated "Paste": P227 cancel_disk_users
Generated "Paste": P228 backups_pro.txt
Generated "Paste": P229 undo_host.txt
Generated "Paste": P230 accelerate_database_accounts.java
Generated "Paste": P231 entomb_accounts.java
Generated "Paste": P232 legendary_legendary_shards_helper.java
Generated "Paste": P233 compact_backup_and_user_and_purge_memory
Generated "Paste": P234 account_script_script_backup_helper_helper.java
Generated "Paste": P235 purge_disk.php
Generated "Paste": P236 forgotten_elder_account.txt
Generated "Paste": P237 ancient_ancient_disks.txt
Generated "Paste": P238 disk_user.php
```

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T8482

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

+182 -85
+2
src/__phutil_library_map__.php
··· 2687 2687 'PhabricatorPasteEditController' => 'applications/paste/controller/PhabricatorPasteEditController.php', 2688 2688 'PhabricatorPasteEditEngine' => 'applications/paste/editor/PhabricatorPasteEditEngine.php', 2689 2689 'PhabricatorPasteEditor' => 'applications/paste/editor/PhabricatorPasteEditor.php', 2690 + 'PhabricatorPasteFilenameContextFreeGrammar' => 'applications/paste/lipsum/PhabricatorPasteFilenameContextFreeGrammar.php', 2690 2691 'PhabricatorPasteListController' => 'applications/paste/controller/PhabricatorPasteListController.php', 2691 2692 'PhabricatorPastePastePHIDType' => 'applications/paste/phid/PhabricatorPastePastePHIDType.php', 2692 2693 'PhabricatorPasteQuery' => 'applications/paste/query/PhabricatorPasteQuery.php', ··· 6987 6988 'PhabricatorPasteEditController' => 'PhabricatorPasteController', 6988 6989 'PhabricatorPasteEditEngine' => 'PhabricatorEditEngine', 6989 6990 'PhabricatorPasteEditor' => 'PhabricatorApplicationTransactionEditor', 6991 + 'PhabricatorPasteFilenameContextFreeGrammar' => 'PhutilContextFreeGrammar', 6990 6992 'PhabricatorPasteListController' => 'PhabricatorPasteController', 6991 6993 'PhabricatorPastePastePHIDType' => 'PhabricatorPHIDType', 6992 6994 'PhabricatorPasteQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
+16 -1
src/applications/lipsum/generator/PhabricatorTestDataGenerator.php
··· 74 74 return $sum; 75 75 } 76 76 77 + protected function newEmptyTransaction() { 78 + throw new PhutilMethodNotImplementedException(); 79 + } 80 + 81 + protected function newTransaction($type, $value, $metadata = array()) { 82 + $xaction = $this->newEmptyTransaction() 83 + ->setTransactionType($type) 84 + ->setNewValue($value); 85 + 86 + foreach ($metadata as $key => $value) { 87 + $xaction->setMetadataValue($key, $value); 88 + } 89 + 90 + return $xaction; 91 + } 92 + 77 93 78 94 79 95 ··· 88 104 $classname)); 89 105 } 90 106 } 91 - 92 107 93 108 public function loadPhabrictorUserPHID() { 94 109 return $this->loadOneRandom('PhabricatorUser')->getPHID();
+87
src/applications/paste/lipsum/PhabricatorPasteFilenameContextFreeGrammar.php
··· 1 + <?php 2 + 3 + final class PhabricatorPasteFilenameContextFreeGrammar 4 + extends PhutilContextFreeGrammar { 5 + 6 + protected function getRules() { 7 + return array( 8 + 'start' => array( 9 + '[scripty]', 10 + ), 11 + 'scripty' => array( 12 + '[thing]', 13 + '[thing]', 14 + '[thing]_[tail]', 15 + '[action]_[thing]', 16 + '[action]_[thing]', 17 + '[action]_[thing]_[tail]', 18 + '[scripty]_and_[scripty]', 19 + ), 20 + 'tail' => array( 21 + 'script', 22 + 'helper', 23 + 'backup', 24 + 'pro', 25 + '[tail]_[tail]', 26 + ), 27 + 'thing' => array( 28 + '[thingnoun]', 29 + '[thingadjective]_[thingnoun]', 30 + '[thingadjective]_[thingadjective]_[thingnoun]', 31 + ), 32 + 'thingnoun' => array( 33 + 'backup', 34 + 'backups', 35 + 'database', 36 + 'databases', 37 + 'table', 38 + 'tables', 39 + 'memory', 40 + 'disk', 41 + 'disks', 42 + 'user', 43 + 'users', 44 + 'account', 45 + 'accounts', 46 + 'shard', 47 + 'shards', 48 + 'node', 49 + 'nodes', 50 + 'host', 51 + 'hosts', 52 + 'account', 53 + 'accounts', 54 + ), 55 + 'thingadjective' => array( 56 + 'backup', 57 + 'database', 58 + 'memory', 59 + 'disk', 60 + 'user', 61 + 'account', 62 + 'forgotten', 63 + 'lost', 64 + 'elder', 65 + 'ancient', 66 + 'legendary', 67 + ), 68 + 'action' => array( 69 + 'manage', 70 + 'update', 71 + 'compact', 72 + 'quick', 73 + 'probe', 74 + 'sync', 75 + 'undo', 76 + 'administrate', 77 + 'assess', 78 + 'purge', 79 + 'cancel', 80 + 'entomb', 81 + 'accelerate', 82 + 'plan', 83 + ), 84 + ); 85 + } 86 + 87 + }
+75 -74
src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php
··· 7 7 return pht('Pastes'); 8 8 } 9 9 10 - // Better Support for this in the future 11 - public $supportedLanguages = array( 12 - 'Java' => 'java', 13 - 'PHP' => 'php', 14 - ); 10 + public function generateObject() { 11 + $author = $this->loadRandomUser(); 12 + 13 + list($name, $language, $content) = $this->newPasteContent(); 14 + 15 + $paste = PhabricatorPaste::initializeNewPaste($author); 15 16 16 - public function generateObject() { 17 - $author = $this->loadPhabrictorUser(); 18 - $authorphid = $author->getPHID(); 19 - $language = $this->generateLanguage(); 20 - $content = $this->generateContent($language); 21 - $title = $this->generateTitle($language); 22 - $paste_file = PhabricatorFile::newFromFileData( 23 - $content, 24 - array( 25 - 'name' => $title, 26 - 'mime-type' => 'text/plain; charset=utf-8', 27 - 'authorPHID' => $authorphid, 28 - )); 29 - $policy = $this->generatePolicy(); 30 - $filephid = $paste_file->getPHID(); 31 - $parentphid = $this->loadPhabrictorPastePHID(); 32 - $paste = PhabricatorPaste::initializeNewPaste($author) 33 - ->setParentPHID($parentphid) 34 - ->setTitle($title) 35 - ->setLanguage($language) 36 - ->setViewPolicy($policy) 37 - ->setEditPolicy($policy) 38 - ->setFilePHID($filephid) 39 - ->save(); 17 + $xactions = array(); 18 + 19 + $xactions[] = $this->newTransaction( 20 + PhabricatorPasteTransaction::TYPE_TITLE, 21 + $name); 22 + 23 + $xactions[] = $this->newTransaction( 24 + PhabricatorPasteTransaction::TYPE_LANGUAGE, 25 + $language); 26 + 27 + $xactions[] = $this->newTransaction( 28 + PhabricatorPasteTransaction::TYPE_CONTENT, 29 + $content); 30 + 31 + $editor = id(new PhabricatorPasteEditor()) 32 + ->setActor($author) 33 + ->setContentSource($this->getLipsumContentSource()) 34 + ->setContinueOnNoEffect(true) 35 + ->applyTransactions($paste, $xactions); 36 + 40 37 return $paste; 41 38 } 42 39 43 - private function loadPhabrictorPastePHID() { 44 - $random = rand(0, 1); 45 - if ($random == 1) { 46 - $paste = id($this->loadOneRandom('PhabricatorPaste')); 47 - if ($paste) { 48 - return $paste->getPHID(); 49 - } 40 + protected function newEmptyTransaction() { 41 + return new PhabricatorPasteTransaction(); 42 + } 43 + 44 + private function newPasteContent() { 45 + $languages = array( 46 + 'txt' => array(), 47 + 'php' => array( 48 + 'content' => 'PhutilPHPCodeSnippetContextFreeGrammar', 49 + ), 50 + 'java' => array( 51 + 'content' => 'PhutilJavaCodeSnippetContextFreeGrammar', 52 + ), 53 + ); 54 + 55 + $language = array_rand($languages); 56 + $spec = $languages[$language]; 57 + 58 + $title_generator = idx($spec, 'title'); 59 + if (!$title_generator) { 60 + $title_generator = 'PhabricatorPasteFilenameContextFreeGrammar'; 50 61 } 51 - return null; 52 - } 53 62 54 - public function generateTitle($language = null) { 55 - $taskgen = new PhutilLipsumContextFreeGrammar(); 56 - // Remove Punctuation 57 - $title = preg_replace('/[^a-zA-Z 0-9]+/', '', $taskgen->generate()); 58 - // Capitalize First Letters 59 - $title = ucwords($title); 60 - // Remove Spaces 61 - $title = preg_replace('/\s+/', '', $title); 62 - if ($language == null || 63 - !in_array($language, array_keys($this->supportedLanguages))) { 64 - return $title.'.txt'; 65 - } else { 66 - return $title.'.'.$this->supportedLanguages[$language]; 63 + $content_generator = idx($spec, 'content'); 64 + if (!$content_generator) { 65 + $content_generator = 'PhutilLipsumContextFreeGrammar'; 67 66 } 68 - } 69 67 70 - public function generateLanguage() { 71 - $supplemented_lang = $this->supportedLanguages; 72 - $supplemented_lang['lipsum'] = 'txt'; 73 - return array_rand($supplemented_lang); 74 - } 68 + $title = newv($title_generator, array()) 69 + ->generate(); 75 70 76 - public function generateContent($language = null) { 77 - if ($language == null || 78 - !in_array($language, array_keys($this->supportedLanguages))) { 79 - return id(new PhutilLipsumContextFreeGrammar()) 80 - ->generateSeveral(rand(30, 40)); 81 - } else { 82 - $cfg_class = 'Phutil'.$language.'CodeSnippetContextFreeGrammar'; 83 - return newv($cfg_class, array())->generate(); 84 - } 85 - } 71 + $content = newv($content_generator, array()) 72 + ->generateSeveral($this->roll(4, 12, 10)); 73 + 74 + // Usually add the language as a suffix. 75 + if ($this->roll(1, 20) > 2) { 76 + $title = $title.'.'.$language; 77 + } 86 78 87 - public function generatePolicy() { 88 - // Make sure 4/5th of all generated Pastes are viewable to all 89 - switch (rand(0, 4)) { 90 - case 0: 91 - return PhabricatorPolicies::POLICY_PUBLIC; 79 + switch ($this->roll(1, 20)) { 92 80 case 1: 93 - return PhabricatorPolicies::POLICY_NOONE; 81 + // On critical miss, set a different, random language. 82 + $highlight_as = array_rand($languages); 83 + break; 84 + case 18: 85 + case 19: 86 + case 20: 87 + // Sometimes set it to the correct language. 88 + $highlight_as = $language; 89 + break; 94 90 default: 95 - return PhabricatorPolicies::POLICY_USER; 91 + // Usually leave it as autodetect. 92 + $highlight_as = ''; 93 + break; 96 94 } 95 + 96 + return array($title, $highlight_as, $content); 97 97 } 98 + 98 99 }
+2 -10
src/applications/project/lipsum/PhabricatorProjectTestDataGenerator.php
··· 51 51 return $project; 52 52 } 53 53 54 - private function newTransaction($type, $value, $metadata = array()) { 55 - $xaction = id(new PhabricatorProjectTransaction()) 56 - ->setTransactionType($type) 57 - ->setNewValue($value); 58 - 59 - foreach ($metadata as $key => $value) { 60 - $xaction->setMetadataValue($key, $value); 61 - } 62 - 63 - return $xaction; 54 + protected function newEmptyTransaction() { 55 + return new PhabricatorProjectTransaction(); 64 56 } 65 57 66 58 public function newProjectTitle() {