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