From 4c9a4fc463ec50afca50ebe0371638c51f1a66c6 Mon Sep 17 00:00:00 2001 From: xiaomlove <353856593@qq.com> Date: Thu, 21 Jan 2021 20:42:22 +0800 Subject: [PATCH] add update --- include/core.php | 1 + include/globalfunctions.php | 60 +++++++++++++++++++++---------------- include/update.php | 58 +++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 26 deletions(-) create mode 100644 include/update.php diff --git a/include/core.php b/include/core.php index a6905fa1..eec26184 100644 --- a/include/core.php +++ b/include/core.php @@ -10,6 +10,7 @@ if (!empty($_SERVER['HTTP_X_REQUEST_ID'])) { define('REQUEST_ID', intval(NEXUS_START * 10000)); } define('ROOT_PATH', $rootpath); +define('VERSION', '1.6.0'); define('IS_ANNOUNCE', (basename($_SERVER['SCRIPT_FILENAME']) == 'announce.php')); require $rootpath . 'include/database/interface_db.php'; diff --git a/include/globalfunctions.php b/include/globalfunctions.php index 91691405..89b4cbc6 100644 --- a/include/globalfunctions.php +++ b/include/globalfunctions.php @@ -1,7 +1,4 @@ + */ + +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) { + +} + + + + +