File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change 5
5
use Yii ;
6
6
use yii \base \Model ;
7
7
use yii \console \Controller ;
8
+ use yii \console \ExitCode ;
8
9
use yii \helpers \Console ;
9
10
use yii \helpers \{FileHelper , VarDumper };
10
11
use yii \helpers \StringHelper ;
@@ -44,8 +45,12 @@ public function actionIndex()
44
45
/**
45
46
* Delete all table contents
46
47
*/
47
- public function actionClear ()
48
+ public function actionClear ($ requireConfirm = true ): int
48
49
{
50
+ if ($ requireConfirm && !$ this ->confirm ('Do you really want to delete all data? ' )) {
51
+ return ExitCode::OK ;
52
+ }
53
+
49
54
$ fakers = FileHelper::findFiles (\Yii::getAlias ('@common/models ' ), [
50
55
'only ' => ['*Faker.php ' ],
51
56
'except ' => ['BaseModelFaker.php ' ],
@@ -59,15 +64,21 @@ public function actionClear()
59
64
Yii::$ app ->db ->createCommand ()->delete ($ modelClass ::tableName ())->execute ();
60
65
$ this ->stdout ("Data from $ modelName was deleted \n" );
61
66
}
67
+ return ExitCode::OK ;
62
68
}
63
69
64
70
/**
65
71
* Delete all table contents and refill with fake data
66
72
*/
67
- public function actionRefresh ()
73
+ public function actionRefresh (): int
68
74
{
69
- $ this ->actionClear ();
75
+ if (!$ this ->confirm ('Do you really want to delete all data and generate new fake data? ' )) {
76
+ return ExitCode::OK ;
77
+ }
78
+
79
+ $ this ->actionClear (false );
70
80
$ this ->actionIndex ();
81
+ return ExitCode::OK ;
71
82
}
72
83
73
84
public static function sortModels (array $ fakers , string $ fakerNamespace = 'app \\models \\' )
You can’t perform that action at this time.
0 commit comments