mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 12:30:49 +08:00
install import data
This commit is contained in:
@@ -62,11 +62,6 @@ if (file_exists('config/allconfig.php')) {
|
||||
*/
|
||||
|
||||
//load settings from database
|
||||
if (IS_ANNOUNCE) {
|
||||
dbconn_announce();
|
||||
} else {
|
||||
dbconn();
|
||||
}
|
||||
$settings = get_setting();
|
||||
foreach ($settings as $name => $value) {
|
||||
$GLOBALS[strtoupper($name)] = $value;
|
||||
|
||||
@@ -152,7 +152,7 @@ function do_log($log, $level = 'info')
|
||||
if (!empty($TWEAK['logging'])) {
|
||||
$logging = $TWEAK['logging'];
|
||||
}
|
||||
if (!empty($TWEAK['logging'])) {
|
||||
if (($fd = fopen($logging, 'a')) !== false) {
|
||||
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
|
||||
$content = sprintf(
|
||||
"[%s] [%s] [%s] %s:%s %s%s%s %s%s",
|
||||
@@ -167,7 +167,8 @@ function do_log($log, $level = 'info')
|
||||
$log,
|
||||
PHP_EOL
|
||||
);
|
||||
file_put_contents($logging, $content, FILE_APPEND);
|
||||
fwrite($fd, $content);
|
||||
fclose($fd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,11 @@ class DB
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDriver()
|
||||
{
|
||||
return $this->driver;
|
||||
}
|
||||
|
||||
public static function getInstance()
|
||||
{
|
||||
if (self::$instance) {
|
||||
@@ -42,25 +47,27 @@ class DB
|
||||
|
||||
public function connect($host, $username, $password, $database, $port)
|
||||
{
|
||||
$this->driver->connect($host, $username, $password, $database, $port);
|
||||
$result = $this->driver->connect($host, $username, $password, $database, $port);
|
||||
if (!$result) {
|
||||
throw new DatabaseException(sprintf('[%s]: %s', $this->errno(), $this->error()));
|
||||
}
|
||||
$this->driver->query("SET NAMES UTF8");
|
||||
$this->driver->query("SET collation_connection = 'utf8_general_ci'");
|
||||
$this->driver->query("SET sql_mode=''");
|
||||
$this->isConnected = true;
|
||||
do_log("do mysql_connect with: " . json_encode(func_get_args()));
|
||||
$log = json_encode(func_get_args());
|
||||
do_log($log);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function autoConnect()
|
||||
{
|
||||
if ($this->isConnected()) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
$config = config('database.mysql');
|
||||
if (!mysql_connect($config['host'], $config['username'], $config['password'], $config['database'], $config['port'])) {
|
||||
throw new DatabaseException(sprintf("mysql connect error: [%s] %s", mysql_errno(), mysql_error()));
|
||||
}
|
||||
mysql_query("SET NAMES UTF8");
|
||||
mysql_query("SET collation_connection = 'utf8_general_ci'");
|
||||
mysql_query("SET sql_mode=''");
|
||||
$this->isConnected = true;
|
||||
do_log(json_encode($config));
|
||||
return $this->connect($config['host'], $config['username'], $config['password'], $config['database'], $config['port']);
|
||||
}
|
||||
|
||||
public function query(string $sql)
|
||||
|
||||
@@ -10,7 +10,13 @@ class Install
|
||||
|
||||
private $minimumPhpVersion = '7.2.0';
|
||||
|
||||
protected $steps = ['环境检测', '添加 .env 文件', '新建数据表', '导入数据', '创建管理员账号'];
|
||||
protected $steps = ['环境检测', '添加 .env 文件', '创建数据表', '导入数据', '创建管理员账号'];
|
||||
|
||||
protected $initializeTables = [
|
||||
'adminpanel', 'agent_allowed_exception', 'agent_allowed_family', 'allowedemails', 'audiocodecs', 'avps', 'bannedemails', 'categories',
|
||||
'caticons', 'codecs', 'countries', 'downloadspeed', 'faq', 'isp', 'language', 'media', 'modpanel', 'processings', 'rules', 'schools',
|
||||
'searchbox', 'secondicons', 'sources', 'standards', 'stylesheets', 'sysoppanel', 'teams', 'torrents_state', 'uploadspeed', 'agent_allowed_family',
|
||||
];
|
||||
|
||||
|
||||
public function __construct()
|
||||
@@ -421,7 +427,7 @@ class Install
|
||||
|
||||
public function saveSettings($settings)
|
||||
{
|
||||
foreach ($settings as $prefix => &$group) {
|
||||
foreach ($settings as $prefix => $group) {
|
||||
$this->doLog("[SAVE SETTING], prefix: $prefix, nameAndValues: " . json_encode($group));
|
||||
saveSetting($prefix, $group);
|
||||
}
|
||||
@@ -443,4 +449,24 @@ class Install
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function importInitialData($sqlFile = '')
|
||||
{
|
||||
if (empty($sqlFile)) {
|
||||
$sqlFile = ROOT_PATH . '_db/dbstructure_v1.6.sql';
|
||||
}
|
||||
$string = file_get_contents($sqlFile);
|
||||
$pattern = "/INSERT INTO `(\w+)` VALUES \(.*\);\n/i";
|
||||
preg_match_all($pattern, $string, $matches, PREG_SET_ORDER);
|
||||
foreach ($matches as $match) {
|
||||
$table = $match[1];
|
||||
$sql = trim($match[0]);
|
||||
if (!in_array($table, $this->initializeTables)) {
|
||||
continue;
|
||||
}
|
||||
$this->doLog("[IMPORT DATA] $table, $sql");
|
||||
sql_query($sql);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -108,6 +108,7 @@ if ($currentStep == 4) {
|
||||
$pass = $settingTableRows['pass'];
|
||||
while ($isPost) {
|
||||
try {
|
||||
$install->importInitialData();
|
||||
$install->saveSettings($settings);
|
||||
$install->createSymbolicLinks($symbolicLinks);
|
||||
$install->nextStep();
|
||||
@@ -205,6 +206,9 @@ if ($currentStep == 5) {
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-10 text-center">
|
||||
欢迎使用 NexusPHP 安装程序,如有疑问,点击<a href="http://nexusphp.cn/" target="_blank" class="text-blue-500 p-1">这里</a>获取参考。
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
function goBack() {
|
||||
|
||||
Reference in New Issue
Block a user