From be743d9d23f9895724435c471e8e91d1ac141f57 Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Fri, 17 Apr 2020 17:10:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=A8=A1=E5=9E=8B=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/catcher/command/ModelGeneratorCommand.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/extend/catcher/command/ModelGeneratorCommand.php b/extend/catcher/command/ModelGeneratorCommand.php index 16f862f..fa4bcfa 100644 --- a/extend/catcher/command/ModelGeneratorCommand.php +++ b/extend/catcher/command/ModelGeneratorCommand.php @@ -30,6 +30,15 @@ class ModelGeneratorCommand extends Command $modelFile= CatchAdmin::getModuleModelDirectory($module) . $model . '.php'; + $asn = 'Y'; + if (file_exists($modelFile)) { + $asn = $this->output->ask($this->input, "Model File {$model} already exists.Are you sure to overwrite, the content will be lost(Y/N)"); + } + + if (strtolower($asn) == 'n') { + exit(0); + } + file_put_contents($modelFile, $this->replaceContent([ $module, $model, $table, $this->generateFields($this->getTableFields($table)) ])); @@ -61,10 +70,10 @@ class ModelGeneratorCommand extends Command { $f = ''; foreach ($fields as $field => $comment) { - $f .= sprintf("'%s', // %s" . "\r\n\t\t\t", $field, $comment); + $f .= sprintf("'%s', // %s" . "\r\n\t\t", $field, $comment); } - return $f; + return rtrim($f, "\r\n\t\t"); } private function replaceContent(array $replace)