webman迁移
This commit is contained in:
@@ -143,9 +143,12 @@ class Install extends Api
|
||||
}
|
||||
// php版本-end
|
||||
|
||||
// 配置文件-start
|
||||
$dbConfigFile = config_path() . self::$dbConfigFileName;
|
||||
$configIsWritable = Filesystem::pathIsWritable(config_path()) && Filesystem::pathIsWritable($dbConfigFile);
|
||||
// 配置文件-start(分别检测目录和文件,便于定位问题)
|
||||
$configDir = rtrim(config_path(), '/\\');
|
||||
$dbConfigFile = $configDir . DIRECTORY_SEPARATOR . self::$dbConfigFileName;
|
||||
$configDirWritable = Filesystem::pathIsWritable($configDir);
|
||||
$dbConfigWritable = Filesystem::pathIsWritable($dbConfigFile);
|
||||
$configIsWritable = $configDirWritable && $dbConfigWritable;
|
||||
if (!$configIsWritable) {
|
||||
$configIsWritableLink = [
|
||||
[
|
||||
@@ -241,7 +244,9 @@ class Install extends Api
|
||||
'link' => $phpVersionLink ?? [],
|
||||
],
|
||||
'config_is_writable' => [
|
||||
'describe' => self::writableStateDescribe($configIsWritable),
|
||||
'describe' => $configIsWritable
|
||||
? self::writableStateDescribe(true)
|
||||
: (self::writableStateDescribe(false) . ' [' . $configDir . ']'),
|
||||
'state' => $configIsWritable ? self::$ok : self::$fail,
|
||||
'link' => $configIsWritableLink ?? []
|
||||
],
|
||||
@@ -408,12 +413,14 @@ class Install extends Api
|
||||
return $this->error(__('The system has completed installation. If you need to reinstall, please delete the %s file first', ['public/' . self::$lockFileName]));
|
||||
}
|
||||
|
||||
$envOk = $this->commandExecutionCheck();
|
||||
$rootPath = str_replace('\\', '/', root_path());
|
||||
$envOk = $this->commandExecutionCheck();
|
||||
$rootPath = str_replace('\\', '/', root_path());
|
||||
$migrateCommand = 'php vendor/bin/phinx migrate';
|
||||
if ($request->isGet()) {
|
||||
return $this->success('', [
|
||||
'rootPath' => $rootPath,
|
||||
'executionWebCommand' => $envOk
|
||||
'executionWebCommand' => $envOk,
|
||||
'migrateCommand' => $migrateCommand,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -433,8 +440,11 @@ class Install extends Api
|
||||
}
|
||||
|
||||
// 写入数据库配置文件(thinkorm.php 使用 $env('database.xxx', 'default') 格式)
|
||||
$dbConfigFile = config_path() . self::$dbConfigFileName;
|
||||
$dbConfigFile = config_path(self::$dbConfigFileName);
|
||||
$dbConfigContent = @file_get_contents($dbConfigFile);
|
||||
if ($dbConfigContent === false || $dbConfigContent === '') {
|
||||
return $this->error(__('File has no write permission:%s', ['config/' . self::$dbConfigFileName]));
|
||||
}
|
||||
$callback = function ($matches) use ($databaseParam) {
|
||||
$key = $matches[1];
|
||||
$value = (string) ($databaseParam[$key] ?? '');
|
||||
@@ -446,7 +456,7 @@ class Install extends Api
|
||||
return $this->error(__('File has no write permission:%s', ['config/' . self::$dbConfigFileName]));
|
||||
}
|
||||
|
||||
// 写入.env-example文件
|
||||
// 写入 dafuweng-webman/.env-example
|
||||
$envFile = root_path() . '.env-example';
|
||||
$envFileContent = @file_get_contents($envFile);
|
||||
if ($envFileContent) {
|
||||
@@ -473,8 +483,11 @@ class Install extends Api
|
||||
// 设置新的Token随机密钥key
|
||||
$oldTokenKey = config('buildadmin.token.key');
|
||||
$newTokenKey = Random::build('alnum', 32);
|
||||
$buildConfigFile = config_path() . self::$buildConfigFileName;
|
||||
$buildConfigFile = config_path(self::$buildConfigFileName);
|
||||
$buildConfigContent = @file_get_contents($buildConfigFile);
|
||||
if ($buildConfigContent === false || $buildConfigContent === '') {
|
||||
return $this->error(__('File has no write permission:%s', ['config/' . self::$buildConfigFileName]));
|
||||
}
|
||||
$buildConfigContent = preg_replace("/'key'(\s+)=>(\s+)'$oldTokenKey'/", "'key'\$1=>\$2'$newTokenKey'", $buildConfigContent);
|
||||
$result = @file_put_contents($buildConfigFile, $buildConfigContent);
|
||||
if (!$result) {
|
||||
@@ -482,21 +495,22 @@ class Install extends Api
|
||||
}
|
||||
|
||||
// 建立安装锁文件
|
||||
$result = @file_put_contents(public_path() . self::$lockFileName, date('Y-m-d H:i:s'));
|
||||
$result = @file_put_contents(public_path(self::$lockFileName), date('Y-m-d H:i:s'));
|
||||
if (!$result) {
|
||||
return $this->error(__('File has no write permission:%s', ['public/' . self::$lockFileName]));
|
||||
}
|
||||
|
||||
return $this->success('', [
|
||||
'rootPath' => $rootPath,
|
||||
'executionWebCommand' => $envOk
|
||||
'executionWebCommand' => $envOk,
|
||||
'migrateCommand' => $migrateCommand,
|
||||
]);
|
||||
}
|
||||
|
||||
protected function isInstallComplete(): bool
|
||||
{
|
||||
if (is_file(public_path() . self::$lockFileName)) {
|
||||
$contents = @file_get_contents(public_path() . self::$lockFileName);
|
||||
if (is_file(public_path(self::$lockFileName))) {
|
||||
$contents = @file_get_contents(public_path(self::$lockFileName));
|
||||
if ($contents == self::$InstallationCompletionMark) {
|
||||
return true;
|
||||
}
|
||||
@@ -517,7 +531,7 @@ class Install extends Api
|
||||
|
||||
$param = $request->only(['type', 'adminname', 'adminpassword', 'sitename']);
|
||||
if ($param['type'] == 'web') {
|
||||
$result = @file_put_contents(public_path() . self::$lockFileName, self::$InstallationCompletionMark);
|
||||
$result = @file_put_contents(public_path(self::$lockFileName), self::$InstallationCompletionMark);
|
||||
if (!$result) {
|
||||
return $this->error(__('File has no write permission:%s', ['public/' . self::$lockFileName]));
|
||||
}
|
||||
@@ -628,20 +642,24 @@ class Install extends Api
|
||||
try {
|
||||
$pdo = new \PDO($dsn, $user, $pass, [
|
||||
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
|
||||
\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
|
||||
]);
|
||||
$pdo->exec("SELECT 1");
|
||||
$pdo->query("SELECT 1")->fetchAll(\PDO::FETCH_ASSOC);
|
||||
} catch (\PDOException $e) {
|
||||
$errorMsg = $e->getMessage();
|
||||
$errorMsg = mb_convert_encoding($e->getMessage() ?: 'unknown', 'UTF-8', 'UTF-8,GBK,GB2312,BIG5');
|
||||
$template = __('Database connection failed:%s');
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => __('Database connection failed:%s', [mb_convert_encoding($errorMsg ?: 'unknown', 'UTF-8', 'UTF-8,GBK,GB2312,BIG5')])
|
||||
'msg' => strpos($template, '%s') !== false ? sprintf($template, $errorMsg) : $template . $errorMsg,
|
||||
];
|
||||
}
|
||||
|
||||
$databases = [];
|
||||
$databasesExclude = ['information_schema', 'mysql', 'performance_schema', 'sys'];
|
||||
$stmt = $pdo->query("SHOW DATABASES");
|
||||
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
foreach ($rows as $row) {
|
||||
$dbName = $row['Database'] ?? $row['database'] ?? '';
|
||||
if ($dbName && !in_array($dbName, $databasesExclude)) {
|
||||
$databases[] = $dbName;
|
||||
|
||||
Reference in New Issue
Block a user