Exemplo n.º 1
0
 /**
  * 添加一个新模块
  * @param $data {Array}
  *  $name 模块路径
  *  $title 前端显示名
  * @return bool
  */
 public function addModule($data)
 {
     $name = $data['name'];
     $title = $data['title'];
     $info = $this->getInfoByStorename($name);
     if (!empty($info)) {
         show_error($name . '模块已存在', true);
     }
     $modulePath = C('SRC_PATH') . '/' . $name;
     if (!file_exists($modulePath)) {
         mkdir($modulePath, 0777, true);
     }
     $siteSrcPath = C('PROJECT.SITE_PATH') . '/' . C('PROJECT.TEMP_DIR') . '/' . C('PROJECT.SRC_DIR');
     $cmd = 'cd ' . $siteSrcPath . ' && ln -snf ' . C('SRC_PATH') . '/' . $name . '/' . C('MASTER_NAME') . ' ' . $title;
     shell_exec_ensure($cmd, false, false);
     $this->set(array('storename' => $name, 'title' => $title, 'filename' => $title, 'description' => $data['description'], 'fe' => $data['fe']));
     $this->save();
     return true;
 }
Exemplo n.º 2
0
 /**
  * 删除一个文件(夹),同时删除svn
  * @param $path
  */
 public static final function rmLocalAndSvn($path)
 {
     if (is_dir($path)) {
         rm_dir($path);
     } else {
         @unlink($path);
     }
     shell_exec_ensure(C('SVN') . ' del ' . $path . ' --force', false, false);
 }
Exemplo n.º 3
0
 /**
  * co代码
  */
 private function updateBranch()
 {
     //        header('Content-Type: text/event-stream');
     header('Content-Type: text/octet-stream');
     header('Cache-Control: no-cache');
     $url = $_POST['url'];
     $name = $_POST['name'];
     $showInfo = isset($_POST['showInfo']) ? $_POST['showInfo'] : true;
     $path = C('SRC_PATH') . '/' . $name;
     if (!file_exists($path)) {
         show_error($name . '模块不存在', true);
     }
     $hashPos = strpos($url, '#');
     if ($hashPos !== false) {
         $branchName = substr($url, $hashPos + 1);
         $url = substr($url, 0, $hashPos);
     }
     $extension = pathinfo($url, PATHINFO_EXTENSION);
     if ($extension === 'git') {
         $branchName = isset($branchName) ? $branchName : C('MASTER_NAME');
         $cmd = 'cd ' . $path . ' && ' . C('GIT') . ' clone ' . $url . ' ' . $branchName . ' && cd ' . $branchName . ' && ' . C('GIT') . ' checkout ' . $branchName;
     } else {
         // svn
         $cmd = 'cd ' . $path . ' && ' . C('SVN') . ' co ' . $url;
         // 如果url和name basename相同,则为trunk分支,co到trunk目录中
         if (basename($url) === basename($name)) {
             $cmd = $cmd . ' trunk';
         }
     }
     $ret = shell_exec_ensure($cmd, $showInfo, false);
     if ($ret['status']) {
         show_error('命令执行失败:' . $cmd);
     } else {
         $model = new ModuleModel();
         $info = $model->getInfoByStorename($name);
         if (!empty($info)) {
             $info = $info[0];
         }
         show_json($info);
     }
 }
Exemplo n.º 4
0
 function get_type_by_content($content)
 {
     $tempFile = str_random(5);
     $info = null;
     file_put_contents($tempFile, $content);
     $cmd = 'file -nbi ' . $tempFile;
     $ret = shell_exec_ensure($cmd, false, false);
     if (!$ret['status']) {
         $info = $ret['output'];
         $info = explode(';', $info);
         $info = $info[0];
     }
     unlink($tempFile);
     return trim($info);
 }
Exemplo n.º 5
0
 /**
  * 更新各个模块软链接
  * @param $data
  */
 private function updateBranch($data)
 {
     $siteName = $data['siteName'];
     foreach ($data['modules'] as $module) {
         $path = C('PROJECT.SITE_PATH') . '/' . $siteName . '/src/' . $module['filename'];
         //            $svnPath = $this->getSvnPath($module['branch'], $module['type'], $module['storename']);
         $svnPath = C('SRC_PATH') . '/' . $module['storename'] . '/' . $module['branch'];
         $ret = shell_exec_ensure('ln -snf ' . $svnPath . ' ' . $path, false, false);
         if ($ret['status']) {
             show_error($ret['output'], true);
             return false;
         }
     }
     return true;
 }
Exemplo n.º 6
0
 public static function ci()
 {
     shell_exec_ensure(C('SVN') . ' add ' . C('IFRESH.PATH') . ' --force', false);
     shell_exec_ensure(C('SVN') . ' ci "' . C('IFRESH.PATH') . '" -m "commit by M3D::IframeRefreshPlugin"', false);
 }
Exemplo n.º 7
0
 /**
  * 拷贝结果到测试环境
  */
 private function copyToTestEnv()
 {
     $envBuildPath = PROJECT_SITE_PATH . '/' . C('PROJECT.BUILD_DIR') . '/' . PROJECT_MODULE_NAME;
     if (file_exists($envBuildPath)) {
         shell_exec_ensure('rm -rf ' . $envBuildPath . '/*');
     } else {
         mkdir($envBuildPath, 0777, true);
     }
     shell_exec_ensure('cp -rf ' . C('SRC.BUILD_CACHE_PATH') . '/* ' . $envBuildPath);
 }
Exemplo n.º 8
0
 /**
  * 生成最新版本号
  */
 private static function genLatestRevision()
 {
     $cmd = 'cd ' . C('SRC.SRC_PATH') . ' && ' . C('SVN') . ' info --xml';
     $info = shell_exec_ensure($cmd, false);
     if (!$info['status']) {
         $info = $info['output'];
         $info = simplexml_load_string($info);
         $revision = $info->entry->commit->attributes()->revision;
         self::$revision = (int) $revision;
     }
 }
Exemplo n.º 9
0
 /**
  * 将本地非svn方式删除的文件,在svn中删除
  */
 private static function localDelToSvn()
 {
     $cmd = 'cd ' . C('SRC.ROOT') . ' && ' . C('SVN') . ' st';
     $ret = shell_exec_ensure($cmd, false);
     if (!$ret['status']) {
         $list = $ret['output'];
         $list = explode("\n", $list);
         if (!empty($list)) {
             foreach ($list as $item) {
                 // 前8位字符,表示状态信息,去掉
                 $file = trim(substr($item, 8));
                 if (!$file || $file && $file[0] === '.') {
                     continue;
                 }
                 $action = trim(substr($item, 0, 7));
                 $action = $action[0];
                 if ($action === '!') {
                     $cmd = C('SVN') . ' del "' . C('SRC.ROOT') . '/' . $file . '"';
                     shell_exec_ensure($cmd, false);
                 }
             }
         }
     }
 }
Exemplo n.º 10
0
 /**
  * 检查某个文件是否已svn修改
  * @param $file
  * @return bool
  */
 private static function checkFileChange($file, $ver)
 {
     $ret = false;
     $cmd = C('SVN') . ' diff ' . $file . ' -r ' . $ver . ':HEAD --summarize --xml';
     $info = shell_exec_ensure($cmd, false);
     if (!$info['status']) {
         $info = $info['output'];
         $info = simplexml_load_string($info);
         if (isset($info->paths->path)) {
             $ret = true;
         }
     }
     return $ret;
 }