protected function install($pack) { $manifest = $pack . '/Manifest.xml'; if (!is_file($manifest)) { return false; } /* @var $install PwInstallApplication */ Wind::import('APPS:appcenter.service.srv.PwInstallApplication'); $install = new PwInstallApplication(); /* @var $_install PwStyleInstall */ $_install = Wekit::load('APPS:appcenter.service.srv.do.PwStyleInstall'); $conf = $install->getConfig('install-type', 'style'); $r = $install->initInstall($manifest); if ($r instanceof PwError) { return false; } $r = $_install->install($install); if ($r instanceof PwError) { return false; } $r = $_install->registeApplication($install); if ($r instanceof PwError) { return false; } $install->addInstallLog('packs', $pack); $install->addInstallLog('service', $conf); $fields = array(); foreach ($install->getInstallLog() as $key => $value) { $_tmp = array('app_id' => $install->getAppId(), 'log_type' => $key, 'data' => $value, 'created_time' => time(), 'modified_time' => time()); $fields[] = $_tmp; } Wekit::load('APPS:appcenter.service.PwApplicationLog')->batchAdd($fields); return $install->getAppId(); }
/** * * @param PwInstallApplication $install */ protected function getStyleType($install) { $allow_style_type = $install->getConfig('style-type'); $style_type = $install->getManifest()->getApplication('style-type'); if (!$style_type || !isset($allow_style_type[$style_type])) { $style_type = key($allow_style_type); } return array($style_type, $allow_style_type[$style_type][1]); }
/** * Enter description here . * * * .. * * @param unknown_type $type * @param PwInstallApplication $install * @return PwError boolean */ protected function _install($type, $install) { $manifest = $install->getManifest(); if (!$this->link) { $this->link = 'index.php?m=app&app=' . $manifest->getApplication('alias'); } $dm = new PwNavDm(); $dm->setLink($this->link)->setType($type); if ($type == 'my') { $prefix = Wind::getComponent('i18n')->getMessage('ADMIN:nav.my.prefix'); $dm->setName($prefix . $manifest->getApplication('name'))->setSign($manifest->getApplication('alias')); } else { $dm->setName($manifest->getApplication('name')); } $id = $this->_navDs()->addNav($dm); if ($id instanceof PwError) { return $id; } $install->addInstallLog('nav', $id); $this->update(); file_put_contents(DATA_PATH . 'tmp/log', 'nav!', FILE_APPEND); 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 string $manifestFile * @param string $package */ private function _install($pack) { /* @var $install PwInstallApplication */ Wind::import('APPCENTER:service.srv.PwInstallApplication'); $install = new PwInstallApplication(); /* @var $_install PwStyleInstall */ $_install = Wekit::load('APPCENTER:service.srv.do.PwStyleInstall'); $conf = $install->getConfig('install-type', 'style'); $manifest = $pack . '/Manifest.xml'; if (!is_file($manifest)) { $this->showError('APPCENTER:install.mainfest.not.exist'); } $r = $install->initInstall($manifest); if ($r instanceof PwError) { $this->showError($r->getError()); } $r = $_install->install($install); if ($r instanceof PwError) { $this->showError($r->getError()); } $r = $_install->registeApplication($install); if ($r instanceof PwError) { $this->showError($r->getError()); } $install->addInstallLog('packs', $pack); $install->addInstallLog('service', $conf); $fields = array(); foreach ($install->getInstallLog() as $key => $value) { $_tmp = array('app_id' => $install->getAppId(), 'log_type' => $key, 'data' => $value, 'created_time' => Pw::getTime(), 'modified_time' => Pw::getTime()); $fields[] = $_tmp; } Wekit::load('APPCENTER:service.PwApplicationLog')->batchAdd($fields); }
/** * 扫描完安装 * * @param unknown_type $pack */ public function installPack($pack) { Wind::import('APPCENTER:service.srv.PwInstallApplication'); $install = new PwInstallApplication(); /* @var $_install PwInstall */ $_install = Wekit::load('APPCENTER:service.srv.do.PwInstall'); $conf = $install->getConfig('install-type', 'app'); $manifest = $pack . '/Manifest.xml'; if (!is_file($manifest)) { return $this->_e(null, new PwError('file.not.exist - ' . $manifest)); } $install->setTmpPackage($pack); $r = $install->initInstall($manifest); if ($r instanceof PwError) { return $this->_e(null, $r); } try { $r = $_install->install($install); if ($r instanceof PwError) { return $this->_e($install, $r); } $r = $_install->registeHooks($install); if ($r instanceof PwError) { return $this->_e($install, $r); } $r = $_install->registeInjectServices($install); if ($r instanceof PwError) { return $this->_e($install, $r); } $r = $_install->registeData($install); if ($r instanceof PwError) { return $this->_e($install, $r); } foreach ($install->getManifest()->getInstallationService() as $var) { $_tmp = $install->getConfig('installation-service', $var); if (!$_tmp) { continue; } $toinstall = Wekit::load($_tmp['class']); if (!$toinstall instanceof iPwInstall) { continue; } $_tmp['_key'] = $var; $_m = empty($_tmp['method']) ? 'install' : $_tmp['method']; $r = $toinstall->{$_m}($install); if ($r instanceof PwError) { return $this->_e($install, $r); } $install->addInstallLog('service', $_tmp); } $manifest = $install->getManifest()->getManifest(); if (isset($manifest['install']) && $manifest['install']) { $_tmp = array('class' => $manifest['install']); $toinstall = Wekit::load($manifest['install']); if (!$toinstall instanceof iPwInstall) { continue; } $r = $toinstall->install($install); if ($r instanceof PwError) { return $this->_e($install, $r); } $install->addInstallLog('service', $_tmp); } $r = $_install->registeResource($install); if ($r instanceof PwError) { return $this->_e($install, $r); } $r = $_install->registeApplication($install); if ($r instanceof PwError) { return $this->_e($install, $r); } } catch (Exception $e) { $error = $e->getMessage(); is_array($error) || ($error = array('APPCENTER:install.fail', array('{{error}}' => $e->getMessage()))); return $this->_e($install, new PwError($error[0], $error[1])); } $install->addInstallLog('packs', $pack); $install->addInstallLog('service', $conf); $fields = array(); foreach ($install->getInstallLog() as $key => $value) { $_tmp = array('app_id' => $install->getAppId(), 'log_type' => $key, 'data' => $value, 'created_time' => time(), 'modified_time' => time()); $fields[] = $_tmp; } Wekit::load('APPCENTER:service.PwApplicationLog')->batchAdd($fields); }