mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-27 14:17:23 +08:00
add update
This commit is contained in:
@@ -10,6 +10,7 @@ if (!empty($_SERVER['HTTP_X_REQUEST_ID'])) {
|
|||||||
define('REQUEST_ID', intval(NEXUS_START * 10000));
|
define('REQUEST_ID', intval(NEXUS_START * 10000));
|
||||||
}
|
}
|
||||||
define('ROOT_PATH', $rootpath);
|
define('ROOT_PATH', $rootpath);
|
||||||
|
define('VERSION', '1.6.0');
|
||||||
define('IS_ANNOUNCE', (basename($_SERVER['SCRIPT_FILENAME']) == 'announce.php'));
|
define('IS_ANNOUNCE', (basename($_SERVER['SCRIPT_FILENAME']) == 'announce.php'));
|
||||||
|
|
||||||
require $rootpath . 'include/database/interface_db.php';
|
require $rootpath . 'include/database/interface_db.php';
|
||||||
|
|||||||
+34
-26
@@ -1,7 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
if(!defined('IN_TRACKER'))
|
|
||||||
die('Hacking attempt!');
|
|
||||||
|
|
||||||
function get_global_sp_state()
|
function get_global_sp_state()
|
||||||
{
|
{
|
||||||
global $Cache;
|
global $Cache;
|
||||||
@@ -256,38 +253,49 @@ function get_setting($name = null)
|
|||||||
return arr_get($settings, $name);
|
return arr_get($settings, $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
function env($key, $default = null)
|
function env($key = null, $default = null)
|
||||||
{
|
{
|
||||||
static $env;
|
static $env;
|
||||||
if (is_null($env)) {
|
if (is_null($env)) {
|
||||||
$envFile = ROOT_PATH . '.env';
|
$envFile = ROOT_PATH . '.env';
|
||||||
if (!file_exists($envFile)) {
|
$env = readEnvFile($envFile);
|
||||||
throw new \RuntimeException(".env file is not exists in the root path.");
|
|
||||||
}
|
|
||||||
$fp = fopen($envFile, 'r');
|
|
||||||
if ($fp === false) {
|
|
||||||
throw new \RuntimeException(".env file: $envFile is not readable.");
|
|
||||||
}
|
|
||||||
while ($line = trim(fgets($fp))) {
|
|
||||||
if (empty($line)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$pos = strpos($line, '=');
|
|
||||||
if ($pos <= 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (mb_substr($line, 0, 1, 'utf-8') == '#') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$lineKey = normalize_env(mb_substr($line, 0, $pos, 'utf-8'));
|
|
||||||
$lineValue = normalize_env(mb_substr($line, $pos + 1, null, 'utf-8'));
|
|
||||||
$env[$lineKey] = $lineValue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (is_null($key)) {
|
||||||
|
return $env;
|
||||||
|
}
|
||||||
return $env[$key] ?? $default;
|
return $env[$key] ?? $default;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function readEnvFile($envFile)
|
||||||
|
{
|
||||||
|
if (!file_exists($envFile)) {
|
||||||
|
throw new \RuntimeException("env file is not exists in the root path.");
|
||||||
|
}
|
||||||
|
$env = [];
|
||||||
|
$fp = fopen($envFile, 'r');
|
||||||
|
if ($fp === false) {
|
||||||
|
throw new \RuntimeException(".env file: $envFile is not readable.");
|
||||||
|
}
|
||||||
|
while (($line = fgets($fp)) !== false) {
|
||||||
|
$line = trim($line);
|
||||||
|
if (empty($line)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$pos = strpos($line, '=');
|
||||||
|
if ($pos <= 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (mb_substr($line, 0, 1, 'utf-8') == '#') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$lineKey = normalize_env(mb_substr($line, 0, $pos, 'utf-8'));
|
||||||
|
$lineValue = normalize_env(mb_substr($line, $pos + 1, null, 'utf-8'));
|
||||||
|
$env[$lineKey] = $lineValue;
|
||||||
|
}
|
||||||
|
return $env;
|
||||||
|
}
|
||||||
|
|
||||||
function normalize_env($value)
|
function normalize_env($value)
|
||||||
{
|
{
|
||||||
$value = trim($value);
|
$value = trim($value);
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
<?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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user