| 1 | <?php |
||
| 5 | class m160219_091156_createUser extends Migration |
||
|
|
|||
| 6 | { |
||
| 7 | public function up() |
||
| 8 | { |
||
| 9 | if(isset($_SERVER['TRAVIS'])||(isset($_SERVER['PWD'])&&strpos($_SERVER['PWD'], '/tests/'))) |
||
| 10 | return null; |
||
| 11 | |||
| 12 | $userName = 'webmaster'; |
||
| 13 | |||
| 14 | $tableName = \dektrium\user\models\User::tableName(); |
||
| 15 | $query = 'SELECT COUNT(*) FROM '.$tableName.' WHERE `username`=:username'; |
||
| 16 | $count = \Yii::$app->db->createCommand($query, [':username'=>$userName])->queryScalar(); |
||
| 17 | if($count>0) |
||
| 18 | return null; |
||
| 19 | |||
| 20 | $user = \Yii::createObject([ |
||
| 21 | 'class' => \dektrium\user\models\User::className(), |
||
| 22 | 'scenario' => 'create', |
||
| 23 | 'username' => $userName, |
||
| 24 | 'password' => $userName, |
||
| 25 | 'email' => $userName.'@yii2enterprise.dev', |
||
| 26 | ]); |
||
| 27 | |||
| 28 | return $user->create(); |
||
| 29 | } |
||
| 30 | |||
| 31 | public function down() |
||
| 37 | |||
| 38 | /* |
||
| 39 | // Use safeUp/safeDown to run migration code within a transaction |
||
| 40 | public function safeUp() |
||
| 41 | { |
||
| 42 | } |
||
| 43 | |||
| 44 | public function safeDown() |
||
| 45 | { |
||
| 46 | } |
||
| 47 | */ |
||
| 48 | } |
||
| 49 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.