improve_install

This commit is contained in:
xiaomlove
2021-01-22 19:43:15 +08:00
parent cf044448c7
commit b80264f7b7
3 changed files with 20 additions and 80 deletions
+20 -6
View File
@@ -1,8 +1,4 @@
<?php
# IMPORTANT: Do not edit below unless you know what you are doing!
if(!defined('IN_TRACKER'))
die('Hacking attempt!');
function get_langfolder_cookie()
{
global $deflang;
@@ -1754,7 +1750,7 @@ function getExportedValue($input,$t = null) {
return 'NULL';
}
function dbconn($autoclean = false)
function dbconn($autoclean = false, $doLogin = true)
{
if (DB::getInstance()->isConnected()) {
return;
@@ -1768,7 +1764,9 @@ function dbconn($autoclean = false)
mysql_query("SET collation_connection = 'utf8_general_ci'");
mysql_query("SET sql_mode=''");
userlogin();
if ($doLogin) {
userlogin();
}
// if (!$useCronTriggerCleanUp && $autoclean) {
// register_shutdown_function("autoclean");
@@ -4402,4 +4400,20 @@ function return_category_image($categoryid, $link="")
return $catimg;
}
function saveSetting($prefix, $nameAndValue)
{
$prefix = strtolower($prefix);
$datetimeNow = date('Y-m-d H:i:s');
$sql = "insert into settings (name, value, created_at, updated_at) values ";
$data = [];
foreach ($nameAndValue as $name => $value) {
if (is_array($value)) {
$value = json_encode($value);
}
$data[] = sprintf("(%s, %s, %s, %s)", sqlesc("$prefix.$name"), sqlesc($value), sqlesc($datetimeNow), sqlesc($datetimeNow));
}
$sql .= implode(",", $data) . " on duplicate key update value = values(value)";
sql_query($sql) or sqlerr(__FILE__, __LINE__);
}
?>
-58
View File
@@ -1,58 +0,0 @@
<?php
/**
* update 1.5 to 1.6, run in console
* @author xiaomlove<1939737565@qq.com>
*/
function printLine($msg, $exit = false)
{
echo sprintf("[%s] %s%s", date('Y-m-d H:i:s'), $msg, PHP_EOL);
if ($exit) {
exit(0);
}
}
if (php_sapi_name() != 'cli') {
printLine("Please run in console!", true);
}
//environment check
printLine("Checking the environment...");
if (version_compare(PHP_VERSION, '7.2.0', '<')) {
printLine(sprintf('Your PHP version: %s not match, require >= 7.2.0', PHP_VERSION));
}
$requireExtensions = ['mysqli', 'mbstring', 'gd', 'json'];
foreach ($requireExtensions as $ext) {
if (extension_loaded($ext)) {
printLine("extension: $ext is loaded.");
} else {
printLine("Error: required extension: $ext is not loaded!", true);
}
}
if (!extension_loaded('redis')) {
printLine("warning: redis is not loaded. highly recommand install it, see: https://pecl.php.net/package/redis/");
}
$gdInfo = gd_info();
$gdShouldAvaliable = ['JPEG Support', 'PNG Support', 'GIF Read Support'];
foreach ($gdShouldAvaliable as $value) {
if (!isset($gdInfo[$value]) || !$gdInfo[$value]) {
printLine("Error: gd $value is not available", true);
}
}
//create .env file
$rootPath = dirname(__DIR__);
$envExample = "$rootPath/.env.example";
$env = "$rootPath/.env";
if (!file_exists("$rootPath.env")) {
printLine("Error: $envExample not exists.");
}
$copyResult = copy($envExample, $env);
if ($copyResult !== true) {
}