Example #1
0
 public function applyPatch($filename)
 {
     $System = new SystemEvent();
     $zip = new \ZipArchive();
     //新建一个ZipArchive的对象
     if ($zip->open($filename) === true) {
         $zip->extractTo(WEB_ROOT);
         //假设解压缩到在当前路径下/文件夹内
         $zip->close();
         //关闭处理的zip文件
         File::delFile($filename);
         $System->clearCacheAll();
         return $this->jsonResult(1, "安装成功");
     } else {
         return $this->jsonResult(0, "文件损坏");
     }
 }
 public function clearAll()
 {
     $SystemEvent = new SystemEvent();
     $SystemEvent->clearCacheAll();
     $this->success("清除成功");
 }
 /**
  * For Mysql only
  */
 public function repair()
 {
     if (get_opinion('DB_TYPE') != 'mysql' && get_opinion('DB_TYPE') != 'mysqli') {
         $this->error('当前数据库类型不被支持');
     }
     $M = M();
     if (IS_POST) {
         $System = new \Common\Event\SystemEvent();
         $System->postIntegrity();
         if (empty($_POST['table']) || count($_POST['table']) == 0) {
             $this->jsonReturn(0, "请选择要处理的表");
         }
         $table = implode(',', $_POST['table']);
         if ($_POST['act'] == 'repair') {
             if ($M->query("REPAIR TABLE {$table} ")) {
                 $this->jsonReturn(1, "修复表成功", U('Admin/Data/repair'));
             }
         } elseif ($_POST['act'] == 'optimize') {
             if ($M->query("OPTIMIZE TABLE {$table}")) {
                 $this->jsonReturn(1, "优化表成功", U('Admin/Data/repair'));
             }
         }
         $this->jsonReturn(0, "请选择操作");
     } else {
         $tabs = $M->query('SHOW TABLE STATUS');
         $total_size = array('table' => 0, 'index' => 0, 'data' => 0, 'free' => 0);
         $tables = array();
         foreach ($tabs as $k => $table) {
             $table['size'] = File::byteFormat($table['Data_length'] + $table['Index_length']);
             $total_size['table'] += $table['Data_length'] + $table['Index_length'];
             $total_size['data'] += $table['Data_length'];
             $table['Data_length'] = File::byteFormat($table['Data_length']);
             $total_size['index'] += $table['Index_length'];
             $table['Index_length'] = File::byteFormat($table['Index_length']);
             $total_size['free'] += $table['Data_free'];
             $table['Data_free'] = File::byteFormat($table['Data_free']);
             $tables[] = $table;
         }
         $total_size['table'] = File::byteFormat($total_size['table']);
         $total_size['free'] = File::byteFormat($total_size['free']);
         $total_size['table'] = File::byteFormat($total_size['table']);
         $total_size['data'] = File::byteFormat($total_size['data']);
         $total_size['index'] = File::byteFormat($total_size['index']);
         $this->assign("list", $tables);
         $this->assign("totalsize", $total_size);
         $this->display();
     }
 }
 public function restoreFileHandle($id = '')
 {
     $file_name = base64_decode($id);
     $System = new SystemEvent();
     $zip = new \ZipArchive();
     //新建一个ZipArchive的对象
     if ($zip->open($file_name) === true) {
         $zip->extractTo(WEB_ROOT);
         $zip->close();
         //关闭处理的zip文件
         //File::delFile($file_name);
         $System->clearCacheAll();
     } else {
         $this->error('文件损坏');
     }
     $this->success('还原成功');
 }
 /**
  *
  */
 public function updateHandle()
 {
     G("UpdateHandle");
     $message = "";
     $version = I('get.version');
     $now_version = get_opinion('software_build', true);
     $url = Server_API . 'api/update/' . $now_version . '/';
     $json = json_decode(file_get_contents($url), true);
     G("GetJson");
     $message .= "下载Index文件成功,用时 " . G("UpdateHandle", "getJson") . "秒<br />";
     if (empty($json)) {
         $message .= "连接主升级服务器出错,使用备用服务器<br />";
         // try backup
         $url = Server_API2 . 'api/update/' . $now_version . '/';
         $json = json_decode(file_get_contents($url), true);
         G("GetJson");
         if (empty($json)) {
             $this->error('连接升级服务器出错');
         }
     }
     $target_version_info = $json['file_list'][$version];
     if (!empty($target_version_info)) {
         File::mkDir(WEB_CACHE_PATH);
         G("WebCache");
         $message .= "清空WEB_CACHE_PATH,用时 " . G("GetJson", "WebCache") . "秒<br />";
         $file_downloaded = WEB_CACHE_PATH . $target_version_info['file_name'];
         $file = file_get_contents($target_version_info['file_url']);
         if (File::writeFile($file_downloaded, $file)) {
             G("DownFile");
             $message .= "下载升级文件成功,用时 " . G("WebCache", "DownFile") . "秒<br />";
         } else {
             $this->error('下载文件失败');
         }
         //calculate md5 of file
         $file_md5 = md5_file($file_downloaded);
         G("MD5");
         $message .= "文件MD5值: {$file_md5} ,用时 " . G("DownFile", "MD5") . "秒<br />";
         //todo 系统备份
         $System = new SystemEvent();
         //$System->backupFile();
         G("BackupFile");
         $message .= "系统备份已跳过 ,用时 " . G("MD5", "BackupFile") . "秒<br />";
         $zip = new \ZipArchive();
         //新建一个ZipArchive的对象
         if ($zip->open($file_downloaded) === true) {
             $zip->extractTo(WEB_ROOT);
             //假设解压缩到在当前路径下/文件夹内
             $zip->close();
             //关闭处理的zip文件
             File::delFile($file_downloaded);
             G("UnzipFile");
             $message .= "解压成功 ,用时 " . G("BackupFile", "UnzipFile") . "秒<br />";
             $System->clearCacheAll();
             $message .= "清空缓存成功 <br />";
         } else {
             $this->error('文件损坏');
         }
         $old_build = get_opinion('software_build');
         $new_build = $target_version_info['build_to'];
         set_opinion('software_version', $target_version_info['version_to']);
         set_opinion('software_build', $target_version_info['build_to']);
         set_opinion('db_build', $target_version_info['build_to']);
         if (File::file_exists(Upgrade_PATH . 'init.php')) {
             include Upgrade_PATH . 'init.php';
             if (function_exists("upgrade_" . $old_build . "_to_" . $new_build)) {
                 $fuction_name = "upgrade_" . $old_build . "_to_" . $new_build;
                 G("FunctionStart");
                 call_user_func($fuction_name);
                 G("FunctionEnd");
                 $message .= "处理升级函数 ,用时 " . G("FunctionStart", "FunctionEnd") . "秒 <br />";
             }
         }
         $this->updateComplete('升级成功' . $target_version_info['build_to'] . "<br />" . $message);
     } else {
         $this->error('升级出错');
     }
 }
 /**
  *
  */
 public function updateHandle()
 {
     $version = I('get.version');
     $now_version = get_opinion('software_build', true);
     $url = Server_API . 'api/update/' . $now_version . '/';
     $json = json_decode(file_get_contents($url), true);
     $target_version_info = $json['file_list'][$version];
     if (!empty($target_version_info)) {
         File::mkDir(WEB_CACHE_PATH);
         $file_downloaded = WEB_CACHE_PATH . $target_version_info['file_name'];
         $file = file_get_contents($target_version_info['file_url']);
         File::writeFile($file_downloaded, $file);
         //todo 系统备份
         $System = new SystemEvent();
         //$System->backupFile();
         $zip = new \ZipArchive();
         //新建一个ZipArchive的对象
         if ($zip->open($file_downloaded) === true) {
             $zip->extractTo(WEB_ROOT);
             //假设解压缩到在当前路径下/文件夹内
             $zip->close();
             //关闭处理的zip文件
             File::delFile($file_downloaded);
             $System->clearCacheAll();
         } else {
             $this->error('文件损坏');
         }
         $old_build = get_opinion('software_build');
         $new_build = $target_version_info['build_to'];
         set_opinion('software_version', $target_version_info['version_to']);
         set_opinion('software_build', $target_version_info['build_to']);
         if (File::file_exists(Upgrade_PATH . 'init.php')) {
             include Upgrade_PATH . 'init.php';
             if (function_exists("upgrade_" . $old_build . "_to_" . $new_build)) {
                 $fuction_name = "upgrade_" . $old_build . "_to_" . $new_build;
                 call_user_func($fuction_name);
             }
         }
         $this->success('升级成功' . $target_version_info['build_to'], U('Admin/Index/updateComplete'));
     } else {
         $this->error('升级出错');
     }
 }
 /**
  * @param string $theme_name
  */
 public function themeChangeHandle($theme_name = 'NovaGreenStudio')
 {
     if (get_kv('home_theme') == $theme_name) {
         $this->error('无需切换');
     }
     S('theme_config', null);
     $res = set_kv('home_theme', $theme_name);
     set_kv($theme_name . '_theme_config', null);
     if ($res) {
         $cache_control = new SystemEvent();
         $cache_control->clearCacheAll();
         $this->success('切换成功');
     } else {
         $this->error('切换失败');
     }
 }
 /**
  * @param string $theme_name
  */
 public function themeChangeHandle($theme_name = 'NovaGreenStudio')
 {
     if (get_kv('home_theme') == $theme_name) {
         $this->error('无需切换');
     }
     if ($this->themeStatus($theme_name) == 'disabled') {
         $this->error('请先启用主题');
     }
     $res = set_kv('home_theme', $theme_name);
     if ($res) {
         $cache_control = new SystemEvent();
         $cache_control->clearCacheAll();
         $this->success('切换成功');
     } else {
         $this->error('切换失败');
     }
 }