sync repo by using a page button

This commit is contained in:
aaronchen2k
2020-01-13 11:09:37 +08:00
parent b6c7f38e1a
commit 91e680de2f
5 changed files with 42 additions and 10 deletions
+25 -4
View File
@@ -403,9 +403,9 @@ class ci extends control
$repo = $this->ci->getRepoByID($repoID);
if($_POST)
{
$needSync = $this->ci->updateRepo($repoID);
$noNeedSync = $this->ci->updateRepo($repoID);
if(dao::isError()) die(js::error(dao::getError()));
if(!$needSync)
if(!$noNeedSync)
{
$link = $this->ci->createLink('showSyncComment', "repoID=$repoID");
$this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $link));
@@ -463,6 +463,21 @@ class ci extends control
$this->display();
}
/**
* sync repo from remote.
*
* @param int $repoID
* @access public
* @return void
*/
public function syncRepo($repoID = 0)
{
$this->dao->update(TABLE_REPO)->set('synced')->eq(0)->where('id')->eq($repoID)->exec();
$link = $this->ci->createLink('showSyncComment', "repoID=$repoID&needPull=true");
$this->send(array('result' => 'success', 'locate' => $link));
}
/**
* watch branch.
*
@@ -486,7 +501,7 @@ class ci extends control
* @access public
* @return void
*/
public function showSyncComment($repoID = 0)
public function showSyncComment($repoID = 0, $needPull = false)
{
if($repoID == 0) $repoID = $this->session->repoID;
@@ -496,6 +511,7 @@ class ci extends control
$latestInDB = $this->ci->getLatestComment($repoID, );
$this->view->version = $latestInDB ? (int)$latestInDB->commit : 1;
$this->view->repoID = $repoID;
$this->view->needPull = $needPull;
$this->display();
}
@@ -507,10 +523,15 @@ class ci extends control
* @access public
* @return void
*/
public function ajaxSyncComment($repoID = 0, $type = 'batch')
public function ajaxSyncComment($repoID = 0, $type = 'batch', $needPull = false)
{
set_time_limit(0);
$repo = $this->ci->getRepoByID($repoID);
if ($needPull) {
$this->loadModel('git')->pull($repo);
}
if(empty($repo)) die();
if($repo->synced) die('finish');
+1
View File
@@ -96,6 +96,7 @@ $lang->repo->create = '添加代码库';
$lang->repo->edit = '编辑代码库';
$lang->repo->delete = '删除代码库';
$lang->repo->confirmDelete = '确认删除该代码库吗?';
$lang->repo->browseBranch = '查看分支';
$lang->repo->id = 'ID';
$lang->repo->name = '名称';
+2
View File
@@ -40,6 +40,8 @@
<td class='c-actions text-right'>
<?php
common::printIcon('ci', 'browseBranch', "repoID=$id", '', 'list', 'file-text');
common::printIcon('ci', 'syncRepo', "repoID=$id", '', 'list', 'refresh');
echo '&nbsp;';
common::printIcon('ci', 'editRepo', "repoID=$id", '', 'list', 'edit');
if (common::hasPriv('ci', 'deleteRepo')) {
$deleteURL = $this->createLink('ci', 'deleteRepo', "repoID=$id&confirm=yes");
+5 -1
View File
@@ -25,11 +25,15 @@
</div>
<script language='Javascript'>
$(function(){
var link = createLink('ci', 'ajaxSyncComment', "repoID=<?php echo $repoID?>");
var link = createLink('ci', 'ajaxSyncComment', "repoID=<?php echo $repoID?>&type=batch&needPull=<?php echo $needPull?>");
alert(link);
function syncComments()
{
$.get(link, function(data)
{
console.log(data);
if(data == 'finish')
{
$('#caption').text('<?php echo $lang->repo->notice->syncComplete?>');
+9 -5
View File
@@ -140,18 +140,22 @@ class gitModel extends model
/**
* Pull codes from remote repo.
*
* @access public
* @return void
* @param $repoRoot
*/
public function pull()
public function pull($repo)
{
chdir($this->repoRoot);
if (!empty($repo)) {
$repoRoot = $repo->path;
$this->setClient($repo);
} else {
$repoRoot = $this->repoRoot;
}
chdir($repoRoot);
// exec('sudo -u aaron whoami', $output, $return);
$cmd = "{$this->client} pull 2>&1";
exec($cmd, $output, $return);
$this->printLog("{$cmd}, {$output}, {$return}");
}
/**