Last active
March 13, 2017 20:29
-
-
Save yahyaerturan/180f01ad0cf924aa44da5e69b7547556 to your computer and use it in GitHub Desktop.
CI3 Fake Date Dumper with Intervals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# Creates an array first with given numbers | |
# Dumps it to db with 250 records/insert intervals | |
# You may need to adjust your php settings: | |
# ini_set('memory_limit', '1024M'); | |
# ini_set('max_execution_time', 300); //300 seconds = 5 minutes | |
/** | |
* Users Seeds | |
* @param integer $number_of_users | |
*/ | |
public function seed_users_users($number_of_users = 200000) | |
{ | |
$_tbl = 'v_users'; | |
$data = array(); | |
for ($i=0; $i < $number_of_users; $i++) { | |
$faker = Faker\Factory::create(); | |
$data[$i] = new stdClass(); | |
$data[$i]->last_name = $faker->lastName; | |
$data[$i]->username = $faker->userName; | |
$data[$i]->password = $faker->password(8); | |
$data[$i]->salt = $faker->password(24); | |
$data[$i]->sex = $faker->randomElement(array ('m','f','u')); | |
switch ($data[$i]->sex) { | |
case "m": | |
$data[$i]->first_name = $faker->firstNameMale; | |
break; | |
case "f": | |
$data[$i]->first_name = $faker->firstNameFemale; | |
break; | |
default: | |
$data[$i]->first_name = $faker->firstName; | |
} | |
$data[$i]->birthday = $faker->dateTimeBetween('-30 years', '-20 years') | |
->format('Y-m-d'); | |
$data[$i]->tcno = null; | |
$data[$i]->last_login = null; | |
$data[$i]->current_login = null; | |
$data[$i]->created_at = $faker->dateTimeBetween('-3 months', 'now') | |
->format('Y-m-d H:i:s'); | |
$data[$i]->updated_at = null; | |
$data[$i]->deleted_at = null; | |
$data[$i]->suspended_at = null; | |
$data[$i]->banned_at = null; | |
$data[$i]->promo_code = null; | |
$data[$i]->system_messages_synced_at = null; | |
$data[$i]->group_id = $faker->numberBetween(1,8); | |
$data[$i]->role_id = $faker->numberBetween(1,6); | |
$data[$i]->is_opt_in = $faker->boolean(70); | |
} | |
$this->db->truncate($_tbl); | |
$partial_counter = 1; | |
$global_counter = 1; | |
$total_count = count($data); | |
if($total_count > 250) { | |
$partial = array(); | |
$last_lot = $total_count % 250; | |
foreach ($data as $row) { | |
$partial[$partial_counter] = $row; | |
if (($partial_counter % 250) == 0) { | |
$this->db->insert_batch($_tbl, $partial); | |
$partial = array(); | |
$partial_counter = 0; | |
} | |
if($last_lot) { | |
if($global_counter == $total_count) { | |
$this->db->insert_batch($_tbl, $partial); | |
$partial = array(); | |
$partial_counter = 0; | |
} | |
} | |
$partial_counter++; | |
$global_counter++; | |
} | |
} else { | |
foreach ($data as $row) { | |
$partial[$global_counter] = $row; | |
if($global_counter == $total_count) { | |
$this->db->insert_batch($_tbl, $partial); | |
} | |
$global_counter++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment