コード例 #1
0
 /**
  *
  */
 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('升级出错');
     }
 }
コード例 #2
0
 /**
  */
 public function pluginExportHandle($plugin_name = '')
 {
     $plugin_path = 'Addons/' . $plugin_name . '/';
     $temp_path = WEB_CACHE_PATH;
     File::delDir(WEB_CACHE_PATH);
     File::mkDir(WEB_CACHE_PATH);
     $file_path = $temp_path . "\\" . 'GCS_Plugin-' . $plugin_name . '-' . md5(time()) . '.zip';
     $zip = new \ZipArchive();
     //新建一个ZipArchive的对象
     $res = $zip->open($file_path, \ZipArchive::CREATE);
     if ($res == true) {
         PHPZip::folderToZip($plugin_path, $zip);
         $zip->close();
     }
     if (!File::file_exists($file_path)) {
         $this->error("该文件不存在,可能是被删除");
     }
     $filename = basename($file_path);
     header("Content-type: application/octet-stream");
     header('Content-Disposition: attachment; filename="' . $filename . '"');
     header("Content-Length: " . filesize($file_path));
     readfile($file_path);
 }
コード例 #3
0
 /**
  *
  */
 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('升级出错');
     }
 }
コード例 #4
0
 public function themeAddLocal()
 {
     File::mkDir(WEB_CACHE_PATH);
     $config = array('rootPath' => WEB_CACHE_PATH, "savePath" => '', "maxSize" => 100000000, "exts" => array('zip'), "subName" => array());
     $upload = new Upload($config);
     $info = $upload->upload();
     if (!$info) {
         // 上传错误提示错误信息
         $this->error($upload->getError());
     } else {
         // 上传成功 获取上传文件信息
         $file_path_full = $info['file']['fullpath'];
         //dump($info);die($file_path_full);
         if (File::file_exists($file_path_full)) {
             $Update = new UpdateEvent();
             $applyRes = $Update->applyPatch($file_path_full);
             $applyInfo = json_decode($applyRes, true);
             if ($applyInfo['status']) {
                 $this->success($applyInfo['info'], U('Admin/Custom/theme'));
             } else {
                 $this->error($applyInfo['info']);
             }
         } else {
             $this->error('文件不存在');
         }
     }
 }