From 6fa48e2501330530e37eb30f59c4d06166794fea Mon Sep 17 00:00:00 2001 From: tale Date: Thu, 23 Mar 2017 09:48:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=BD=E4=BB=A4=E8=A1=8C=E5=B7=A5=E5=85=B7sc?= =?UTF-8?q?hema=E5=A2=9E=E5=8A=A0config=E5=8F=82=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BC=A0=E5=85=A5=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../think/console/command/optimize/Schema.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/library/think/console/command/optimize/Schema.php b/library/think/console/command/optimize/Schema.php index d4d1f0f6..27eb9dbb 100644 --- a/library/think/console/command/optimize/Schema.php +++ b/library/think/console/command/optimize/Schema.php @@ -25,6 +25,7 @@ class Schema extends Command protected function configure() { $this->setName('optimize:schema') + ->addOption('config', null, Option::VALUE_REQUIRED, 'db config .') ->addOption('db', null, Option::VALUE_REQUIRED, 'db name .') ->addOption('table', null, Option::VALUE_REQUIRED, 'table name .') ->addOption('module', null, Option::VALUE_REQUIRED, 'module name .') @@ -36,6 +37,10 @@ class Schema extends Command if (!is_dir(RUNTIME_PATH . 'schema')) { @mkdir(RUNTIME_PATH . 'schema', 0755, true); } + $config = []; + if ($input->hasOption('config')) { + $config = $input->getOption('config'); + } if ($input->hasOption('module')) { $module = $input->getOption('module'); // 读取模型 @@ -53,12 +58,12 @@ class Schema extends Command } elseif ($input->hasOption('table')) { $table = $input->getOption('table'); if (!strpos($table, '.')) { - $dbName = Db::getConfig('database'); + $dbName = Db::connect($config)->getConfig('database'); } $tables[] = $table; } elseif ($input->hasOption('db')) { $dbName = $input->getOption('db'); - $tables = Db::getTables($dbName); + $tables = Db::connect($config)->getTables($dbName); } elseif (!\think\Config::get('app_multi_module')) { $app = App::$namespace; $list = scandir(APP_PATH . 'model'); @@ -72,11 +77,11 @@ class Schema extends Command $output->writeln('Succeed!'); return; } else { - $tables = Db::getTables(); + $tables = Db::connect($config)->getTables(); } $db = isset($dbName) ? $dbName . '.' : ''; - $this->buildDataBaseSchema($tables, $db); + $this->buildDataBaseSchema($tables, $db, $config); $output->writeln('Succeed!'); } @@ -94,16 +99,16 @@ class Schema extends Command } } - protected function buildDataBaseSchema($tables, $db) + protected function buildDataBaseSchema($tables, $db, $config) { if ('' == $db) { - $dbName = Db::getConfig('database') . '.'; + $dbName = Db::connect($config)->getConfig('database') . '.'; } else { $dbName = $db; } foreach ($tables as $table) { $content = 'getFields($db . $table); $content .= var_export($info, true) . ';'; file_put_contents(RUNTIME_PATH . 'schema' . DS . $dbName . $table . EXT, $content); }