10 if (!Yii::app()->getModule(
'user')) {
11 echo
"\n\nAdd to console.php :\n"
12 .
"'modules'=>array(\n"
15 .
" ... # copy settings from main config\n"
23 Yii::import(
'user.models.User');
27 $this->createTable(Yii::app()->getModule(
'user')->tableUsers, array(
29 "username" =>
"varchar(20) NOT NULL DEFAULT ''",
30 "password" =>
"varchar(128) NOT NULL DEFAULT ''",
31 "email" =>
"varchar(128) NOT NULL DEFAULT ''",
32 "activkey" =>
"varchar(128) NOT NULL DEFAULT ''",
33 "createtime" =>
"int(10) NOT NULL DEFAULT 0",
34 "lastvisit" =>
"int(10) NOT NULL DEFAULT 0",
35 "superuser" =>
"int(1) NOT NULL DEFAULT 0",
36 "status" =>
"int(1) NOT NULL DEFAULT 0",
37 ), $this->MySqlOptions);
38 $this->createIndex(
'user_username', Yii::app()->getModule(
'user')->tableUsers,
'username',
true);
39 $this->createIndex(
'user_email', Yii::app()->getModule(
'user')->tableUsers,
'email',
true);
40 $this->createTable(Yii::app()->getModule(
'user')->tableProfiles, array(
42 'first_name' =>
'string',
43 'last_name' =>
'string',
44 ), $this->MySqlOptions);
45 $this->addForeignKey(
'user_profile_id', Yii::app()->getModule(
'user')->tableProfiles,
'user_id', Yii::app()->getModule(
'user')->tableUsers,
'id',
'CASCADE',
'RESTRICT');
46 $this->createTable(Yii::app()->getModule(
'user')->tableProfileFields, array(
48 "varname" =>
"varchar(50) NOT NULL DEFAULT ''",
49 "title" =>
"varchar(255) NOT NULL DEFAULT ''",
50 "field_type" =>
"varchar(50) NOT NULL DEFAULT ''",
51 "field_size" =>
"int(3) NOT NULL DEFAULT 0",
52 "field_size_min" =>
"int(3) NOT NULL DEFAULT 0",
53 "required" =>
"int(1) NOT NULL DEFAULT 0",
54 "match" =>
"varchar(255) NOT NULL DEFAULT ''",
55 "range" =>
"varchar(255) NOT NULL DEFAULT ''",
56 "error_message" =>
"varchar(255) NOT NULL DEFAULT ''",
57 "other_validator" =>
"text",
58 "default" =>
"varchar(255) NOT NULL DEFAULT ''",
59 "widget" =>
"varchar(255) NOT NULL DEFAULT ''",
60 "widgetparams" =>
"text",
61 "position" =>
"int(3) NOT NULL DEFAULT 0",
62 "visible" =>
"int(1) NOT NULL DEFAULT 0",
63 ), $this->MySqlOptions);
68 $this->createTable(Yii::app()->getModule(
'user')->tableUsers, array(
70 "username" =>
"varchar(20) NOT NULL",
71 "password" =>
"varchar(128) NOT NULL",
72 "email" =>
"varchar(128) NOT NULL",
73 "activkey" =>
"varchar(128) NOT NULL",
74 "createtime" =>
"int(10) NOT NULL",
75 "lastvisit" =>
"int(10) NOT NULL",
76 "superuser" =>
"int(1) NOT NULL",
77 "status" =>
"int(1) NOT NULL",
79 $this->createIndex(
'user_username', Yii::app()->getModule(
'user')->tableUsers,
'username',
true);
80 $this->createIndex(
'user_email', Yii::app()->getModule(
'user')->tableUsers,
'email',
true);
81 $this->createTable(Yii::app()->getModule(
'user')->tableProfiles, array(
83 'first_name' =>
'string',
84 'last_name' =>
'string',
86 $this->createTable(Yii::app()->getModule(
'user')->tableProfileFields, array(
88 "varname" =>
"varchar(50) NOT NULL",
89 "title" =>
"varchar(255) NOT NULL",
90 "field_type" =>
"varchar(50) NOT NULL",
91 "field_size" =>
"int(3) NOT NULL",
92 "field_size_min" =>
"int(3) NOT NULL",
93 "required" =>
"int(1) NOT NULL",
94 "match" =>
"varchar(255) NOT NULL",
95 "range" =>
"varchar(255) NOT NULL",
96 "error_message" =>
"varchar(255) NOT NULL",
97 "other_validator" =>
"text NOT NULL",
98 "default" =>
"varchar(255) NOT NULL",
99 "widget" =>
"varchar(255) NOT NULL",
100 "widgetparams" =>
"text NOT NULL",
101 "position" =>
"int(3) NOT NULL",
102 "visible" =>
"int(1) NOT NULL",
108 if (in_array(
'--interactive=0', $_SERVER[
'argv'])) {
109 $this->_model->username =
'admin';
110 $this->_model->email =
'webmaster@example.com';
111 $this->_model->password =
'admin';
114 $this->
readStdinUser(
'Admin email',
'email',
'webmaster@example.com');
118 $this->insert(Yii::app()->getModule(
'user')->tableUsers, array(
120 "username" => $this->_model->username,
121 "password" => Yii::app()->getModule(
'user')->encrypting($this->_model->password),
122 "email" =>
"webmaster@example.com",
123 "activkey" => Yii::app()->getModule(
'user')->encrypting(microtime()),
124 "createtime" => time(),
130 $this->insert(Yii::app()->getModule(
'user')->tableProfiles, array(
132 "first_name" =>
"Administrator",
133 "last_name" =>
"Admin",
136 $this->insert(Yii::app()->getModule(
'user')->tableProfileFields, array(
138 "varname" =>
"first_name",
139 "title" =>
"First Name",
140 "field_type" =>
"VARCHAR",
141 "field_size" =>
"255",
142 "field_size_min" =>
"3",
146 "error_message" =>
"Incorrect First Name (length between 3 and 50 characters).",
147 "other_validator" =>
"",
150 "widgetparams" =>
"",
154 $this->insert(Yii::app()->getModule(
'user')->tableProfileFields, array(
156 "varname" =>
"last_name",
157 "title" =>
"Last Name",
158 "field_type" =>
"VARCHAR",
159 "field_size" =>
"255",
160 "field_size_min" =>
"3",
164 "error_message" =>
"Incorrect Last Name (length between 3 and 50 characters).",
165 "other_validator" =>
"",
168 "widgetparams" =>
"",
176 $this->dropTable(Yii::app()->getModule(
'user')->tableProfileFields);
177 $this->dropTable(Yii::app()->getModule(
'user')->tableProfiles);
178 $this->dropTable(Yii::app()->getModule(
'user')->tableUsers);
183 list($type) = explode(
':', Yii::app()->db->connectionString);
184 echo
"type db: ".$type.
"\n";
189 private function readStdin($prompt, $valid_inputs, $default =
'')
191 while (!isset($input) || (is_array($valid_inputs) && !in_array($input, $valid_inputs)) || ($valid_inputs ==
'is_file' && !is_file($input))) {
193 $input = strtolower(trim(fgets(STDIN)));
194 if (empty($input) && !empty($default)) {
204 if (!$this->_model) {
205 $this->_model =
new User();
208 while (!isset($input) || !$this->_model->validate(array($field))) {
209 echo $prompt.(($default) ?
" [$default]" :
'').
': ';
210 $input = (trim(fgets(STDIN)));
211 if (empty($input) && !empty($default)) {
214 $this->_model->setAttribute($field, $input);