public function getUpdateList($token) { $new_versions = array(); $return = $this->curl(appstoreU('Appstore/Install/getUpdateList', array('token' => $token))); $versions = json_decode($return, true); if ($versions['status'] == 1) { return $versions['updateList']; } else { $this->error = L('_UPDATED_VERSION_LIST_IS_NOT_PRESENT_WITH_PERIOD_'); return false; } }
public function getUpdateList($token) { $new_versions = array(); $return = $this->curl(appstoreU('Appstore/Install/getUpdateList', array('token' => $token))); $versions = json_decode($return, true); if ($versions['status'] == 1) { return $versions['updateList']; } else { $this->error = '更新版本列表不存在。'; return false; } }
private function installModule($version, $token) { $module['name'] = $version['goods']['etitle']; $module['alias'] = $version['goods']['title']; $this->write(' >' . L('_INSTALLING_PARAM_', array('object' => '模块')) . '【' . $module['alias'] . '】【' . $module['name'] . '】'); if (file_exists(APP_PATH . $version['goods']['etitle'])) { //todo 进行版本检测 $this->write(' >' . L('_OBJECT_SAME_EXIST_PARAM_', array('object' => '模块')), 'danger'); $this->goBack(); return false; } //下载文件 $localPath = C('CLOUD_PATH') . $this->switchEntity($version['goods']['entity']) . '/'; $this->createFolder($localPath); $localFile = $localPath . $version['goods']['etitle'] . '.zip'; $this->downloadFile(appstoreU('Appstore/Index/download', array('token' => $token)), $localFile); //开始安装 $this->unzipFile($localFile, APP_PATH); //todo 进行文件合法性检测,防止错误安装。 if (!file_exists(APP_PATH . $version['goods']['etitle'] . '/' . 'Info/info.php')) { $this->write(L('_FILE_VERIFY_FAIL_PLEASE_')); exit; } $moduleModel = M('Common/Module'); $moduleModel->reload(); $module = $moduleModel->getModule($module['name']); $res = $moduleModel->install($module['id']); if ($res === true) { $this->write($moduleModel->getError()); $this->write(' >' . L('_SUCCESS_MODULE_INSTALL_') . L('_PERIOD_'), 'success'); D('Channel')->where(array('url' => $module['entry']))->delete(); $this->write(' >' . L('_SUCCESS_NAV_CLEAR_') . L('_PERIOD_'), 'success'); $channel['title'] = $module['alias']; $channel['url'] = $module['entry']; $channel['sort'] = 100; $channel['status'] = 1; $channel['icon'] = $module['icon']; D('Channel')->add($channel); S('common_nav', null); $this->write(' >' . L('_SUCCESS_NAV_ADD_') . L('_PERIOD_'), 'success'); $tokenFile = APP_PATH . $module['name'] . '/Info/token.ini'; $this->cleanModuleListCache(); if ($moduleModel->setToken($module['name'], $token)) { $this->write(L('_MODULE_INSTALLATION_SUCCESS_'), 'success'); $jump = U('Module/lists'); sleep(2); $this->writeScript(<<<str location.href="{$jump}"; str ); } else { $this->write(L('_SUCCESS_MODULE_INSTALL_BUT_PARAM_', array('object' => '模块', 'tokenFile' => $tokenFile)) . $token, 'warning'); return true; } } else { $this->write(L('_FAIL_MODULE_INSTALL_') . $moduleModel->getError(), 'warning'); } return true; }
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 false; } //下载文件 $localPath = C('CLOUD_PATH') . $this->switchEntity($version['goods']['entity']) . '/'; $this->createFolder($localPath); $localFile = $localPath . $version['goods']['etitle'] . '.zip'; $this->downloadFile(appstoreU('Appstore/Index/download', array('token' => $token)), $localFile); //开始安装 $this->unzipFile($localFile, APP_PATH); //todo 进行文件合法性检测,防止错误安装。 if (!file_exists(APP_PATH . $version['goods']['etitle'] . '/' . 'Info/info.php')) { $this->write('文件验证失败,无法执行安装,请检查文件结构。'); exit; } $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'); $tokenFile = APP_PATH . $module['name'] . '/Info/token.ini'; $this->cleanModuleListCache(); if ($moduleModel->setToken($module['name'], $token)) { $this->write('模块安装成功,即将跳转到本地模块页面。', 'success'); $jump = U('Module/lists'); sleep(2); $this->writeScript(<<<str location.href="{$jump}"; str ); } else { $this->write('模块安装成功,但未能成功写入token,请手动创建并复制token内容到' . $tokenFile . '下。token内容<br/>' . $token, 'warning'); return true; } } else { $this->write('模块安装失败。错误信息:' . $moduleModel->getError(), 'warning'); } return true; }