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 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); }