mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 20:52:48 +08:00
Merge branch 'master' of https://github.com/top-think/framework
This commit is contained in:
@@ -1300,7 +1300,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
public static function get($data, $with = [], $cache = false)
|
||||
{
|
||||
if (is_null($data)) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (true === $with || is_int($with)) {
|
||||
|
||||
@@ -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('<info>Succeed!</info>');
|
||||
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('<info>Succeed!</info>');
|
||||
}
|
||||
@@ -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 = '<?php ' . PHP_EOL . 'return ';
|
||||
$info = Db::getFields($db . $table);
|
||||
$info = Db::connect($config)->getFields($db . $table);
|
||||
$content .= var_export($info, true) . ';';
|
||||
file_put_contents(RUNTIME_PATH . 'schema' . DS . $dbName . $table . EXT, $content);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user