/** * 重新从服务器获取所有的版本信息并更新本地 */ public function refreshVersions() { $content = file_get_contents(C('__CLOUD__') . cloudU('Appstore/Update/versions')); $versions = json_decode($content, true); foreach ($versions as $key => $v) { $version = $this->where(array('name' => $v['name']))->find(); if (!$version) { $this->add($v); } else { unset($v['update_time']); $version = $v + $version; $this->save($version); } } $this->where(array('name' => array('not in', getSubByKey($versions, 'name'))))->delete(); }
/** * 获取文件列表 */ public function getFileList() { $aVersion = I('get.version', '', 'text'); if ($aVersion == '') { $this->error(L('_UPGRADE_FAILED_PLEASE_CONFIRM_THE_VERSION_')); } $versionModel = M('Version'); $nextVersion = $versionModel->getNextVersion(); if ($aVersion != $nextVersion['name']) { $this->error(L('_THIS_VERSION_DOES_NOT_ALLOW_THE_CURRENT_VERSION_TO_UPGRADE_')); } $this->assign('path', C('UPDATE_PATH') . $nextVersion['name']); /*版本正确性检测↑*/ $currentVersion = $versionModel->getCurrentVersion(); $this->assign('currentVersion', $currentVersion); $this->assign('nextVersion', $nextVersion); $this->disableCheckUpdate(); $this->display(); $this->writeMessage(L('_ORIGIN_PACK_DOWNLOAD_START_')); set_time_limit(0); $old_file_path = C('UPDATE_PATH') . $nextVersion['name'] . '/old'; $new_file_path = C('UPDATE_PATH') . $nextVersion['name'] . '/new'; if (!$this->createFolder($old_file_path)) { $this->write(L('_CREATE_DIRECTORY_FAILED_') . $old_file_path . L('_PLEASE_CHECK_THE_PERMISSIONS_'), 'danger'); return; } if (!$this->createFolder($new_file_path)) { $this->write(L('_CREATE_DIRECTORY_FAILED_') . $new_file_path . L('_PLEASE_CHECK_THE_PERMISSIONS_'), 'danger'); return; } $this->downloadFile(C('__CLOUD__') . cloudU('Appstore/Update/download', array('number' => $nextVersion['number'], 'type' => 'old')), C('UPDATE_PATH') . $nextVersion['name'] . '/old.zip'); $this->unzipFile(C('UPDATE_PATH') . $nextVersion['name'] . '/old.zip', $old_file_path); $this->writeMessage('开始下载升级文件包。<br/>'); $this->downloadFile(C('__CLOUD__') . cloudU('Appstore/Update/download', array('number' => $nextVersion['number'], 'type' => 'new')), C('UPDATE_PATH') . $nextVersion['name'] . '/new.zip'); $this->unzipFile(C('UPDATE_PATH') . $nextVersion['name'] . '/new.zip', $new_file_path); $files = $this->treeDirectory($new_file_path, $new_file_path); foreach ($files as $v) { $this->writeFile($v); } $this->writeScript('enable()'); $_SESSION['nextVersion'] = $nextVersion; $_SESSION['currentVersion'] = $currentVersion; }
function appstoreU($url, $p = array()) { return C('__CLOUD__') . cloudU($url, $p); }
private function installModule($version, $token) { $module['name'] = $version['goods']['etitle']; $module['alias'] = $version['goods']['title']; $this->write(' >当前正在安装的是【模块】,模块名【' . $module['alias'] . '】【' . $module['name'] . '】'); if (file_exists(APP_PATH . '/' . $version['goods']['etitle'])) { //todo 进行版本检测 $this->write(' >本地已存在同名模块,安装被强制终止。请删除本地模块之后刷新本页面重试。3秒后回到上一页。', 'danger'); $this->goBack(); return; } //下载文件 $localPath = APP_PATH . '/'; $localFile = $localPath . $version['goods']['etitle'] . '.zip'; $this->downloadFile($this->url(cloudU('Appstore/Index/download', array('token' => $token))), APP_PATH . '/' . $version['goods']['etitle'] . '.zip'); chmod($localFile, 0777); //开始安装 require_once "./ThinkPHP/Library/OT/PclZip.class.php"; $archive = new \PclZip($localFile); $this->write('开始安装模块......'); $this->write(' >开始解压安装包......'); $list = $archive->extract(PCLZIP_OPT_PATH, $localPath); $this->write(' >解压成功。', 'success'); //todo 进行文件合法性检测,防止错误安装。 $moduleModel = D('Common/Module'); $moduleModel->reload(); $module = $moduleModel->getModule($module['name']); $res = $moduleModel->install($module['id']); if ($res === true) { $this->write($moduleModel->getError()); $this->write(' >安装模块成功。', 'success'); M('Channel')->where(array('url' => $module['entry']))->delete(); $this->write(' >清理原有的模块导航成功。', 'success'); $channel['title'] = $module['alias']; $channel['url'] = $module['entry']; $channel['sort'] = 100; $channel['status'] = 1; $channel['icon'] = $module['icon']; M('Channel')->add($channel); S('common_nav', null); $this->write(' >导航添加成功。', 'success'); $this->write('模块安装成功,即将跳转到本地模块页面。', 'success'); $jump = U('Module/lists'); sleep(2); $this->writeScript(<<<str location.href="{$jump}"; str ); } else { $this->write('模块安装失败。错误信息:' . $moduleModel->getError(), 'warning'); } }
/** * 获取文件列表 */ public function getFileList() { $aVersion = I('get.version', '', 'text'); if ($aVersion == '') { $this->error('升级失败,请确认版本。'); } $versionModel = D('Version'); $nextVersion = $versionModel->getNextVersion(); if ($aVersion != $nextVersion['name']) { $this->error('此版本不允许当前版本升级,请不要跳过中间版本。'); } $this->assign('path', C('UPDATE_PATH') . $nextVersion['name']); /*版本正确性检测↑*/ $currentVersion = $versionModel->getCurrentVersion(); $this->assign('currentVersion', $currentVersion); $this->assign('nextVersion', $nextVersion); $this->disableCheckUpdate(); $this->display(); $this->writeMessage('开始下载原版文件包。<br/>'); set_time_limit(0); $old_file_path = C('UPDATE_PATH') . $nextVersion['name'] . '/old'; $new_file_path = C('UPDATE_PATH') . $nextVersion['name'] . '/new'; if (!$this->createFolder($old_file_path)) { $this->write('创建目录失败' . $old_file_path . '请检查权限。', 'danger'); return; } if (!$this->createFolder($new_file_path)) { $this->write('创建目录失败' . $new_file_path . '请检查权限。', 'danger'); return; } $this->downloadFile(C('__CLOUD__') . cloudU('Appstore/Update/download', array('number' => $nextVersion['number'], 'type' => 'old')), C('UPDATE_PATH') . $nextVersion['name'] . '/old.zip'); $this->unzipFile(C('UPDATE_PATH') . $nextVersion['name'] . '/old.zip', $old_file_path); $this->writeMessage('开始下载升级文件包。<br/>'); $this->downloadFile(C('__CLOUD__') . cloudU('Appstore/Update/download', array('number' => $nextVersion['number'], 'type' => 'new')), C('UPDATE_PATH') . $nextVersion['name'] . '/new.zip'); $this->unzipFile(C('UPDATE_PATH') . $nextVersion['name'] . '/new.zip', $new_file_path); $files = $this->treeDirectory($new_file_path, $new_file_path); foreach ($files as $v) { $this->writeFile($v); } $this->writeScript('enable()'); $_SESSION['nextVersion'] = $nextVersion; $_SESSION['currentVersion'] = $currentVersion; }