Skip to content

Commit f2192c9

Browse files
committed
add confirm at actions clear, refresh
1 parent bce3725 commit f2192c9

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

console/commands/FakerController.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Yii;
66
use yii\base\Model;
77
use yii\console\Controller;
8+
use yii\console\ExitCode;
89
use yii\helpers\Console;
910
use yii\helpers\{FileHelper, VarDumper};
1011
use 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

Comments
 (0)