Commit ccf8ceb9 authored by Tilmann Becker's avatar Tilmann Becker Committed by Matthias Larisch

add more seed

parent ec57e0de
Pipeline #17435705 canceled with stages
......@@ -23,6 +23,8 @@ class SeedCommand extends Command implements CustomCommandInterface
*/
protected $output;
protected $foodsavers = [];
/**
* returns the name of the command.
*
......@@ -54,6 +56,15 @@ class SeedCommand extends Command implements CustomCommandInterface
$this->seed();
}
protected function getRandomUser($number = 1)
{
$rand = array_rand($this->foodsavers, $number);
if ($number === 1) return $this->foodsavers[$rand];
if (count($rand) > 0) return array_intersect_key($this->foodsavers, $rand);
return [];
}
protected function seed()
{
$I = $this->helper;
......@@ -69,7 +80,7 @@ class SeedCommand extends Command implements CustomCommandInterface
'bezirk_id' => $bezirk1,
'about_me_public' => 'hello!'
]);
$I->createOrga('user', false, ['email' => 'userorga@example.com', 'name' => 'Orga', 'bezirk_id' => $bezirk1]);
$userorga = $I->createOrga('user', false, ['email' => 'userorga@example.com', 'name' => 'Orga', 'bezirk_id' => $bezirk1]);
$I->addBezirkMember($bezirk1, $userbot['id'], true);
$I->addBezirkMember($bezirk1, $user2['id']);
......@@ -86,9 +97,10 @@ class SeedCommand extends Command implements CustomCommandInterface
$I->addConversationMessage($userbot['id'], $conv1['id']);
$I->addConversationMessage($userbot['id'], $conv2['id']);
$store = $I->createStore($bezirk1, $conv1['id'], $conv2['id']);
$store = $I->createStore($bezirk1, $conv1['id'], $conv2['id'], ['betrieb_status_id' => 5]);
$I->addStoreTeam($store['id'], $user2['id']);
$I->addStoreTeam($store['id'], $userbot['id'], true);
$I->addRecurringPickup($store['id']);
$theme = $I->addForumTheme($bezirk1, $userbot['id']);
$I->addForumThemePost($theme['id'], $user2['id']);
......@@ -97,17 +109,58 @@ class SeedCommand extends Command implements CustomCommandInterface
$I->addFairteilerFollower($user2['id'], $fairteiler['id']);
$I->addFairteilerPost($userbot['id'], $fairteiler['id']);
// load test
foreach (range(0, 200) as $number) {
$saver = $I->createFoodsaver('user', ['bezirk_id' => $bezirk1]);
$I->addBezirkMember($bezirk1, $saver['id']);
$I->addStoreTeam($store['id'], $saver['id']);
$I->addCollector($saver['id'], $store['id']);
$I->addStoreNotiz($saver['id'], $store['id']);
$I->addForumThemePost($theme['id'], $saver['id']);
if ($number > 0 && $number % 100 == 0) {
$this->output->writeln($number);
// create users and collect their ids in a list
$this->foodsavers = [$user2['id'], $userbot['id'], $userorga['id']];
foreach (range(0, 100) as $_) {
$user = $I->createFoodsaver('user', ['bezirk_id' => $bezirk1]);
$this->foodsavers[] = $user['id'];
$I->addBezirkMember($bezirk1, $user['id']);
$I->addStoreTeam($store['id'], $user['id']);
$I->addCollector($user['id'], $store['id']);
$I->addStoreNotiz($user['id'], $store['id']);
$I->addForumThemePost($theme['id'], $user['id']);
}
// create conversations between users
foreach ($this->foodsavers as $user) {
foreach ($this->getRandomUser(10) as $chatpartner) {
if ($user !== $chatpartner) {
$conv = $I->createConversation([$user, $chatpartner]);
$I->addConversationMessage($user, $conv['id']);
$I->addConversationMessage($chatpartner, $conv['id']);
}
}
}
// create more stores
foreach (range(0, 20) as $_) {
// TODO conversations are missing the other store members
$conv1 = $I->createConversation([$userbot['id']], ['name' => 'team']);
$conv2 = $I->createConversation([$userbot['id']], ['name' => 'springer']);
$store = $I->createStore($bezirk1, $conv1['id'], $conv2['id']);
foreach (range(0, 5) as $_) {
$I->addRecurringPickup($store['id']);
}
}
// create foodbaskets
foreach (range(0, 500) as $_) {
$user = $this->getRandomUser();
$foodbasket = $I->createFoodbasket($user);
$commenter = $this->getRandomUser();
$I->addFoodbasketWallpost($commenter, $foodbasket['id']);
}
// create fairteiler
foreach ($this->getRandomUser(50) as $user) {
$fairteiler = $I->createFairteiler($user, $bezirk1);
foreach ($this->getRandomUser(10) as $follower) {
if ($user !== $follower) {
$I->addFairteilerFollower($follower, $fairteiler['id']);
}
$I->addFairteilerPost($follower, $fairteiler['id']);
}
}
}
......
......@@ -27,6 +27,7 @@ class Foodsharing extends \Codeception\Module\Db
DELETE FROM fs_betrieb_team;
DELETE FROM fs_betrieb;
DELETE FROM fs_abholer;
DELETE FROM fs_abholzeiten;
DELETE FROM fs_botschafter;
DELETE FROM fs_theme_post;
DELETE FROM fs_bezirk_has_theme;
......@@ -36,6 +37,8 @@ class Foodsharing extends \Codeception\Module\Db
DELETE FROM fs_fairteiler_follower;
DELETE FROM fs_fairteiler_has_wallpost;
DELETE FROM fs_wallpost;
DELETE FROM fs_basket;
DELETE FROM fs_basket_has_wallpost;
', []);
}
......@@ -144,29 +147,29 @@ class Foodsharing extends \Codeception\Module\Db
public function createStore($bezirk_id, $team_conversation = null, $springer_conversation = null, $extra_params = [])
{
$params = array_merge([
'betrieb_status_id' => 1,
'status' => 1, // same as betrieb_status_id
'betrieb_status_id' => $this->faker->numberBetween(0, 6),
'status' => 1,
'added' => $this->faker->dateTime(),
'plz' => '',
'stadt' => '',
'str' => '',
'hsnr' => '',
'lat' => '',
'lon' => '',
'name' => 'betrieb_' . $this->faker->name(),
'plz' => $this->faker->postcode(),
'stadt' => $this->faker->city(),
'str' => $this->faker->streetAddress(),
'hsnr' => $this->faker->numberBetween(0, 1000),
'lat' => $this->faker->latitude(),
'lon' => $this->faker->longitude(),
'name' => 'betrieb_' . $this->faker->company(),
'status_date' => $this->faker->dateTime(),
'ansprechpartner' => '',
'telefon' => '',
'fax' => '',
'email' => '',
'begin' => '0000-00-00',
'ansprechpartner' => $this->faker->name(),
'telefon' => $this->faker->phoneNumber(),
'fax' => $this->faker->phoneNumber(),
'email' => $this->faker->email(),
'begin' => $this->faker->date('Y-m-d'),
'besonderheiten' => '',
'public_info' => '',
'public_time' => 0,
'ueberzeugungsarbeit' => 0,
'presse' => 0,
'sticker' => 0,
'abholmenge' => 0,
'abholmenge' => $this->faker->numberBetween(0, 70),
'team_status' => 1,
'prefetchtime' => 1209600,
......@@ -241,6 +244,22 @@ class Foodsharing extends \Codeception\Module\Db
return $params;
}
public function addRecurringPickup($store, $extra_params = [])
{
$params = array_merge([
'betrieb_id' => $store,
'dow' => $this->faker->numberBetween(0,6),
'time' => $this->faker->date($format = 'H:i:s', $max = 'now'),
'fetcher' => $this->faker->numberBetween(1,8),
], $extra_params);
$id = $this->haveInDatabase('fs_abholzeiten', $params);
$params['id'] = $id;
return $params;
}
public function createWorkingGroup($name, $extra_params = [])
{
/* 392 is global working groups */
......@@ -439,9 +458,7 @@ class Foodsharing extends \Codeception\Module\Db
'type' => 1,
'infotype' => 1,
], $extra_params);
$id = $this->haveInDatabase('fs_fairteiler_follower', $params);
$params['id'] = $id;
$this->haveInDatabase('fs_fairteiler_follower', $params);
return $params;
}
......@@ -478,6 +495,46 @@ class Foodsharing extends \Codeception\Module\Db
return $params;
}
public function createFoodbasket($user, $bezirk = 241, $extra_params = [])
{
$params = array_merge([
'foodsaver_id' => $user,
'status' => 1,
'time' => $this->faker->dateTime($max = 'now'),
'until' => $this->faker->dateTimeBetween('now', '+14 days'),
'fetchtime' => null,
'description' => $this->faker->realText(200),
'picture' => null,
'tel' => $this->faker->phoneNumber(),
'handy' => $this->faker->phoneNumber(),
'contact_type' => 1,
'location_type' => 0,
'weight' => $this->faker->numberBetween(1, 100),
'lat' => $this->faker->latitude,
'lon' => $this->faker->longitude,
'bezirk_id' => $bezirk,
], $extra_params);
$params['time'] = $this->toDateTime($params['time']);
$params['until'] = $this->toDateTime($params['until']);
$id = $this->haveInDatabase('fs_basket', $params);
$params['id'] = $id;
return $params;
}
public function addFoodbasketWallpost($user, $foodbasket, $extra_params = [])
{
$post = $this->createWallpost($user, $extra_params);
$this->haveInDatabase('fs_basket_has_wallpost', [
'basket_id' => $foodbasket,
'wallpost_id' => $post['id'],
]);
return $post;
}
// =================================================================================================================
// private methods
// =================================================================================================================
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment