/** * Execute the console command. * * @return mixed */ public function handle() { $first_name = $this->option('first_name'); $last_name = $this->option('last_name'); $username = $this->option('username'); $email = $this->option('email'); $password = $this->option('password'); $show_in_list = $this->argument('show_in_list'); if ($first_name == '' || $last_name == '' || $username == '' || $email == '' || $password == '') { $this->info('ERROR: All fields are required.'); } else { $user = new \App\Models\User(); $user->first_name = $first_name; $user->last_name = $last_name; $user->username = $username; $user->email = $email; $user->permissions = '{"admin":1,"user":1,"superuser":1,"reports.view":1, "licenses.keys":1}'; $user->password = bcrypt($password); $user->activated = 1; if ($show_in_list == 'false') { $user->show_in_list = 0; } if ($user->save()) { $this->info('New user created'); $user->groups()->attach(1); } else { $this->info('Admin user was not created'); $errors = $user->getErrors(); foreach ($errors->all() as $error) { $this->info('ERROR:' . $error); } } } }
/** * Returns the current logged in user * * @return array|null */ function loggedin_user() { //User is not lgged in if (!isLoggedIn()) { //we return null return null; } //Check if we have user id if (!isset($_SESSION['user_id']) || $_SESSION['user_id'] == '' || $_SESSION['user_id'] == null) { //Return null return null; } //Create new user object $user = new App\Models\User(); //Get user id $user_id = $_SESSION['user_id']; //Get the user $results = $user->query("SELECT * FROM users WHERE id = '" . $user_id . "'"); //We got the results if ($results != false) { //Return the current user row return $results[0]; } else { //No user found //return null return null; } }
public function action() { $this->view->errors = array(); // Si la requète est en POST if ($this->request->isPost()) { // Récupère les données du formulaire $formData = $this->request->getParams(); // puis valide les données du formulaire $errors = array(); $filterOptions = array('maxLength' => 40); if (!array_key_exists('inputName', $formData) || false === \My\DataFilter::isValidString($formData['inputName'], $filterOptions)) { $errors[] = 'Le champ "Nom" est invalide'; } if (!array_key_exists('inputLogin', $formData) || false === \My\DataFilter::isValidString($formData['inputLogin'], $filterOptions)) { $errors[] = 'Le champ "Identifiant" est invalide'; } if (!array_key_exists('inputEmail', $formData) || false === \My\DataFilter::isValidEmail($formData['inputEmail'])) { $errors[] = 'Le champ "E-mail" est invalide'; } $this->view->errors = $errors; if (0 === count($errors)) { $user = new \App\Models\User(); $user->setName($formData['inputName'])->setLogin($formData['inputLogin'])->setEmail($formData['inputEmail']); $bd = new \App\Models\Mappers\User('mysql:dbname=throne;host=127.0.0.1', 'root', '0000'); $this->view->success = $bd->save($user); // redirection en cas de success vers l'index if ($this->view->success) { // todo header('location: index.phtml'); } } } }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('users')->delete(); $user = new App\Models\User(); $user->username = "******"; $user->email = "*****@*****.**"; $user->password = bcrypt("test"); $user->save(); $profile = new App\Models\Profile(); $user->profile()->save($profile); $user = new App\Models\User(); $user->username = "******"; $user->email = "*****@*****.**"; $user->password = bcrypt("test"); $user->save(); $profile = new App\Models\Profile(); $user->profile()->save($profile); $user = new App\Models\User(); $user->username = "******"; $user->email = "*****@*****.**"; $user->password = bcrypt("test"); $user->save(); $profile = new App\Models\Profile(); $user->profile()->save($profile); $user = new App\Models\User(); $user->username = "******"; $user->email = "*****@*****.**"; $user->password = bcrypt("test"); $user->save(); $profile = new App\Models\Profile(); $user->profile()->save($profile); }
public function find($id) { // Fausse récupération en BDD (mock, simulation) $userData = array('id' => 3, 'name' => 'Utilisateur1', 'email' => '*****@*****.**', 'login' => 'user1'); $user = new \App\Models\User(); $user->setId($userData['id'])->setName($userData['name'])->setEmail($userData['email'])->setLogin($userData['login']); return $user; }
function GenerateUser($username, $password) { global $database; $user = new \App\Models\User($database); $user->CreateNew($username, $password); $user->Save(); echo "User: {$username} created with password: {$password}"; }
/** * Run the database seeds. * * @return void */ public function run() { $user = new \App\Models\User(); $user->email = "*****@*****.**"; $user->password = \Hash::make("admin"); $user->save(); $role = \App\Models\Role::where("key", "=", "admin")->first(); $user->roles()->attach($role->id); }
protected function prepareUser() { if (!($id = \Components\Session::getSession('user_id'))) { exit(header('Location: /account/authorize')); } $user = new \App\Models\User(); $this->user = $user->initRel(['country', 'group'])->findByPk($id)->getValuesAllField(); $this->setVar('user', $this->user); }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('users')->delete(); $user = new \App\Models\User(); $user->email = "*****@*****.**"; $user->username = "******"; $user->password = \Hash::make("admin"); $user->save(); $user->roles()->save(Role::where("key", "=", "admin")->first()); }
public function postIndex(Request $request) { $titleAction = 'Update Profile'; $inputs = $request->all(); $id = $this->id; $userValidation = new \App\Models\User(); $validation = \Validator::make($inputs, $userValidation->rules($id)); if ($validation->fails()) { return redirect()->back()->withErrors($validation)->withInfo('something error')->withInput(); } $values = ['role_id' => $request->role_id, 'email' => $request->email, 'name' => $request->name, 'password' => \Hash::make($request->password), 'firstname' => $request->firstname, 'lastname' => $request->lastname, 'gender' => $request->gender, 'address' => $request->address, 'phone' => $request->phone]; $this->model->find($id)->update($values); Helper::history('Update His Profile', '', $values); return redirect(Helper::urlAction('index'))->withMessage('Data has been updated!'); }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('users')->truncate(); // Create default administrator user App\Models\User::create(array('name' => 'Administrator', 'email' => '*****@*****.**', 'password' => bcrypt('p4ssw0rd'), 'id_user_role' => 1)); factory(App\Models\User::class, 15)->create(); }
public function run() { DB::table('suppliers')->delete(); DB::table('categories')->delete(); $categories = [['slug' => 'otomotif', 'name' => 'Otomotif'], ['slug' => 't-shirt', 'name' => 'T-Shirt', 'childs' => [['slug' => 'woman', 'name' => 'Woman'], ['slug' => 'man', 'name' => 'Man']]], ['slug' => 'electronic', 'name' => 'Electronic', 'childs' => [['slug' => 'laptop', 'name' => 'Laptop'], ['slug' => 'handphone', 'name' => 'Handphone']]]]; $categories = collect($categories)->map(function ($cat) { $category = App\Models\Category::create(['slug' => $cat['slug'], 'name' => $cat['name']]); if (array_key_exists('childs', $cat)) { foreach ($cat['childs'] as $cate) { App\Models\Category::create(['slug' => $cat['slug'], 'name' => $cat['name'], 'parent_id' => $category->id]); } } return $category; }); $users = App\Models\User::all(); $users->each(function ($user) use($categories) { $suppliers = factory(App\Models\Supplier::class, 10)->create(); $suppliers->each(function ($supplier) use($categories, $user) { $supplier->users()->attach($user); $cat_ids = $categories->pluck('id'); $cat_pick = $cat_ids->random(); factory(App\Models\Product::class, 15)->create(['supplier_id' => $supplier->id, 'category_id' => $cat_pick]); }); }); }
public function findByUsernameOrCreateGoogle($userData) { //dd($userData); // protected $fillable = ['name', 'email', 'password', 'blocked', 'banned', 'confirmed', 'activated']; if ($userData->name == null) { $userData->name = $userData->nickname; } if ($userData->email == null) { $userData->email = $userData->nickname; } if ($userData->avatar == null) { $userData->avatar = Config::get('kagi.kagi_avatar', 'assets/images/usr.png'); } $date = date("Y-m-d H:i:s"); $name = $userData->name; $email = $userData->email; $avatar = $userData->avatar; $check = $this->checkUserExists($name, $email); //dd($check); if ($check == null) { User::firstOrCreate(['name' => $name, 'email' => $email, 'avatar' => $avatar, 'activated_at' => date("Y-m-d H:i:s"), 'blocked' => 0, 'banned' => 0, 'confirmed' => 1, 'activated' => 1, 'activated_at' => $date, 'last_login' => $date, 'avatar' => $avatar, 'confirmation_code' => md5(microtime() . Config::get('app.key'))]); $check_again = $this->checkUserExists($name, $email); //dd($check_again->id); $user = $this->user->find($check_again->id); $user->syncRoles([Config::get('kagi.default_role')]); \Event::fire(new \ProfileWasCreated($check_again)); \Event::fire(new \EmployeeWasCreated($check_again)); return User::firstOrCreate(['name' => $name, 'email' => $email]); } else { //dd($check); $this->touchLastLogin($check->id); return User::firstOrCreate(['name' => $name, 'email' => $email]); } }
/** * @test */ public function it_deactivates_the_business() { $this->arrangeBusinessWithOwner(); $this->assertCount(1, $this->owner->fresh()->businesses); $this->actingAs($this->owner); $this->call('DELETE', route('manager.business.destroy', $this->business)); $this->assertCount(0, $this->owner->fresh()->businesses); }
/** * Run the database seeds. * * @return void */ public function run() { App\Models\Question::truncate(); $users = App\Models\User::all(); factory('App\\Models\\Question', 200)->create()->each(function ($question) use($users) { $question->user()->associate($users->random())->save(); }); }
function register($request, $response, $args) { if ($this->container->get('authenticator')->hasIdentity()) { return $response->withRedirect($this->container->router->pathFor('home')); } $params = $request->getParsedBody(); if ($request->isPost()) { $_SESSION['register_params'] = $params; if ($this->container->registerValidation->hasErrors()) { $errors = $this->container->registerValidation->getErrors(); $error_messages = []; foreach ($errors as $key => $value) { $this->container->flash->addMessage('Error', str_replace("\"\"", ucfirst($key), $value[0])); } return $response->withHeader('Location', $this->container->router->pathFor('register')); } $user = \App\Models\User::where('email', '=', $params['email'])->first(); // User exist if ($user) { $this->container->flash->addMessage("Error", 'User already exist.'); $params['title'] = 'Register'; return $this->container->view->render($response, 'register.phtml', $params); } // Insert new user $user = new \App\Models\User(); $user->email = $params['email']; $user->password = password_hash($params['password'], PASSWORD_DEFAULT); $result = $user->save(); if ($result) { // Create user profile $user_profile = new \App\Models\UserProfile(); $user_profile->first_name = $params['first_name']; $user_profile->last_name = $params['last_name']; $user->profile()->save($user_profile); $this->container->flash->addMessage("Success", 'User added.'); return $response->withRedirect($this->container->router->pathFor('login')); } exit; } $register_params = ['first_name' => '', 'last_name' => '', 'email' => '', 'password' => '', 'confirm_password' => '']; if (isset($_SESSION['register_params'])) { $register_params = $_SESSION['register_params']; } unset($_SESSION['register_params']); return $this->container->view->render($response, 'register.phtml', ['title' => 'Register', 'params' => $register_params]); }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker::create(); $adminIds = App\Models\User::all()->where('is_admin', 1)->lists('id'); //echo('Investor Ids'); //var_dump($investorIds); foreach ($adminIds as $id) { //factory('App\Models\Investor', $id)->create(); Admin::create(['user_id' => $id, 'fname' => $faker->firstName, 'lname' => $faker->lastName, 'home_street' => $faker->streetAddress, 'home_city' => $faker->city, 'home_state' => $faker->state, 'home_zip' => $faker->postcode, 'home_phone' => $faker->phoneNumber, 'security_level' => $faker->numberBetween($min = 5, $max = 15)]); } }
/** * Run the database seeds. * * @return void */ public function run() { $adminRole = App\Models\Role::where('slug', 'admin')->first(); $userRole = App\Models\Role::where('slug', 'user')->first(); $adminRole->permissions()->sync(App\Models\Permission::all()->lists('id')->toArray()); $userRole->permissions()->sync(App\Models\Permission::whereIn('slug', ['permission.index', 'role.index'])->lists('id')->toArray()); $admin = App\Models\User::where('email', '*****@*****.**')->first(); $user = App\Models\User::where('email', '*****@*****.**')->first(); $admin->roles()->sync(App\Models\Role::where('slug', 'admin')->lists('id')->toArray()); $user->roles()->sync(App\Models\Role::where('slug', 'user')->lists('id')->toArray()); }
/** * Run the database seeds. * * @return void */ public function run() { try { // DB::table('osu_favouritemaps')->delete(); // DB::table('osu_user_beatmap_playcount')->delete(); // DB::table('osu_leaders')->delete(); $allusers = App\Models\User::all()->toArray(); $userids = []; for ($ct = 0; $ct < count($allusers); $ct++) { $userids[] = $allusers[$ct]['user_id']; } // FAVOURITE BEATMAPS AND BEATMAP PLAYCOUNTS FOR EACH USER foreach (App\Models\User::all() as $usr) { $bms = $usr->scoresBestOsu()->get(); if (count($bms) < 1) { $this->command->info('Can\'t seed favourite maps, map playcounts or leaders due to having no beatmap data.'); return; } $usr_id = $usr->user_id; foreach ($bms as $bm) { DB::table('osu_favouritemaps')->where('user_id', $usr_id)->where('beatmapset_id', $bm['beatmapset_id'])->delete(); $fav = new App\Models\FavouriteBeatmapSet(); $fav->beatmapset_id = $bm['beatmapset_id']; $fav->user_id = $usr_id; $fav->save(); // Add a random couple few first place ranks $bm = $bms[rand(0, count($bms) - 1)]; DB::table('osu_user_beatmap_playcount')->where('user_id', $usr_id)->where('beatmap_id', $bm['beatmap_id'])->delete(); $playcount = new App\Models\BeatmapPlaycount(); $playcount->user_id = $usr_id; $playcount->beatmap_id = $bm['beatmap_id']; $playcount->playcount = rand(0, 1500); $playcount->save(); $bm = $bms[rand(0, count($bms) - 1)]; if (DB::table('osu_leaders')->where('beatmap_id', $bm['beatmap_id'])->first()) { $bm = $bms[rand(0, count($bms) - 1)]; // try once more if (DB::table('osu_leaders')->where('beatmap_id', $bm['beatmap_id'])->first()) { DB::table('osu_leaders')->where('beatmap_id', $bm['beatmap_id'])->delete(); } } $leader = new App\Models\BeatmapLeader\Osu(); $leader->beatmap_id = $bm['beatmap_id']; $leader->user_id = $usr_id; $leader->score_id = $bm['score_id']; $leader->save(); } } } catch (\Illuminate\Database\QueryException $e) { $this->command->error("Error: Unable to save User Profile Data\r\n" . $e->getMessage()); } catch (Exception $ex) { $this->command->error("Error: Unable to save User Profile Data\r\n" . $ex->getMessage()); } }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('subscribes')->truncate(); $list = collect()->merge(App\Models\Question::all())->merge(App\Models\Tag::all()); $users = App\Models\User::all(); $list->each(function ($item) use($users) { for ($i = 0, $count = rand(0, 10); $i < $count; $i++) { $item->subscribers()->attach($users->random()); } }); }
/** * Run the database seeds. * * @return void */ public function run() { App\Models\Answer::truncate(); $users = App\Models\User::all(); App\Models\Question::all()->each(function ($question) use($users) { for ($i = 0, $count = rand(0, 5); $i < $count; $i++) { $question->answers()->save($answer = factory('App\\Models\\Answer')->create()); $question->update(['is_resolved' => $answer->is_solution]); $answer->user()->associate($users->random())->save(); } }); }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker::create(); $foundersIds = App\Models\User::all()->where('is_founder', 1)->lists('id'); //echo('Founder Ids'); //var_dump($foundersIds); foreach ($foundersIds as $id) { //factory('App\Models\Investor', $id)->create(); //TODO: change faker state to country Founder::create(['user_id' => $id, 'fname' => $faker->firstName, 'lname' => $faker->lastName, 'company_name' => $faker->company, 'company_street' => $faker->streetAddress, 'company_city' => $faker->city, 'company_state' => $faker->state, 'company_zip' => $faker->postcode, 'company_phone' => $faker->phoneNumber, 'company_industry' => $faker->sentence(), 'company_mktcap' => $faker->numberBetween($min = 1000, $max = 1000000)]); } }
/** * Run the database seeds. * * @return void */ public function run() { App\Models\Comment::truncate(); $list = collect()->merge(App\Models\Question::all())->merge(App\Models\Answer::all()); $users = App\Models\User::all(); $list->each(function ($item) use($users) { for ($i = 0, $count = rand(0, 5); $i < $count; $i++) { $item->comments()->save($comment = factory('App\\Models\\Comment')->create()); $comment->user()->associate($users->random())->save(); } }); }
public function run() { // Disable foreign key check for this connection. DB::statement('SET FOREIGN_KEY_CHECKS=0;'); // Delete all records. DB::table('users')->delete(); // Reset AUTO_INCREMENT. DB::table('users')->truncate(); // Dev user. App\Models\User::create(['email' => '*****@*****.**', 'password' => '$2y$10$t6q81nz.XrMrh20NHDvxUu/szwHBwgzPd.01e8uuP0qVy0mPa6H/e', 'first_name' => 'L5', 'last_name' => 'App', 'username' => 'l5-app', 'is_email_verified' => 1]); // Dummy users. TestDummy::times(10)->create('App\\Models\\User'); }
/** * @test */ public function test_follow_each_other() { $follow_input = ['follower_id' => 1, 'followee_id' => 2]; // follow test $response = $this->action('POST', 'UserController@postToggleFollow', [], $follow_input); $result = $response->getData(); $this->assertTrue($result->is_follow); $user1 = App\Models\User::find(1); $this->call('GET', "/{$user1->username}/followings"); $this->assertResponseOk(); $this->assertViewHas('followings'); // then unfollow test $response = $this->action('POST', 'UserController@postToggleFollow', [], $follow_input); $result = $response->getData(); $this->assertFalse($result->is_follow); }
public function likes(\AcceptanceTester $I) { $answer = App\Models\Answer::get()->random(); $user = App\Models\User::get()->random(); \Auth::login($user); $likes = $answer->likes->count(); $I->wantTo('like answer'); $I->amOnRoute('q', ['id' => $answer->question->id]); $I->see($answer->question->title); $c = $likes ? (int) $I->grabTextFrom('li#answer_' . $answer->id . ' a.btn_like .like_count') : 0; $I->assertEquals($likes, $c); $I->click('li#answer_' . $answer->id . ' a.btn_like'); $I->amOnRoute('q', ['id' => $answer->question->id]); $answer = App\Models\Answer::find($answer->id); $I->assertEquals($likes + 1, $answer->likes->count()); }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('answer_likes')->truncate(); $users = App\Models\User::get(); App\Models\Answer::all()->each(function ($answer) use($users) { if (rand(0, 10) < 6) { return; } $random_users = ($count = rand(1, 5)) ? $users->random($count) : []; $random_users = $count == 1 ? [$random_users] : $random_users->all(); foreach ($random_users as $user) { if ($answer->user->id == $user->id) { continue; } $answer->likes()->attach($user->id); } }); }
/** * Run the database seeds. * * @return void */ public function run() { if (App\Models\User::count() < 1) { $publicPath = env('PUBLIC_PATH'); $SuperAdmin = ['name' => 'Razi', 'email' => '*****@*****.**', 'username' => 'razi', 'password' => bcrypt('1234'), 'date_of_birth' => '1992-02-01', 'phone' => '9746730324', 'address' => 'kallayi House, Kooriyad, Indianoor PO, Kottakkal (via), Malappuram (Dt), Kerala (State), India', 'gender' => 'M', 'avatar' => url($publicPath . 'uploads/avatar/razi/razi.jpg'), 'user_type_id' => '5', 'school_id' => '2', 'status' => 'ACTIVE']; $user = App\Models\User::create($SuperAdmin); $SuperAdmin = ['designation' => 'Developer', 'user_id' => $user->id]; App\Models\Foundation::create($SuperAdmin); $Student = ['name' => 'Aysha Nazrin', 'email' => '*****@*****.**', 'username' => 'aysha', 'password' => bcrypt('1234'), 'date_of_birth' => '2000-02-02', 'phone' => '9956656525', 'address' => 'Velliveyil House, Eranhippalam PO, Calicut', 'gender' => 'F', 'avatar' => 'http://localhost/pschool/public/uploads/avatar/aysha/Ayshatest.png', 'user_type_id' => '1', 'school_id' => '1', 'status' => 'ACTIVE']; $user = App\Models\User::create($Student); $StudentDetails = ['course_school_id' => '1', 'roll_no' => '2', 'admission_no' => '1001', 'year_of_admission' => '2006', 'user_id' => $user->id]; App\Models\Student::create($StudentDetails); $Staff = ['name' => 'Ishaq Sheikh', 'email' => '*****@*****.**', 'username' => 'ishaq', 'password' => bcrypt('1234'), 'date_of_birth' => '1989-12-22', 'phone' => '9857645696', 'address' => 'Good House, Kadampuzha PO, Malappuram', 'gender' => 'M', 'avatar' => 'http://localhost/pschool/public/uploads/avatar/ishaq/ishaqTest.png', 'user_type_id' => '2', 'school_id' => '1', 'status' => 'ACTIVE']; $user = App\Models\User::create($Staff); $StaffDetails = ['department' => 'Sociology', 'user_id' => $user->id]; App\Models\Staff::create($StaffDetails); } else { // factory('App\Models\User')->create(); } }
/** * Run the database seeds. * * @return void */ public function run() { /* [ErrorException] Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, string given, called in /home/vagrant/group4-project/vendor/laravel/framework/ src/Illuminate/Database/Query/Grammars/Grammar.php on line 654 and defined foreach($investorIds as $id) { factory('App\Models\Investor',10, $id)->create(); } */ $faker = Faker::create(); $investorIds = App\Models\User::all()->where('is_investor', 1)->lists('id'); //echo('Investor Ids'); //var_dump($investorIds); foreach ($investorIds as $id) { //factory('App\Models\Investor', $id)->create(); Investor::create(['user_id' => $id, 'fname' => $faker->firstName, 'lname' => $faker->lastName, 'profile_name' => $faker->colorName, 'street' => $faker->streetAddress, 'city' => $faker->city, 'state' => $faker->state, 'zip' => $faker->postcode, 'phone' => $faker->phoneNumber, 'invst_objective' => $faker->sentence(), 'invst_amount_total' => $faker->randomFloat($nbMaxDecimals = 2, $min = 100.0, $max = 100000.0)]); } }
/** * Run the database seeds. * * @return void */ public function run() { $beatmaps_array = []; $beatmapset_array = []; $overbeatmaps = []; $overbeatmapsets = []; $base_url = 'https://osu.ppy.sh/api/'; $api_key = env('OSU_API_KEY', null); if (empty($api_key)) { $this->command->error('Error: No OSU_API_KEY value set in .env file. Can\'t seed beatmap data!'); return; } $api = '&k=' . $api_key; $users = App\Models\User::orderByRaw('RAND()')->get()->toArray(); if (count($users) < 1) { $users = [['user_id' => 1]]; } try { $beatmaps = json_decode(file_get_contents($base_url . 'get_beatmaps?since=2016-01-01%2000:00:00' . $api)); $last_beatmapset = null; $beatmap_diff_names = []; $beatmapset_versions = 0; $set_playcount = 0; $number_of_beatmaps = count($beatmaps); $i = 0; $first_map = true; $last_map = false; foreach ($beatmaps as $bm) { $make_new_set = false; if ($i === $number_of_beatmaps - 1) { $make_new_set = true; $last_map = true; } // Here we are going to check if the current beatmap belongs to a new set, and make the set if necessary if ($last_beatmapset === $bm->beatmapset_id || $first_map === true) { ++$beatmapset_versions; $beatmap_diff_names[] = $bm->version . '@' . $bm->mode; $set_playcount += $bm->playcount; } else { $make_new_set = true; } if ($make_new_set === true) { if ($last_map === true) { $the_beatmap = $bm; } else { $the_beatmap = $previous_beatmap; } // Create new beatmapset $set = \App\Models\BeatmapSet::where('beatmapset_id', $the_beatmap->beatmapset_id)->first(); if ($set) { $set->delete(); $overbeatmapsets[] = $the_beatmap->beatmapset_id; } $beatmap_diff_names = implode(',', $beatmap_diff_names); $set = new \App\Models\BeatmapSet(); $set->beatmapset_id = $the_beatmap->beatmapset_id; $set->creator = $the_beatmap->creator; $set->artist = $the_beatmap->artist; $set->title = $the_beatmap->title; $set->displaytitle = $the_beatmap->title; $set->source = $the_beatmap->source; $set->tags = $the_beatmap->tags; $set->bpm = $the_beatmap->bpm; $set->approved = $the_beatmap->approved; $set->approved_date = $the_beatmap->approved_date; $set->genre_id = $the_beatmap->genre_id; $set->language_id = $the_beatmap->language_id; $set->versions_available = $beatmapset_versions; $set->difficulty_names = $beatmap_diff_names; $set->play_count = $set_playcount; $set->favourite_count = $the_beatmap->favourite_count; $set->user_id = array_rand_val($users)['user_id']; $set->save(); $set->difficulty_names = $beatmap_diff_names; $beatmapset_array[] = $set; $set_playcount = $bm->playcount; $beatmapset_versions = 1; $beatmap_diff_names = [$bm->version . '@' . $bm->mode]; } if ($new_bm = \App\Models\Beatmap::where('beatmap_id', $bm->beatmap_id)->first()) { $new_bm->delete(); $overbeatmaps[] = $new_bm; } $new_bm = new \App\Models\Beatmap(); $new_bm->beatmap_id = $bm->beatmap_id; $new_bm->beatmapset_id = $bm->beatmapset_id; $new_bm->filename = $bm->beatmapset_id . ' ' . $bm->artist . ' - ' . $bm->title . '.osz'; $new_bm->checksum = $bm->file_md5; $new_bm->version = $bm->version; $new_bm->total_length = $bm->total_length; $new_bm->hit_length = $bm->hit_length; $new_bm->countTotal = $bm->max_combo !== null ? $bm->max_combo : 1500; $new_bm->countNormal = round(intval($bm->max_combo) - 0.2 * intval($bm->max_combo)); $new_bm->countSlider = round(intval($bm->max_combo) - 0.8 * intval($bm->max_combo)) - 1; $new_bm->countSpinner = 1; $new_bm->diff_drain = $bm->diff_drain; $new_bm->diff_size = $bm->diff_size; $new_bm->diff_overall = $bm->diff_overall; $new_bm->diff_approach = $bm->diff_approach; $new_bm->playmode = $bm->mode; $new_bm->approved = $bm->approved; $new_bm->difficultyrating = $bm->difficultyrating; $new_bm->playcount = $bm->playcount; $new_bm->passcount = $bm->passcount; $new_bm->user_id = array_rand_val($users)['user_id']; $new_bm->save(); $beatmaps_array[] = $new_bm; if ($first_map === true) { $first_map = false; } $last_beatmapset = $bm->beatmapset_id; $previous_beatmap = $bm; ++$i; } // end foreach beatmap $this->command->info('Saved ' . strval(count($beatmaps_array)) . ' Beatmaps (Overwritten ' . strval(count($overbeatmaps)) . ').'); $this->command->info('Saved ' . strval(count($beatmapset_array)) . ' Beatmap Sets (Overwritten ' . strval(count($overbeatmapsets)) . ').'); } catch (\Illuminate\Database\QueryException $e) { $this->command->error("DB Error: Unable to save Beatmap Data\r\n" . $e->getMessage()); } catch (Exception $ex) { $this->command->error("Error: Unable to save Beatmap Data\r\n" . $ex->getMessage()); } }