public function generate() { $addons = Wekit::load('APPS:appcenter.service.srv.PwInstallApplication')->getConfig('style-type'); $base = str_replace('/', '.', $addons[$this->style_type][1]); $this->defaultDir = Wind::getRealDir('THEMES:' . $base . '.default'); if (!is_dir($this->defaultDir)) { return new PwError('APPCENTER:generate.style.unsupport'); } $this->baseDir = Wind::getRealDir('THEMES:' . $base . '.' . $this->alias); if (is_dir($this->baseDir)) { return new PwError('APPCENTER:alias.exist'); } WindFolder::mkRecur($this->baseDir); Wind::import('APPS:appcenter.service.srv.helper.PwSystemHelper'); $writable = PwSystemHelper::checkWriteAble($this->baseDir . '/'); if (!$writable) { return new PwError('APPCENTER:generate.copy.fail'); } PwApplicationHelper::copyRecursive($this->defaultDir, $this->baseDir); $file = $this->baseDir . '/Manifest.xml'; Wind::import('WIND:parser.WindXmlParser'); $parser = new WindXmlParser(); $manifest = $parser->parse($file); $manifest['application']['name'] = $this->name; $manifest['application']['alias'] = $this->alias; $manifest['application']['description'] = $this->description; $manifest['application']['version'] = $this->version; $manifest['application']['pw-version'] = $this->pwversion; $manifest['application']['website'] = $this->website; $manifest['application']['author-name'] = $this->author; $manifest['application']['author-email'] = $this->email; $parser = new WindXmlParser(); $manifest = str_replace('><', ">\n\t<", $parser->parseToXml(array('manifest' => $manifest), Wind::getApp()->getResponse()->getCharset())); WindFile::write($this->baseDir . '/Manifest.xml', $manifest); return 'THEMES:' . $base . '.' . $this->alias; }
/** * 更新成功后备份 * * @return multitype:string */ private function _backSuccess() { $data_dir = Wind::getRealDir('DATA:'); $suffix = '[' . Pw::time2str(WEKIT_TIMESTAMP, 'Y-m-d Hi') . ']'; $up_source = $data_dir . 'upgrade'; $up_target = $data_dir . 'upgrade' . $suffix; PwApplicationHelper::copyRecursive($up_source, $up_target); $status = Wekit::cache()->get('system_upgrade'); $ba_source = $data_dir . 'backup' . DIRECTORY_SEPARATOR . 'phpwind_' . str_replace('.', '', $status['oldversion']) . '_' . $status['oldrelease']; $ba_target = $data_dir . 'backup' . $suffix; PwApplicationHelper::copyRecursive($ba_source, $ba_target); WindFolder::clearRecur($up_source, true); WindFolder::clearRecur($ba_source, true); return array($up_target, $ba_target); }
/** * 下载 * 1、下载zip包 * 2、单个文件下载 */ public function download($downloadUrl, $hash, $file = '') { if ($this->useZip) { list($bool, $package) = PwSystemHelper::download($downloadUrl, $this->tmpPath . '/' . basename($downloadUrl)); if (!$bool) { return new PwError($package); } if ($hash !== md5_file($package)) { $this->_log('check Package fail. expected hash:' . $hash . 'real hash :' . md5_file($package)); return new PwError('APPCENTER:install.checkpackage.fail'); } $this->_log('download zip success, dir:' . $package); $this->tmpPackage = $this->tmpPath . DIRECTORY_SEPARATOR . $this->target; $r = PwApplicationHelper::extract($package, $this->tmpPath); if ($r === false) { $this->_log('extract Package fail. '); return new PwError('APPCENTER:install.checkpackage.format.fail', array('{{error}}' => $r)); } if ($r != realpath($this->tmpPackage)) { PwApplicationHelper::copyRecursive($r, $this->tmpPackage); } $this->_log('extract zip success, dir:' . $this->tmpPackage); return true; } else { $_file = $this->tmpPath . DIRECTORY_SEPARATOR . $this->target . DIRECTORY_SEPARATOR . $file; $dir = dirname($_file); list($bool, $_file) = PwSystemHelper::download($downloadUrl . '/' . $file . 'wind', $_file); if (!$bool) { return new PwError($_file); } if ($hash !== md5_file($_file)) { $this->_log('check file fail. expected hash:' . $hash . 'real hash :' . md5_file($_file)); return new PwError('APPCENTER:upgrade.check.file.fail'); } $this->_log('download file success, file:' . $_file); return true; } }
/** * * @param PwInstallApplication $install */ public function afterInstall($install) { $tmp = $install->getTmpPackage(); WindFile::del($tmp . '/Manifest.xml'); PwApplicationHelper::copyRecursive($tmp, ROOT_PATH); }
/** * 注册静态资源 * * @param PwInstallApplication $install * @return PwError true */ public function registeResource($install) { $manifest = $install->getManifest()->getManifest(); if (!isset($manifest['res']) || !$manifest['res']) { return true; } $name = $install->getManifest()->getApplication('alias'); $source = $install->getTmpPackage() . '/' . str_replace('.', '/', $manifest['res']); $targetPath = Wind::getRealDir('THEMES:extres', true); if (!is_dir($source)) { return true; } $writable = PwSystemHelper::checkWriteAble($targetPath . '/'); if (!$writable) { return new PwError('APPCENTER:install.mv.fail', array('{{error}}' => 'THEMES:extres.' . $name)); } PwApplicationHelper::copyRecursive($source, $targetPath . '/' . $name); $install->addInstallLog('packs', $targetPath . '/' . $name); file_put_contents(DATA_PATH . 'tmp/log', 'res!', FILE_APPEND); }
/** * 复制资源文件 * * @param unknown_type $alias * @param unknown_type $manifest * @return boolean */ private function _copyRes($alias, $manifest) { $this->app = $this->_appDs()->findByAlias($alias); $this->app_id = $this->app['app_id']; $this->manifest = new PwManifest($manifest); $man_array = $this->manifest->getManifest(); $log = array(); if ($man_array['res']) { $source = dirname($manifest) . DIRECTORY_SEPARATOR . str_replace('.', DIRECTORY_SEPARATOR, $man_array['res']); $targetPath = Wind::getRealDir('THEMES:extres.' . $alias, true); if (!is_dir($source)) { return false; } PwApplicationHelper::copyRecursive($source, $targetPath); $app_log = $this->_loadInstallLog()->findByAppId($this->app_id); $packs_log = array(); foreach ($app_log as $v) { if ($v['log_type'] == 'packs') { $packs_log = $v['data']; } } if (!in_array($targetPath, $packs_log)) { $packs_log[] = $targetPath; } $log[] = array('app_id' => $this->app_id, 'log_type' => 'packs', 'data' => $packs_log, 'created_time' => WEKIT_TIMESTAMP, 'modified_time' => WEKIT_TIMESTAMP); } $log && $this->_loadInstallLog()->batchAdd($log); }
public function generate() { $this->baseDir = Wind::getRealDir('EXT:' . $this->alias); if (is_dir($this->baseDir)) { return new PwError('APPCENTER:alias.exist'); } WindFolder::mkRecur($this->baseDir); Wind::import('APPCENTER:service.srv.helper.PwSystemHelper'); $writable = PwSystemHelper::checkWriteAble($this->baseDir . '/'); if (!$writable) { return new PwError('APPCENTER:generate.copy.fail'); } PwApplicationHelper::copyRecursive($this->defaultDir, $this->baseDir, array('service')); $manifest = WindFile::read($this->baseDir . '/Manifest.xml'); $this->manifest = $this->_strtr($manifest); $this->_generateAdmin(); WindFile::write($this->baseDir . '/Manifest.xml', $this->manifest); $this->_resolveTemplate(); $this->_generateService(); return true; }