예제 #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create();
     try {
         // DB::table('phpbb_forums')->delete();
         // DB::table('phpbb_topics')->delete();
         // DB::table('phpbb_posts')->delete();
         $forums = [];
         $beatmapCount = App\Models\Beatmapset::count();
         if ($beatmapCount > 0) {
             // Create beatmap threads
             $f = App\Models\Forum\Forum::create(['forum_name' => 'Beatmap Threads', 'forum_desc' => 'Beatmap thread info for beatmaps', 'forum_type' => 0]);
             $f2 = $f->subforums()->save(factory(App\Models\Forum\Forum::class, 'child')->make(['parent_id' => 1, 'forum_name' => 'Beatmap Threads', 'forum_desc' => 'Beatmap thread info for beatmaps']));
             $bms = App\Models\Beatmapset::all();
             foreach ($bms as $set) {
                 $t = $f2->topics()->save(factory(App\Models\Forum\Topic::class)->make(['forum_id' => $f2->forum_id, 'topic_poster' => $set->creator, 'topic_title' => $set->artist . ' - ' . $set->title]));
                 $p = $t->posts()->save(factory(App\Models\Forum\Post::class)->make(['forum_id' => $f2->forum_id, 'poster_id' => $set->user_id, 'post_username' => $set->creator, 'post_subject' => $set->artist . ' - ' . $set->title, 'post_text' => '---------------']));
                 $t->refreshCache();
                 $set->thread_id = $t->topic_id;
                 $set->save();
             }
             $f2->refreshCache();
         }
         // Create 3 forums
         factory(App\Models\Forum\Forum::class, 'parent', 3)->create()->each(function ($f) {
             for ($i = 0; $i < 4; $i++) {
                 // Subforums for each forum.
                 $f2 = $f->subforums()->save(factory(App\Models\Forum\Forum::class, 'child')->make());
                 // Topics for each subforum
                 for ($j = 0; $j < 3; $j++) {
                     $t = $f2->topics()->save(factory(App\Models\Forum\Topic::class)->make(['forum_id' => $f2->forum_id]));
                     // Replies to the topic
                     for ($k = 0; $k < 5; $k++) {
                         $p = $t->posts()->save(factory(App\Models\Forum\Post::class)->make(['forum_id' => $f2->forum_id]));
                     }
                     // Refresh topic cache (updates last post times etc)
                     $t->refreshCache();
                 }
                 // Refresh forum cache
                 $f2->refreshCache();
             }
         });
     } catch (\Illuminate\Database\QueryException $e) {
         echo $e->getMessage() . "\r\n";
     } catch (Exception $ex) {
         echo $ex->getMessage() . "\r\n";
     }
 }
예제 #2
0
파일: ScoreSeeder.php 프로젝트: ppy/osu-web
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // DB::table('osu_scores')->delete();
     // DB::table('osu_scores_high')->delete();
     // DB::table('osu_scores_taiko')->delete();
     // DB::table('osu_scores_taiko_high')->delete();
     // DB::table('osu_scores_fruits')->delete();
     // DB::table('osu_scores_fruits_high')->delete();
     $beatmaps = App\Models\Beatmap::orderByRaw('RAND()')->get();
     $beatmapCount = count($beatmaps);
     if ($beatmapCount === 0) {
         $this->command->info('Can\'t seed Scores due to having no beatmap data.');
         return;
     }
     $faker = Faker::create();
     $users = App\Models\User::all();
     App\Models\Score\Model::unguard();
     $allBeatmapsets = App\Models\Beatmapset::all();
     $possible_ranks = ['A', 'S', 'B', 'SH', 'XH', 'X'];
     foreach ($users as $k => $u) {
         $osuBeatmaps = $beatmaps->where('playmode', 0)->take(20);
         $taikoBeatmaps = $beatmaps->where('playmode', 1)->take(20);
         $fruitsBeatmaps = $beatmaps->where('playmode', 2)->take(20);
         $maniaBeatmaps = $beatmaps->where('playmode', 3)->take(20);
         //add 20 osu! Standard scores
         foreach ($osuBeatmaps as $bm) {
             $bms = $allBeatmapsets->find($bm->beatmapset_id);
             $maxcombo = rand(1, $bm->countTotal);
             $possible_mods = [0, 16, 24, 64, 72];
             // hr, hd/hr, dt, hd/dt
             $sc = App\Models\Score\Osu::create(['user_id' => $u->user_id, 'beatmap_id' => $bm->beatmap_id, 'beatmapset_id' => $bm->beatmapset_id, 'score' => rand(50000, 100000000), 'maxcombo' => $maxcombo, 'count300' => round($maxcombo * 0.8), 'count100' => rand(0, round($maxcombo * 0.15)), 'count50' => rand(0, round($maxcombo * 0.05)), 'countgeki' => round($maxcombo * 0.3), 'countmiss' => round($maxcombo * 0.05), 'countkatu' => round($maxcombo * 0.05), 'enabled_mods' => array_rand_val($possible_mods), 'date' => rand(1451606400, time()), 'pass' => $faker->boolean(85), 'rank' => array_rand_val($possible_ranks)]);
             $sc2 = App\Models\Score\Best\Osu::create(['user_id' => $u->user_id, 'beatmap_id' => $bm->beatmap_id, 'beatmapset_id' => $bm->beatmapset_id, 'score' => rand(50000, 100000000), 'maxcombo' => $maxcombo, 'count300' => round($maxcombo * 0.8), 'count100' => rand(0, round($maxcombo * 0.15)), 'count50' => rand(0, round($maxcombo * 0.05)), 'countgeki' => round($maxcombo * 0.3), 'countmiss' => round($maxcombo * 0.05), 'countkatu' => round($maxcombo * 0.05), 'enabled_mods' => array_rand_val($possible_mods), 'date' => rand(1451606400, time()), 'pp' => $faker->biasedNumberBetween(10, 100) * 1.5 * $bm->difficultyrating, 'rank' => array_rand_val($possible_ranks)]);
         }
         //Taiko scores
         foreach ($taikoBeatmaps as $bm) {
             $bms = $allBeatmapsets->find($bm->beatmapset_id);
             $maxcombo = rand(1, $bm->countTotal);
             $possible_mods = [0, 16, 24, 64, 72];
             $sc3 = App\Models\Score\Taiko::create(['user_id' => $u->user_id, 'beatmap_id' => $bm->beatmap_id, 'beatmapset_id' => $bm->beatmapset_id, 'score' => rand(50000, 100000000), 'maxcombo' => $maxcombo, 'count300' => round($maxcombo * 0.8), 'count100' => rand(0, round($maxcombo * 0.15)), 'count50' => rand(0, round($maxcombo * 0.05)), 'countgeki' => round($maxcombo * 0.3), 'countmiss' => round($maxcombo * 0.05), 'countkatu' => round($maxcombo * 0.05), 'enabled_mods' => array_rand_val($possible_mods), 'date' => rand(1451606400, time()), 'pass' => $faker->boolean(85), 'rank' => array_rand_val($possible_ranks)]);
             $sc4 = App\Models\Score\Best\Taiko::create(['user_id' => $u->user_id, 'beatmap_id' => $bm->beatmap_id, 'beatmapset_id' => $bm->beatmapset_id, 'score' => rand(50000, 100000000), 'maxcombo' => $maxcombo, 'rank' => array_rand_val($possible_ranks), 'count300' => round($maxcombo * 0.8), 'count100' => rand(0, round($maxcombo * 0.15)), 'count50' => rand(0, round($maxcombo * 0.05)), 'countgeki' => round($maxcombo * 0.3), 'countmiss' => round($maxcombo * 0.05), 'countkatu' => round($maxcombo * 0.05), 'enabled_mods' => array_rand_val($possible_mods), 'date' => rand(1451606400, time()), 'pp' => $faker->biasedNumberBetween(10, 100) * 1.3 * $bm->difficultyrating]);
         }
         // end taiko
         //Fruits scores
         foreach ($fruitsBeatmaps as $bm) {
             $bms = $allBeatmapsets->find($bm->beatmapset_id);
             $maxcombo = rand(1, $bm->countTotal);
             $possible_mods = [0, 16, 24, 64, 72];
             $sc5 = App\Models\Score\Fruits::create(['user_id' => $u->user_id, 'beatmap_id' => $bm->beatmap_id, 'beatmapset_id' => $bm->beatmapset_id, 'score' => rand(50000, 100000000), 'maxcombo' => $maxcombo, 'rank' => array_rand_val($possible_ranks), 'count300' => round($maxcombo * 0.8), 'count100' => rand(0, round($maxcombo * 0.15)), 'count50' => rand(0, round($maxcombo * 0.05)), 'countgeki' => round($maxcombo * 0.3), 'countmiss' => round($maxcombo * 0.05), 'countkatu' => round($maxcombo * 0.05), 'enabled_mods' => array_rand_val($possible_mods), 'date' => rand(1451606400, time()), 'pass' => $faker->boolean(85)]);
             $sc6 = App\Models\Score\Best\Fruits::create(['user_id' => $u->user_id, 'beatmap_id' => $bm->beatmap_id, 'beatmapset_id' => $bm->beatmapset_id, 'score' => rand(50000, 100000000), 'maxcombo' => $maxcombo, 'rank' => array_rand_val($possible_ranks), 'count300' => round($maxcombo * 0.8), 'count100' => rand(0, round($maxcombo * 0.15)), 'count50' => rand(0, round($maxcombo * 0.05)), 'countgeki' => round($maxcombo * 0.3), 'countmiss' => round($maxcombo * 0.05), 'countkatu' => round($maxcombo * 0.05), 'enabled_mods' => array_rand_val($possible_mods), 'date' => rand(1451606400, time()), 'pp' => $faker->biasedNumberBetween(10, 100) * 1.3 * $bm->difficultyrating]);
         }
         // end fruits
         //Mania scores
         foreach ($maniaBeatmaps as $bm) {
             $bms = $allBeatmapsets->find($bm->beatmapset_id);
             $maxcombo = rand(1, $bm->countTotal);
             $possible_mods = [0, 16, 24, 64, 72];
             // hr, hd/hr, dt, hd/dt
             $sc7 = App\Models\Score\Mania::create(['user_id' => $u->user_id, 'beatmap_id' => $bm->beatmap_id, 'beatmapset_id' => $bm->beatmapset_id, 'score' => rand(50000, 100000000), 'maxcombo' => $maxcombo, 'rank' => array_rand_val($possible_ranks), 'count300' => round($maxcombo * 0.8), 'count100' => rand(0, round($maxcombo * 0.15)), 'count50' => rand(0, round($maxcombo * 0.05)), 'countgeki' => round($maxcombo * 0.3), 'countmiss' => round($maxcombo * 0.05), 'countkatu' => round($maxcombo * 0.05), 'enabled_mods' => array_rand_val($possible_mods), 'date' => rand(1451606400, time()), 'pass' => $faker->boolean(85)]);
             $sc8 = App\Models\Score\Best\Mania::create(['user_id' => $u->user_id, 'beatmap_id' => $bm->beatmap_id, 'beatmapset_id' => $bm->beatmapset_id, 'score' => rand(50000, 100000000), 'maxcombo' => $maxcombo, 'rank' => array_rand_val($possible_ranks), 'count300' => round($maxcombo * 0.8), 'count100' => rand(0, round($maxcombo * 0.15)), 'count50' => rand(0, round($maxcombo * 0.05)), 'countgeki' => round($maxcombo * 0.3), 'countmiss' => round($maxcombo * 0.05), 'countkatu' => round($maxcombo * 0.05), 'enabled_mods' => array_rand_val($possible_mods), 'date' => rand(1451606400, time()), 'pp' => $faker->biasedNumberBetween(10, 100) * 2 * $bm->difficultyrating]);
         }
         // end mania
     }
     App\Models\Score\Model::reguard();
 }
예제 #3
0
파일: ForumSeeder.php 프로젝트: ppy/osu-web
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create();
     try {
         // Create appropriate forum permissions
         $authOptionIds = [];
         foreach (['f_post', 'f_reply'] as $authOption) {
             $option = new App\Models\Forum\AuthOption();
             $option->auth_option = $authOption;
             $option->save();
             $authOptionIds[] = $option->auth_option_id;
         }
         $beatmapCount = App\Models\Beatmapset::count();
         if ($beatmapCount > 0) {
             // Create beatmap threads
             $f = App\Models\Forum\Forum::create(['forum_name' => 'Beatmap Threads', 'forum_desc' => 'Beatmap thread info for beatmaps', 'forum_type' => 0]);
             $f2 = $f->subforums()->save(factory(App\Models\Forum\Forum::class, 'child')->make(['parent_id' => 1, 'forum_name' => 'Beatmap Threads', 'forum_desc' => 'Beatmap thread info for beatmaps']));
             $bms = App\Models\Beatmapset::all();
             foreach ($bms as $set) {
                 $t = $f2->topics()->save(factory(App\Models\Forum\Topic::class)->make(['forum_id' => $f2->forum_id, 'topic_poster' => $set->creator, 'topic_title' => $set->artist . ' - ' . $set->title]));
                 $p = $t->posts()->save(factory(App\Models\Forum\Post::class)->make(['forum_id' => $f2->forum_id, 'poster_id' => $set->user_id, 'post_username' => $set->creator, 'post_subject' => $set->artist . ' - ' . $set->title, 'post_text' => '---------------']));
                 $t->refreshCache();
                 $set->thread_id = $t->topic_id;
                 $set->save();
             }
             $f2->refreshCache();
         }
         // Create 3 forums
         factory(App\Models\Forum\Forum::class, 'parent', 3)->create()->each(function ($f) {
             for ($i = 0; $i < 4; $i++) {
                 // Subforums for each forum.
                 $f2 = $f->subforums()->save(factory(App\Models\Forum\Forum::class, 'child')->make());
                 // Topics for each subforum
                 for ($j = 0; $j < 3; $j++) {
                     $t = $f2->topics()->save(factory(App\Models\Forum\Topic::class)->make(['forum_id' => $f2->forum_id]));
                     // Replies to the topic
                     for ($k = 0; $k < 5; $k++) {
                         $p = $t->posts()->save(factory(App\Models\Forum\Post::class)->make(['forum_id' => $f2->forum_id]));
                     }
                     // Refresh topic cache (updates last post times etc)
                     $t->refreshCache();
                 }
                 // Refresh forum cache
                 $f2->refreshCache();
             }
         });
         foreach (App\Models\Forum\Forum::all() as $forum) {
             foreach ($authOptionIds as $optionId) {
                 $group = new App\Models\Forum\Authorize();
                 $group->group_id = App\Models\UserGroup::GROUPS['default'];
                 $group->forum_id = $forum->forum_id;
                 $group->auth_option_id = $optionId;
                 $group->auth_setting = 1;
                 $group->save();
             }
         }
     } catch (\Illuminate\Database\QueryException $e) {
         echo $e->getMessage() . "\r\n";
     } catch (Exception $ex) {
         echo $ex->getMessage() . "\r\n";
     }
 }