|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Phinx\Seed\AbstractSeed; |
|
4
|
|
|
|
|
5
|
|
|
class UserSeeder extends AbstractSeed |
|
6
|
|
|
{ |
|
7
|
|
|
|
|
8
|
|
|
public function run() |
|
9
|
|
|
{ |
|
10
|
|
|
$faker = Faker\Factory::create(); |
|
11
|
|
|
$data = []; |
|
12
|
|
|
$flush = 32; |
|
13
|
|
|
$max = 512; |
|
14
|
|
|
$statuses = [ |
|
15
|
|
|
'suspended', // we closed account |
|
16
|
|
|
'closed', // we closed account |
|
17
|
|
|
'cancelled', // user cancelled account |
|
18
|
|
|
'registered', // initial registration |
|
19
|
|
|
'confirmed', // user has confirmed email address - needed for api access |
|
20
|
|
|
]; |
|
21
|
|
|
$groups = ['admin', 'user', 'api', 'user,api', 'admin,user,api']; |
|
22
|
|
|
for ($i = 0; $i < $max; $i++) { |
|
23
|
|
|
$data[] = [ |
|
24
|
|
|
'uuid' => $faker->uuid, |
|
25
|
|
|
'password' => substr(sha1($faker->password),0,15), |
|
26
|
|
|
'email' => $faker->email, |
|
27
|
|
|
'firstname' => $faker->firstName, |
|
28
|
|
|
'lastname' => $faker->lastName, |
|
29
|
|
|
'groups' => $groups[rand(0,4)], |
|
30
|
|
|
'status' => $statuses[rand(0,4)], |
|
31
|
|
|
'password_question' => $faker->sentence(10, true), |
|
32
|
|
|
'password_answer' => $faker->sentence(3), |
|
33
|
|
|
'created' => $faker->dateTimeBetween('-3 years', 'now')->format('Y-m-d H:i:s'), |
|
34
|
|
|
'login_last' => $faker->dateTimeBetween('-3 years', 'now')->format('Y-m-d H:i:s'), |
|
35
|
|
|
'login_count' => rand(1, 1000) |
|
36
|
|
|
]; |
|
37
|
|
|
// flush data to database |
|
38
|
|
|
if (count($data) > $flush) { |
|
39
|
|
|
$this->insert('users', $data); |
|
40
|
|
|
$data = []; |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
if (count($data) > $flush) { |
|
44
|
|
|
$this->insert('users', $data); |
|
45
|
|
|
$data = []; |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|