|
@@ -11,12 +11,12 @@ class PackageClass
|
|
|
{
|
|
|
//初始化
|
|
|
if(! self::initialize($vendorDir)){
|
|
|
- self::setUpdateFailed('INITIALIZE_FAILED');
|
|
|
+ self::setProgressFailed('INITIALIZE_FAILED');
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
//依赖库都已下载,默认先给个进度
|
|
|
- self::updateProgress(0,100);
|
|
|
+ self::setProgressStep1(100);
|
|
|
|
|
|
//逐个依赖仓库操作
|
|
|
self::postUpdateVendorPkgs($vendorDir,$vendorPkgs);
|
|
@@ -25,12 +25,13 @@ class PackageClass
|
|
|
self::postUpdateRootPkg($vendorDir,$rootPkg);
|
|
|
|
|
|
//全部操作完毕
|
|
|
- self::setUpdateOK(true);
|
|
|
+ self::setProgressOK(true);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
private static function postUpdateVendorPkgs($vendorDir,$vendorPkgs)
|
|
|
{
|
|
|
+ $count = count($vendorPkgs);
|
|
|
foreach($vendorPkgs as $i=>$pkg){
|
|
|
//获取包信息
|
|
|
$repoDir = pathJoin($vendorDir,$pkg->getName());
|
|
@@ -38,16 +39,15 @@ class PackageClass
|
|
|
|
|
|
//获取当前包的module文件
|
|
|
self::fetchModuleFiles($packageInfo);
|
|
|
+ self::setProgressStep2($count,$i,1);
|
|
|
|
|
|
//获取当前包的common文件
|
|
|
self::fetchCommonFiles($packageInfo);
|
|
|
+ self::setProgressStep2($count,$i,2);
|
|
|
|
|
|
//拷贝当前包的config文件
|
|
|
self::copyConfigFiles($packageInfo);
|
|
|
-
|
|
|
- //更新部署进度
|
|
|
- $percent = intval(100.0 * ($i+1) / count(vendorPkgs));
|
|
|
- self::updateProgress(1,$percent);
|
|
|
+ self::setProgressStep2($count,$i,3);
|
|
|
}
|
|
|
}
|
|
|
private static function postUpdateRootPkg($vendorDir,$pkg)
|
|
@@ -112,15 +112,22 @@ class PackageClass
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- private static function updateProgress($step,$percent)
|
|
|
+ private static function setProgressStep1($percent)
|
|
|
{
|
|
|
- file_put_contents(PROGRESS_PATH,strval($percent));
|
|
|
+ $progress = 0.1 * $percent;
|
|
|
+ file_put_contents(PROGRESS_PATH,strval($progress));
|
|
|
}
|
|
|
- private static function setUpdateFailed($msg)
|
|
|
+ private static function setProgressStep2($total,$index,$step)
|
|
|
+ {
|
|
|
+ $index = $index + $step/3.0;
|
|
|
+ $progress = 10 + intval(90.0 * $index / $total);
|
|
|
+ file_put_contents(PROGRESS_PATH,strval($progress));
|
|
|
+ }
|
|
|
+ private static function setProgressFailed($msg)
|
|
|
{
|
|
|
file_put_contents(PROGRESS_PATH,"FAIL:" . $msg);
|
|
|
}
|
|
|
- private static function setUpdateOK($restart)
|
|
|
+ private static function setProgressOK($restart)
|
|
|
{
|
|
|
if($restart){
|
|
|
file_put_contents(PROGRESS_PATH,"OK:NEED_RESTART");
|
|
@@ -133,6 +140,9 @@ class PackageClass
|
|
|
private static function getPackageInfo($vendorDir,$repoDir,$pkg)
|
|
|
{
|
|
|
$config = self::$config;
|
|
|
+ $version = $pkg->getPrettyVersion();
|
|
|
+ if($version == 'dev-master')
|
|
|
+ $version = 'master';
|
|
|
|
|
|
$cfgPath = pathJoin($repoDir,'composer.json');
|
|
|
$data = json_decode(file_get_contents($cfgPath), true);
|
|
@@ -143,16 +153,16 @@ class PackageClass
|
|
|
$rootDir = dirname($vendorDir);
|
|
|
$commonDir = pathJoin($rootDir,'siscom');
|
|
|
$configDir = pathJoin($rootDir,'config',$moduleName);
|
|
|
- $moduleDir = pathJoin($rootDir,'module',$moduleName . '-' . $pkg->getPrettyVersion());
|
|
|
+ $moduleDir = pathJoin($rootDir,'module',$moduleName . '-' . $version);
|
|
|
|
|
|
//获取缓存目录
|
|
|
- $cacheName = str_replace('/','-',$pkg->getName()) . '-' . $pkg->getPrettyVersion();
|
|
|
+ $cacheName = str_replace('/','-',$pkg->getName()) . '-' . $version;
|
|
|
$cacheDir = pathJoin($config['cache-dir'],$cacheName);
|
|
|
|
|
|
//返回包的相关信息
|
|
|
return array(
|
|
|
"repoName" => $pkg->getName(),
|
|
|
- "version" => $pkg->getPrettyVersion(),
|
|
|
+ "version" => $version,
|
|
|
"cacheDir" => $cacheDir,
|
|
|
"toolDir" => $config['tool-dir'],
|
|
|
"ossHost" => $config['oss-host'],
|
|
@@ -181,7 +191,6 @@ class PackageClass
|
|
|
|
|
|
foreach($moduleFiles as $fileInfo){
|
|
|
$fileName = $fileInfo['name'];
|
|
|
- logInfo($repoName,"fetching module file -- ",$fileName);
|
|
|
|
|
|
//下载文件到缓存区
|
|
|
$filePath = downloadToDir($toolDir,$ossHost,$repoName,$version,$fileName,$cacheDir);
|
|
@@ -189,6 +198,7 @@ class PackageClass
|
|
|
logError($repoName,"fetch module file failed",$fileName);
|
|
|
return false;
|
|
|
}
|
|
|
+ logInfo($repoName,"module file fetched-- ",$fileName);
|
|
|
|
|
|
// 解压文件
|
|
|
if( isZipFile($fileName) ){
|
|
@@ -216,13 +226,13 @@ class PackageClass
|
|
|
}
|
|
|
foreach($commonFiles as $fileInfo){
|
|
|
$fileName = $fileInfo['name'];
|
|
|
- logInfo($repoName,"fetching common file -- ",$fileName);
|
|
|
//下载文件到缓存区
|
|
|
$filePath = downloadToDir($toolDir,$ossHost,$repoName,$version,$fileName,$cacheDir);
|
|
|
if(! $filePath ){
|
|
|
logError($repoName,"fetch common file failed",$fileName);
|
|
|
- continue;
|
|
|
+ return false;
|
|
|
}
|
|
|
+ logInfo($repoName,"common file fetched -- ",$fileName);
|
|
|
|
|
|
// 解压文件
|
|
|
if( isZipFile($fileName) ){
|