示例#1
0
 public function gc()
 {
     foreach (glob($this->dir . '/*.php') as $f) {
         if (basename($f) != basename($this->file) && filemtime($this->file) + $this->expire < time()) {
             Dir::delFile($f);
         }
     }
 }
示例#2
0
 public function upgrade()
 {
     switch (q('get.action')) {
         case 'downloadLists':
             $data = f('_upgrade_');
             if (empty($data['data']['files'])) {
                 //文件全部下载完成或本次更新没有修改的文件时,更新数据库
                 go(u('upgrade', ['action' => 'sql']));
             }
             return view('downloadLists')->with('data', $data);
             break;
         case 'download':
             $data = f('_upgrade_');
             $fileLists = $data['data']['files'];
             //下载文件,根据文件类型 ADM  AM下载,D删除
             if (empty($fileLists)) {
                 //全部下载完成
                 $res = ['valid' => 2];
             } else {
                 //从第一个文件开始下载
                 $firstFile = current($fileLists);
                 $action = strtoupper($firstFile[0]);
                 $file = trim(substr($firstFile, 1));
                 if ($action == 'D') {
                     if (\Dir::delFile($file)) {
                         array_shift($fileLists);
                         $res = ['valid' => 1];
                     } else {
                         $res = ['valid' => 0];
                     }
                 } else {
                     //下载文件
                     $postData = ['file' => $file, 'releaseCode' => $data['data']['version'][0]['releaseCode']];
                     $content = \Curl::post($this->url . '&a=cloud/download&t=web&siteid=1&m=store', $postData);
                     is_dir(dirname($file)) or mkdir(dirname($file), 0755, TRUE);
                     $res = json_decode($content, TRUE);
                     if (isset($res['valid']) && $res['valid'] == 0) {
                         $res = ['valid' => 0];
                     } else {
                         if (in_array(basename($file), ['database.php'])) {
                             $res = ['valid' => 1, 'file' => $file];
                         } else {
                             if (in_array(dirname($file), ['theme', 'addons', 'attachment'])) {
                                 $res = ['valid' => 1, 'file' => $file];
                             } else {
                                 if (file_put_contents($file, $content)) {
                                     $res = ['valid' => 1, 'file' => $file];
                                 } else {
                                     $res = ['valid' => 0, 'file' => $file];
                                 }
                             }
                         }
                     }
                 }
             }
             $data['data']['files'] = $fileLists;
             f('_upgrade_', $data);
             echo json_encode($res);
             break;
         case 'sql':
             if (IS_POST) {
                 cli('migrate:make');
                 echo json_encode($res = ['valid' => 2]);
                 exit;
             }
             return view('updateSql')->with('data', f('_upgrade_'));
             break;
         case 'finish':
             $data = f('_upgrade_');
             //全部更新完成
             $this->db['id'] = 1;
             $this->db['versionCode'] = $data['data']['version'][0]['versionCode'];
             $this->db['releaseCode'] = $data['data']['version'][0]['releaseCode'];
             $this->db['createtime'] = time();
             $this->db->save();
             //删除更新缓存
             f('_upgrade_', '[del]');
             message('恭喜! 系统更新完成', 'upgrade', 'success');
             break;
         default:
             $hdcms = $this->db->find(1);
             $data = \Curl::get($this->url . "&a=cloud/HdcmsUpgrade&t=web&siteid=1&m=store&AppSecret={$hdcms['AppSecret']}&releaseCode=" . $hdcms['releaseCode']);
             $data = json_decode($data, TRUE);
             f('_upgrade_', $data);
             return view()->with(['data' => $data, 'hdcms' => $hdcms]);
     }
 }