| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- /**
- * Created by PhpStorm.
- * Name: 芸众商城系统
- * Author: 广州市芸众信息科技有限公司
- * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
- * Date: 2022-03-10
- * Time: 10:26
- */
- namespace app\backend\modules\setting\controllers;
- use app\common\components\BaseController;
- use app\common\models\SqlInstallLog;
- class SqlManageController extends BaseController
- {
- public function index()
- {
- $log = SqlInstallLog::first();
- $is_install = 0;
- $access_path = '';
- if ($log) {
- $access_url_len = strlen(base_path());
- $access_path = request()->getSchemeAndHttpHost().'/'.substr($log->path, $access_url_len+1).'/phpmyadmin';
- if (config('app.framework') != 'platform') {
- $access_path = request()->getSchemeAndHttpHost().'/addons/yun_shop/'.substr($log->path, $access_url_len+1).'/phpmyadmin';
- }
- $is_install = 1;
- }
- $list = [
- [
- 'download_url' => 'https://downloads.yunzmall.com/phpmyadmin.zip',
- 'is_install' => $is_install,
- 'access_url' => $access_path,
- ]
- ];
- return view('setting.sql-manage.index', [
- 'list' => json_encode($list),
- ]);
- }
- public function download()
- {
- $url = request()->url;
- $file_info = pathinfo($url);
- $basename = $file_info['basename'];
- $download_path = base_path().'/'.$basename;
- $get_res = file_get_contents($url);
- if (!$get_res) {
- return $this->errorJson('请求链接数据失败');
- }
- file_put_contents($download_path, file_get_contents($url));
- if (!file_exists($download_path)) {
- return $this->errorJson('下载失败');
- }
- $zip = new \ZipArchive();
- $new_path = base_path(md5(str_random(6).time()));
- if ($zip->open($download_path)) {
- $zip->extractTo($new_path);
- $zip->close();
- } else {
- return $this->errorJson('解压失败');
- }
- $log_arr = [
- 'path' => $new_path,
- ];
- $log = SqlInstallLog::first();
- if ($log) {
- $log->update($log_arr);
- } else {
- SqlInstallLog::create($log_arr);
- }
- @unlink($download_path);
- return $this->successJson('下载安装成功');
- }
- public function uninstall()
- {
- $log = SqlInstallLog::first();
- if (!$log) {
- return $this->errorJson('安装记录不存在');
- }
- if (file_exists($log->path)) {
- if (!$this->removeDir($log->path)) {
- return $this->errorJson('卸载失败');
- }
- $log->delete();
- }
- return $this->successJson('卸载成功');
- }
- private function removeDir($dir_name)
- {
- if (!is_dir($dir_name)) {
- return false;
- }
- $handle = @opendir($dir_name);
- while ($file = @readdir($handle)) {
- if ($file != '.' && $file != '..') {
- $dir = $dir_name . '/' . $file;
- is_dir($dir) ? $this->removeDir($dir) : @unlink($dir);
- }
- }
- closedir($handle);
- @rmdir($dir_name);
- return true;
- }
- }
|