55use Yii ;
66use yii \base \Model ;
77use yii \console \Controller ;
8+ use yii \console \ExitCode ;
89use yii \helpers \Console ;
910use yii \helpers \{FileHelper , VarDumper };
1011use yii \helpers \StringHelper ;
@@ -44,8 +45,12 @@ public function actionIndex()
4445 /**
4546 * Delete all table contents
4647 */
47- public function actionClear ()
48+ public function actionClear ($ requireConfirm = true ): int
4849 {
50+ if ($ requireConfirm && !$ this ->confirm ('Do you really want to delete all data? ' )) {
51+ return ExitCode::OK ;
52+ }
53+ 4954 $ fakers = FileHelper::findFiles (\Yii::getAlias ('@common/models ' ), [
5055 'only ' => ['*Faker.php ' ],
5156 'except ' => ['BaseModelFaker.php ' ],
@@ -59,15 +64,21 @@ public function actionClear()
5964 Yii::$ app ->db ->createCommand ()->delete ($ modelClass ::tableName ())->execute ();
6065 $ this ->stdout ("Data from $ modelName was deleted \n" );
6166 }
67+ return ExitCode::OK ;
6268 }
6369
6470 /**
6571 * Delete all table contents and refill with fake data
6672 */
67- public function actionRefresh ()
73+ public function actionRefresh (): int
6874 {
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 );
7080 $ this ->actionIndex ();
81+ return ExitCode::OK ;
7182 }
7283
7384 public static function sortModels (array $ fakers , string $ fakerNamespace = 'app \\models \\' )
0 commit comments