|
@@ -1,8 +1,8 @@
|
|
<?php
|
|
<?php
|
|
namespace DistributeHelper;
|
|
namespace DistributeHelper;
|
|
error_reporting(E_ALL & ~E_NOTICE);
|
|
error_reporting(E_ALL & ~E_NOTICE);
|
|
-include "Utility.php";
|
|
|
|
-include "WscriptShell.php";
|
|
|
|
|
|
+include_once "Utility.php";
|
|
|
|
+include_once "WscriptShell.php";
|
|
|
|
|
|
class PackageClass
|
|
class PackageClass
|
|
{
|
|
{
|
|
@@ -24,7 +24,13 @@ class PackageClass
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
logInfo("distribute mode: ",self::$config['distribute-mode']);
|
|
logInfo("distribute mode: ",self::$config['distribute-mode']);
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ //预先系统准备操作
|
|
|
|
+ if(! self::prepare($vendorDir,$rootPkg) ){
|
|
|
|
+ self::setProgressFailed('PREPARE_FAILED');
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
//分发模式
|
|
//分发模式
|
|
if( self::$config['distribute-mode'] == 'install'){
|
|
if( self::$config['distribute-mode'] == 'install'){
|
|
self::install($vendorDir,$rootPkg,$vendorPkgs);
|
|
self::install($vendorDir,$rootPkg,$vendorPkgs);
|
|
@@ -35,6 +41,20 @@ class PackageClass
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private static function prepare($vendorDir,$pkg)
|
|
|
|
+ {
|
|
|
|
+ //获取包信息
|
|
|
|
+ $repoDir = dirname($vendorDir);
|
|
|
|
+ $packageInfo = self::getPackageInfo($vendorDir,$repoDir,$pkg);
|
|
|
|
+
|
|
|
|
+ //关闭进程
|
|
|
|
+ if(! self::removeProcess($packageInfo) ){
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
private static function install($vendorDir,$rootPkg,$vendorPkgs){
|
|
private static function install($vendorDir,$rootPkg,$vendorPkgs){
|
|
//依赖库都已下载,默认先给个进度
|
|
//依赖库都已下载,默认先给个进度
|
|
self::setProgressStep1(100);
|
|
self::setProgressStep1(100);
|
|
@@ -176,6 +196,9 @@ class PackageClass
|
|
if( !file_exists($distributeDir) ){
|
|
if( !file_exists($distributeDir) ){
|
|
createDirectory($distributeDir);
|
|
createDirectory($distributeDir);
|
|
}
|
|
}
|
|
|
|
+ if(! defined('DIST_DIR')){
|
|
|
|
+ define('DIST_DIR',$distributeDir);
|
|
|
|
+ }
|
|
|
|
|
|
//设置日志文件路径
|
|
//设置日志文件路径
|
|
if(! defined('LOG_PATH')){
|
|
if(! defined('LOG_PATH')){
|
|
@@ -385,6 +408,39 @@ class PackageClass
|
|
return true;
|
|
return true;
|
|
}*/
|
|
}*/
|
|
|
|
|
|
|
|
+ private static function removeProcess($packageInfo)
|
|
|
|
+ {
|
|
|
|
+ $app = self::$app;
|
|
|
|
+ $cacheDir = $packageInfo['cacheDir'];
|
|
|
|
+ $repoName = $packageInfo['repoName'];
|
|
|
|
+ $version = $packageInfo['version'];
|
|
|
|
+ $rootDir = $packageInfo['rootDir'];
|
|
|
|
+ $removeProcess = $app["distribute-root"]["remove-process"] ? : array();
|
|
|
|
+ $proc = new WinProcess(DIST_DIR);
|
|
|
|
+ foreach($removeProcess as $process){
|
|
|
|
+ $name = $process['name'];
|
|
|
|
+ //获取进程PIDs
|
|
|
|
+ $pids = $proc->find($name);
|
|
|
|
+ if( $pids === false ){
|
|
|
|
+ logError("failed to find process, action failed.",$name);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ if( count($pids) === 0 ){
|
|
|
|
+ logInfo("process not exists.no need to remove process",$name);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ //移除进程
|
|
|
|
+ $ret = $proc->remove($name);
|
|
|
|
+ if( $ret === false ){
|
|
|
|
+ logError("failed to remove process, remove action failed.",$name);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ logInfo("succeeded to remove process",$name);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
//拷贝copy-files文件
|
|
//拷贝copy-files文件
|
|
private static function copyFiles($packageInfo)
|
|
private static function copyFiles($packageInfo)
|
|
{
|
|
{
|