From 6a3c1ba05c9131039a883e7b5cd23af69fea278f Mon Sep 17 00:00:00 2001 From: Mihir Kedia Date: Tue, 7 Jul 2015 05:32:54 -0700 Subject: [PATCH] Fix bin/lipsum Summary: - Set a default edit policy to match view policy for projects - It seems like initializeNew* is a better init function than new Phabricator*, so ported two classes to use it and spot-checked the others (this also fixed a fatal.) - Other minor bugs Test Plan: Ran lipsum for a while without any fatals Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: epriestley, jhurwitz, Korvin Differential Revision: https://secure.phabricator.com/D13559 --- .../paste/lipsum/PhabricatorPasteTestDataGenerator.php | 7 ++++--- .../lipsum/PhabricatorPholioMockTestDataGenerator.php | 6 +++++- .../lipsum/PhabricatorProjectTestDataGenerator.php | 9 ++++----- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php b/src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php index 744a98b621..60c75083b6 100644 --- a/src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php +++ b/src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php @@ -10,7 +10,8 @@ final class PhabricatorPasteTestDataGenerator ); public function generate() { - $authorphid = $this->loadPhabrictorUserPHID(); + $author = $this->loadPhabrictorUser(); + $authorphid = $author->getPHID(); $language = $this->generateLanguage(); $content = $this->generateContent($language); $title = $this->generateTitle($language); @@ -24,12 +25,12 @@ final class PhabricatorPasteTestDataGenerator $policy = $this->generatePolicy(); $filephid = $paste_file->getPHID(); $parentphid = $this->loadPhabrictorPastePHID(); - $paste = id(new PhabricatorPaste()) + $paste = PhabricatorPaste::initializeNewPaste($author) ->setParentPHID($parentphid) - ->setAuthorPHID($authorphid) ->setTitle($title) ->setLanguage($language) ->setViewPolicy($policy) + ->setEditPolicy($policy) ->setFilePHID($filephid) ->save(); return $paste; diff --git a/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php b/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php index 2601284408..a2fb3b38fb 100644 --- a/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php +++ b/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php @@ -92,7 +92,11 @@ final class PhabricatorPholioMockTestDataGenerator $quantity = min($quantity, count($images)); if ($quantity) { - foreach (array_rand($images, $quantity) as $random) { + $random_images = $quantity === 1 ? + array(array_rand($images, $quantity)) : + array_rand($images, $quantity); + + foreach ($random_images as $random) { $rand_images[] = $images[$random]->getPHID(); } } diff --git a/src/applications/project/lipsum/PhabricatorProjectTestDataGenerator.php b/src/applications/project/lipsum/PhabricatorProjectTestDataGenerator.php index fd797ca1fd..0462bdd790 100644 --- a/src/applications/project/lipsum/PhabricatorProjectTestDataGenerator.php +++ b/src/applications/project/lipsum/PhabricatorProjectTestDataGenerator.php @@ -9,15 +9,13 @@ final class PhabricatorProjectTestDataGenerator $title = $this->generateTitle(); $author = $this->loadPhabrictorUser(); $author_phid = $author->getPHID(); - $project = id(new PhabricatorProject()) - ->setName($title) - ->setAuthorPHID($author_phid); + $project = PhabricatorProject::initializeNewProject($author) + ->setName($title); $this->addTransaction( PhabricatorProjectTransaction::TYPE_NAME, $title); - $this->addTransaction( - PhabricatorProjectTransaction::TYPE_MEMBERS, + $project->attachMemberPHIDs( $this->loadMembersWithAuthor($author_phid)); $this->addTransaction( PhabricatorProjectTransaction::TYPE_STATUS, @@ -35,6 +33,7 @@ final class PhabricatorProjectTestDataGenerator $editor = id(new PhabricatorProjectTransactionEditor()) ->setActor($author) ->setContentSource(PhabricatorContentSource::newConsoleSource()) + ->setContinueOnNoEffect(true) ->applyTransactions($project, $this->xactions); return $project->save();