From 644b05ec08ff30ec3388cee957d5fe56d73dab3f Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Sun, 1 Mar 2015 09:41:40 +1100 Subject: [PATCH] Minor fix for `lipsum generate` Summary: I was hitting the following error when attempting to use `./bin/lipsum generate`: ``` [2015-02-28 21:55:00] ERROR 2: array_rand(): Second argument has to be between 1 and the number of elements in the array at [/usr/src/phabricator/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php:93] arcanist(head=master, ref.master=d8182cf55d50), phabricator(head=master, ref.master=658175925931), phutil(head=master, ref.master=260e6105dee5) #0 array_rand(array, integer) called at [/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php:93] #1 PhabricatorPholioMockTestDataGenerator::generateImages() called at [/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php:30] #2 PhabricatorPholioMockTestDataGenerator::generate() called at [/src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php:67] #3 PhabricatorLipsumGenerateWorkflow::infinitelyGenerate(array) called at [/src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php:36] #4 PhabricatorLipsumGenerateWorkflow::execute(PhutilArgumentParser) called at [/src/parser/argument/PhutilArgumentParser.php:396] #5 PhutilArgumentParser::parseWorkflowsFull(array) called at [/src/parser/argument/PhutilArgumentParser.php:292] #6 PhutilArgumentParser::parseWorkflows(array) called at [/scripts/lipsum/manage_lipsum.php:21] ``` Test Plan: Ran `./bin/lipsum generate` and received less errors. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin, epriestley Differential Revision: https://secure.phabricator.com/D11908 --- .../lipsum/PhabricatorPholioMockTestDataGenerator.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php b/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php index 0cdf812ee7..a9cfdb6bb6 100644 --- a/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php +++ b/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php @@ -90,11 +90,14 @@ final class PhabricatorPholioMockTestDataGenerator $rand_images = array(); $quantity = rand(2, 10); $quantity = min($quantity, count($images)); - foreach (array_rand($images, $quantity) as $random) { - $rand_images[] = $images[$random]->getPHID(); + + if ($quantity) { + foreach (array_rand($images, $quantity) as $random) { + $rand_images[] = $images[$random]->getPHID(); + } } - // this means you don't have any jpegs yet. we'll - // just use a builtin image + + // This means you don't have any JPEGs yet. We'll just use a built-in image. if (empty($rand_images)) { $default = PhabricatorFile::loadBuiltin( PhabricatorUser::getOmnipotentUser(),