-
Notifications
You must be signed in to change notification settings - Fork 8
/
ExampleSeederTask.php
141 lines (124 loc) · 2.65 KB
/
ExampleSeederTask.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
App::uses('SeederTaskBase', 'FakeSeeder.Console');
/**
* Example Seeder Task
*/
class ExampleSeederTask extends SeederTaskBase {
/**
* The config key to read, 'FakeSeeder.$_configKey.valueKey'
*
* Does not need to be set, uses the name of the seeder class by default, e.g. "Article" for "ArticleSeederShell".
*
* @var string
*/
protected $_configKey = 'ExampleKey';
/**
* The name of the model to seed
*
* Does not need to be set, uses the name of the seeder class by default, e.g. "Article" for "ArticleSeederTask".
*
* @var string
*/
protected $_modelName = 'NotExample';
/**
* Models to truncate
*
* Does not need to be set, uses the name of the seeder class by default, e.g. "Article" for "ArticleSeederTask".
*
* @var array
*/
protected $_modelsToTruncate = array('SomeModel', 'AnotherModel');
/**
* Fixture records which are processed additionally and before the faked ones
*
* @var array
*/
protected $_fixtureRecords = array(
array(
'id' => 1,
'name' => 'abc',
),
array(
'id' => 2,
'name' => 'def',
),
);
/**
* The seeding mode, optional.
*
* @var null|string
*/
protected $_mode = 'mixed';
/**
* The locale to use for Faker, optional
*
* @var null|int
*/
protected $_locale = 'de_DE';
/**
* Set the minimum record count for a seeder task, null means no minimum.
*
* @var null|int
*/
protected $_minRecords = 100;
/**
* Set the maximum record count for a seeder task, null means no maximum.
*
* @var null|int
*/
protected $_maxRecords = 20000;
/**
* The records to seed, optional
*
* @var null|int
*/
protected $_records = 12345;
/**
* Whether or not to validate the seeding data when saving, optional
*
* @var null|bool|string
* @see Model::saveAll() See for possible values for `validate`.
*/
protected $_validateSeeding = true;
/**
* The seeding number for Faker to use
*
* @var null|bool|int
* @see Generator::seed Faker's seed method.
*/
protected $_seedingNumber = 123456;
/**
* Whether or not to truncate the model , optional.
*
* @var null|bool
*/
protected $_noTruncate = false;
/**
* Set/get the field formatters
*
* {@inheritDoc}
*/
public function fieldFormatters() {
parent::fieldFormatters();
$faker = $this->faker;
return $this->_mergeFieldFormatters(
array(
'name' => function ($state) use ($faker) {
return $faker->unique()->name;
},
)
);
}
/**
* Set/get state per record
*
* Can be overridden to return some state with data per record.
*
* @return array The state per record.
*/
public function recordState() {
return array(
'foo' => 'bar',
);
}
}