From 4260ee14e37bcecd58de9f478c4b2b9ee27b4c39 Mon Sep 17 00:00:00 2001 From: Karson Date: Wed, 7 Feb 2018 23:49:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=91=BD=E4=BB=A4=E8=A1=8C?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E5=8D=87=E7=BA=A7=E5=92=8C=E6=89=93=E5=8C=85?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E5=90=8E=E5=8F=B0=E4=BF=9D=E6=8C=81?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E4=B8=8D=E8=B5=B7=E4=BD=9C=E7=94=A8=E7=9A=84?= =?UTF-8?q?BUG=20=E4=BC=98=E5=8C=96=E5=AE=89=E8=A3=85=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E7=9A=84=E6=96=87=E5=AD=97=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 +- application/admin/command/Addon.php | 84 ++++++++++++++++--- .../admin/command/Install/install.lock | 1 + application/admin/library/Auth.php | 2 +- public/install.php | 10 +-- public/uploads/.gitkeep | 1 + runtime/.gitkeep | 1 + 7 files changed, 85 insertions(+), 19 deletions(-) create mode 100644 application/admin/command/Install/install.lock create mode 100644 public/uploads/.gitkeep create mode 100644 runtime/.gitkeep diff --git a/.gitignore b/.gitignore index cd13b271..b883f26b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,11 @@ /nbproject/ /thinkphp/ /vendor/ -/runtime/ +/runtime/* /addons/* -/application/admin/command/Install/*.lock /public/assets/libs/ /public/assets/addons/* -/public/uploads/ +/public/uploads/* .idea composer.lock *.log diff --git a/application/admin/command/Addon.php b/application/admin/command/Addon.php index c1283f6e..216ac47e 100644 --- a/application/admin/command/Addon.php +++ b/application/admin/command/Addon.php @@ -19,8 +19,9 @@ class Addon extends Command $this ->setName('addon') ->addOption('name', 'a', Option::VALUE_REQUIRED, 'addon name', null) - ->addOption('action', 'c', Option::VALUE_REQUIRED, 'action(create/enable/disable/install/uninstall/refresh)', 'create') + ->addOption('action', 'c', Option::VALUE_REQUIRED, 'action(create/enable/disable/install/uninstall/refresh/upgrade/package)', 'create') ->addOption('force', 'f', Option::VALUE_OPTIONAL, 'force override', null) + ->addOption('release', 'r', Option::VALUE_OPTIONAL, 'addon release version', null) ->setDescription('Addon manager'); } @@ -30,6 +31,8 @@ class Addon extends Command $action = $input->getOption('action') ?: ''; //强制覆盖 $force = $input->getOption('force'); + //版本 + $release = $input->getOption('release') ?: ''; include dirname(__DIR__) . DS . 'common.php'; @@ -37,15 +40,15 @@ class Addon extends Command { throw new Exception('Addon name could not be empty'); } - if (!$action || !in_array($action, ['create', 'disable', 'enable', 'install', 'uninstall', 'refresh'])) + if (!$action || !in_array($action, ['create', 'disable', 'enable', 'install', 'uninstall', 'refresh', 'upgrade', 'package'])) { throw new Exception('Please input correct action name'); } - + // 查询一次SQL,判断连接是否正常 Db::execute("SELECT 1"); - - $addonDir = ADDON_PATH . $name; + + $addonDir = ADDON_PATH . $name . DS; switch ($action) { case 'create': @@ -65,9 +68,9 @@ class Addon extends Command 'addon' => $name, 'addonClassName' => ucfirst($name) ]; - $this->writeToFile("addon", $data, $addonDir . DS . ucfirst($name) . '.php'); - $this->writeToFile("config", $data, $addonDir . DS . 'config.php'); - $this->writeToFile("info", $data, $addonDir . DS . 'info.ini'); + $this->writeToFile("addon", $data, $addonDir . ucfirst($name) . '.php'); + $this->writeToFile("config", $data, $addonDir . 'config.php'); + $this->writeToFile("info", $data, $addonDir . 'info.ini'); $output->info("Create Successed!"); break; case 'disable': @@ -117,7 +120,7 @@ class Addon extends Command } try { - Service::install($name, 0); + Service::install($name, 0, ['version' => $release]); } catch (AddonException $e) { @@ -137,7 +140,7 @@ class Addon extends Command { throw new Exception("Operation is aborted!"); } - Service::install($name, 1); + Service::install($name, 1, ['version' => $release]); } catch (Exception $e) { @@ -187,6 +190,67 @@ class Addon extends Command Service::refresh(); $output->info("Refresh Successed!"); break; + case 'upgrade': + Service::upgrade($name, ['version' => $release]); + $output->info("Upgrade Successed!"); + break; + case 'package': + $infoFile = $addonDir . 'info.ini'; + if (!is_file($infoFile)) + { + throw new Exception(__('Addon info file was not found')); + } + + $info = get_addon_info($name); + if (!$info) + { + throw new Exception(__('Addon info file data incorrect')); + } + $infoname = isset($info['name']) ? $info['name'] : ''; + if (!$infoname || !preg_match("/^[a-z]+$/i", $infoname) || $infoname != $name) + { + throw new Exception(__('Addon info name incorrect')); + } + + $infoversion = isset($info['version']) ? $info['version'] : ''; + if (!$infoversion || !preg_match("/^\d+\.\d+\.\d+$/i", $infoversion)) + { + throw new Exception(__('Addon info version incorrect')); + } + + $addonTmpDir = RUNTIME_PATH . 'addons' . DS; + if (!is_dir($addonTmpDir)) + { + @mkdir($addonTmpDir, 0755, true); + } + $addonFile = $addonTmpDir . $infoname . '-' . $infoversion . '.zip'; + if (!class_exists('ZipArchive')) + { + throw new Exception(__('ZinArchive not install')); + } + $zip = new \ZipArchive; + $zip->open($addonFile, \ZipArchive::CREATE | \ZipArchive::OVERWRITE); + + $files = new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator($addonDir), \RecursiveIteratorIterator::LEAVES_ONLY + ); + + foreach ($files as $name => $file) + { + if (!$file->isDir()) + { + $filePath = $file->getRealPath(); + $relativePath = substr($filePath, strlen($addonDir)); + if (!in_array($file->getFilename(), ['.git', '.DS_Store', 'Thumbs.db'])) + { + $zip->addFile($filePath, $relativePath); + } + } + } + $zip->close(); + $output->info("Package Successed!"); + break; + default : break; } diff --git a/application/admin/command/Install/install.lock b/application/admin/command/Install/install.lock new file mode 100644 index 00000000..56a6051c --- /dev/null +++ b/application/admin/command/Install/install.lock @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/application/admin/library/Auth.php b/application/admin/library/Auth.php index 00a99741..7ff03d94 100644 --- a/application/admin/library/Auth.php +++ b/application/admin/library/Auth.php @@ -126,7 +126,7 @@ class Auth extends \fast\Auth $expiretime = time() + $keeptime; $key = md5(md5($this->id) . md5($keeptime) . md5($expiretime) . $this->token); $data = [$this->id, $keeptime, $expiretime, $key]; - Cookie::set('keeplogin', implode('|', $data)); + Cookie::set('keeplogin', implode('|', $data), 86400 * 30); return true; } return false; diff --git a/public/install.php b/public/install.php index fea5ba0d..cd65321d 100644 --- a/public/install.php +++ b/public/install.php @@ -77,7 +77,7 @@ else if (!extension_loaded("PDO")) } else if (!is_really_writable($dbConfigFile)) { - $errInfo = "当前权限不足,无法写入配置文件application/database.php"; + $errInfo = '当前权限不足,无法写入配置文件application/database.php
点击查看解决办法'; } else { @@ -86,7 +86,7 @@ else { if (!is_dir(ROOT_PATH . $v)) { - $errInfo = '当前代码不完整,请加入QQ群(636393962),在群共享免费下载FastAdmin完整包后再尝试安装'; + $errInfo = '当前代码仅包含核心代码,请前往官网下载完整包或资源包覆盖后再尝试安装,立即前往下载'; break; } } @@ -95,7 +95,7 @@ else if (!$errInfo && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') { $err = ''; - $mysqlHostname = isset($_POST['mysqlHost']) ? $_POST['mysqlHost'] : 'localhost'; + $mysqlHostname = isset($_POST['mysqlHost']) ? $_POST['mysqlHost'] : '127.0.0.1'; $mysqlHostport = 3306; $hostArr = explode(':', $mysqlHostname); if (count($hostArr) > 1) @@ -330,7 +330,7 @@ if (!$errInfo && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD']

安装

-

若你在安装中遇到麻烦可点击 安装文档 交流论坛 QQ交流群

+

若你在安装中遇到麻烦可点击 安装文档 交流社区 QQ交流群

@@ -345,7 +345,7 @@ if (!$errInfo && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD']
- +
diff --git a/public/uploads/.gitkeep b/public/uploads/.gitkeep new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/public/uploads/.gitkeep @@ -0,0 +1 @@ + diff --git a/runtime/.gitkeep b/runtime/.gitkeep new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/runtime/.gitkeep @@ -0,0 +1 @@ +