- [misc] delete unused code.

This commit is contained in:
caoyanyi
2024-07-29 15:43:47 +08:00
committed by 李阳
parent 82910f6981
commit 95c40ccd34
4 changed files with 0 additions and 360 deletions
-14
View File
@@ -1,14 +0,0 @@
VERSION=$(shell head -n 1 VERSION)
all: zip
clean:
rm -fr syncer
rm -fr *.zip
zip:
mkdir -p syncer/
cp -fr ../../../lib/api/api.class.php syncer/
cp -fr config.php syncer/
cp -fr syncer.php syncer/
zip -r -9 svnsyncer.$(VERSION).zip syncer
rm -fr syncer
-1
View File
@@ -1 +0,0 @@
1.0.beta
-46
View File
@@ -1,46 +0,0 @@
<?php
/**
* 1. client设置: svn客户端执行文件的路径,windows下面考虑安装Slik-Subversion,然后找到svn.exe的路径。linux下面比如/usr/bin/svn
* 2. svn repos设置 可以是多个,需要设定某一个库的访问路径,以及用户名和密码。
* 3. zentao访问信息设置,需要设置zentao的访问路径以及拥有subversion模块的 接口:同步svn日志权限的用户和密码。
*
* 1. client: the svn client binary path. You can install Slik-Subversion unser windows, then find the path of svn.exe. under linux, try /usr/bin/svn
* 2. svn repos: Can set multi repos, ervery one should set the path, username and password.
* 3. zentao setting: must set the zentao url and the account with his password who can access subversion modules' api:sync svn log page.
*
* example:
* $config->svn->client = '/usr/bin/svn'; // c:\svn\svn.exe
* $config->svn->repos['pms']['path'] = 'http://svn.zentao.net/zentao/trunk/';
* $config->svn->repos['pms']['username'] = 'user';
* $config->svn->repos['pms']['password'] = 'pass';
*
* $config->zentao->path = "http://pms.zentao.net/";
* $config->zentao->user = 'demo';
* $config->zentao->password = '123456';
*
*/
/* System settings. */
$config->timezone = 'Asia/Shanghai'; // The time zone setting, for more see http://www.php.net/manual/en/timezones.php
$config->sleep = 0; // The seconds to sleep.
$config->svn = new stdclass();
/* Subversion settings. */
$config->svn->client = '';
$i = 1;
$config->svn->repos[$i]['path'] = '';
$config->svn->repos[$i]['username'] = '';
$config->svn->repos[$i]['password'] = '';
/*
$i ++;
$config->svn->repos[$i]['path'] = '';
$config->svn->repos[$i]['username'] = '';
$config->svn->repos[$i]['password'] = '';
*/
/* ZenTaoPMS settings. */
$config->zentao = new stdclass();
$config->zentao->path = '';
$config->zentao->user = '';
$config->zentao->password = '';
-299
View File
@@ -1,299 +0,0 @@
<?php
/**
* The syncer of svn.
*
* @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
* @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
* @author Chunsheng Wang <chunsheng@cnezsoft.com>
* @package svn
* @version $Id$
* @link https://www.zentao.net
*/
error_reporting(E_ALL ^ E_STRICT ^ E_WARNING);
include './config.php';
include './api.class.php';
$syncer = new syncer($config);
$syncer->run();
class syncer
{
/**
* The svn binary svnClient.
*
* @var string
* @access public
*/
public $svnClient;
/**
* The zentao client.
*
* @var string
* @access public
*/
public $zentaoClient;
/**
* Repos.
*
* @var array
* @access public
*/
public $repos = array();
/**
* The log root.
*
* @var string
* @access public
*/
public $logRoot = '';
/**
* The construct function.
*
* @access public
* @return void
*/
public function __construct($config)
{
$this->setConfig($config);
$this->setTimeZone();
$this->setRepos();
$this->setLogRoot();
$this->loginZentao();
}
/**
* Set config.
*
* @param object $config
* @access public
* @return void
*/
public function setConfig($config)
{
$this->config = $config;
}
/**
* Set timezone.
*
* @access public
* @return void
*/
public function setTimeZone()
{
date_default_timezone_set($this->config->timezone);
}
/**
* Set the repos.
*
* @access public
* @return void
*/
public function setRepos()
{
if(!$this->config->svn->repos) die("You must set one svn repo.\n");
$this->repos = $this->config->svn->repos;
}
/**
* Set the log root.
*
* @access public
* @return void
*/
public function setLogRoot()
{
$this->logRoot = './log/';
if(!is_dir($this->logRoot)) mkdir($this->logRoot);
}
/**
* Login to zentao.
*
* @access public
* @return void
*/
public function loginZentao()
{
if(!$this->config->zentao->path or !$this->config->zentao->user) die("You must set the zentao path and user.\n");
$zentaoConfig = $this->config->zentao;
$this->zentaoClient = new ztclient($zentaoConfig->path, $zentaoConfig->user, $zentaoConfig->password);
}
/**
* Run.
*
* @access public
* @return void
*/
public function run()
{
while(true)
{
foreach($this->repos as $name => $repo)
{
$this->printLog("begin repo $name");
$repo = (object)$repo;
$repo->name = $name;
$this->setRepo($repo);
$savedRevision = $this->getSavedRevision();
$this->printLog("start from revision $savedRevision");
$logs = $this->getRepoLogs($repo, $savedRevision);
$revisions = $this->getRevisionsFromLogs($logs);
if(!$revisions)
{
$this->printLog("no logs");
continue;
}
$this->printLog('fetched ' . count($revisions) . ' logs');
$this->printLog('begin posting logs');
$objects = $this->zentaoClient->post('svn', 'apiSync', array('logs' => $logs, 'repoRoot' => $this->repoRoot));
$objects = $objects->parsedObjects;
$this->printLog('parsed objects:');
echo 'story: ' . join(',', (array)$objects->stories) . "\n";
echo 'task: ' . join(',', (array)$objects->tasks) . "\n";
echo 'bugs: ' . join(',', (array)$objects->bugs) . "\n";
$this->saveLastRevision(max($revisions));
echo "----------------------\n";
}
$this->printLog("sleeping {$this->config->sleep} seconds");
sleep($this->config->sleep);
}
}
/**
* Set repo.
*
* @param object $repo
* @access public
* @return void
*/
public function setRepo($repo)
{
$this->setClient($repo);
$this->setLogFile($repo->name);
$this->setRepoRoot($repo);
}
/**
* Set the svn binary svnClient of a repo.
*
* @param object $repo
* @access public
* @return void
*/
public function setClient($repo)
{
if($this->config->svn->client == '') die("You must set the svn svnClient file.\n");
$this->svnClient = $this->config->svn->client . " --non-interactive";
if(isset($repo->username)) $this->svnClient .= " --username $repo->username --password $repo->password --no-auth-cache";
}
/**
* Set the log file of a repo.
*
* @param string $repoName
* @access public
* @return void
*/
public function setLogFile($repoName)
{
$this->logFile = $this->logRoot . $repoName;
}
/**
* set the root path of a repo.
*
* @param object $repo
* @access public
* @return void
*/
public function setRepoRoot($repo)
{
$cmd = $this->svnClient . " info --xml $repo->path";
$info = `$cmd`;
$info = simplexml_load_string($info);
$repoRoot = (string)$info->entry->repository->root;
$this->repoRoot = $repoRoot;
}
/**
* Get repo logs.
*
* @param object $repo
* @param int $fromRevision
* @access public
* @return string
*/
public function getRepoLogs($repo, $fromRevision)
{
$parsedLogs = array();
/* The svn log command. */
$cmd = $this->svnClient . " log -r $fromRevision:HEAD -v --xml $repo->path";
$logs = `$cmd`;
return $logs;
}
/**
* Get the saved revision.
*
* @access public
* @return int
*/
public function getSavedRevision()
{
if(!file_exists($this->logFile)) return 0;
return (int)trim(file_get_contents($this->logFile));
}
/**
* Get revisons from logs.
*
* @param string $logs
* @access public
* @return array|bool
*/
public function getRevisionsFromLogs($logs)
{
if(!preg_match_all('|revision="(.*)"|', $logs, $results)) return false;
$revisions = $results[1];
return $revisions;
}
/**
* Save the last revision.
*
* @param int $revision
* @access public
* @return void
*/
public function saveLastRevision($revision)
{
file_put_contents($this->logFile, $revision);
}
/**
* Print log.
*
* @param string $log
* @access public
* @return void
*/
public function printLog($log)
{
echo date('Y-m-d H:i:s') . " $log\n";
}
}