restuructured SubversionMode and GitModel by introcucing a common parent class CodeRepoModel for the pending git support work
This commit is contained in:
parent
328ef3829c
commit
4ece845bdd
@ -1,6 +1,7 @@
|
|||||||
wwwdir=$(WWWDIR)/codepot/models
|
wwwdir=$(WWWDIR)/codepot/models
|
||||||
www_DATA = \
|
www_DATA = \
|
||||||
codemodel.php \
|
codemodel.php \
|
||||||
|
coderepomodel.php \
|
||||||
dbloginmodel.php \
|
dbloginmodel.php \
|
||||||
filemodel.php \
|
filemodel.php \
|
||||||
gitmodel.php \
|
gitmodel.php \
|
||||||
|
@ -146,6 +146,7 @@ target_alias = @target_alias@
|
|||||||
wwwdir = $(WWWDIR)/codepot/models
|
wwwdir = $(WWWDIR)/codepot/models
|
||||||
www_DATA = \
|
www_DATA = \
|
||||||
codemodel.php \
|
codemodel.php \
|
||||||
|
coderepomodel.php \
|
||||||
dbloginmodel.php \
|
dbloginmodel.php \
|
||||||
filemodel.php \
|
filemodel.php \
|
||||||
gitmodel.php \
|
gitmodel.php \
|
||||||
|
@ -1,22 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class GitModel extends Model
|
$CI = &get_instance();
|
||||||
|
$CI->load->model('CodeRepoModel');
|
||||||
|
|
||||||
|
class GitModel extends CodeRepoModel
|
||||||
{
|
{
|
||||||
protected $errmsg = '';
|
|
||||||
|
|
||||||
function capture_error ($errno, $errmsg)
|
|
||||||
{
|
|
||||||
$this->errmsg = $errmsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getErrorMessage ()
|
|
||||||
{
|
|
||||||
return $this->errmsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
function GitModel ()
|
function GitModel ()
|
||||||
{
|
{
|
||||||
parent::Model ();
|
parent::CodeRepoModel ();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _canonical_path($path)
|
private function _canonical_path($path)
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
$CI = &get_instance();
|
||||||
|
$CI->load->model('SubversionModel');
|
||||||
|
|
||||||
class ProjectModel extends Model
|
class ProjectModel extends Model
|
||||||
{
|
{
|
||||||
function ProjectModel ()
|
function ProjectModel ()
|
||||||
@ -194,57 +197,13 @@ class ProjectModel extends Model
|
|||||||
$cfgdir = CODEPOT_CFG_DIR;
|
$cfgdir = CODEPOT_CFG_DIR;
|
||||||
$repodir = CODEPOT_SVNREPO_DIR;
|
$repodir = CODEPOT_SVNREPO_DIR;
|
||||||
|
|
||||||
// create repository
|
if (SubversionModel::createRepo($project->id, $repodir, $cfgdir, $api) === FALSE)
|
||||||
if (@svn_repos_create ("{$repodir}/{$project->id}") === FALSE)
|
|
||||||
{
|
{
|
||||||
$this->db->trans_rollback ();
|
$this->db->trans_rollback ();
|
||||||
$repo_error = TRUE;
|
$repo_error = TRUE;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
$hooks = array (
|
|
||||||
"pre-commit",
|
|
||||||
"start-commit",
|
|
||||||
"post-commit",
|
|
||||||
"pre-revprop-change",
|
|
||||||
"post-revprop-change"
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($hooks as $hook)
|
|
||||||
{
|
|
||||||
// copy hook scripts to the top repository directory
|
|
||||||
// overwriting existing scripts are ok as they are
|
|
||||||
// just updated to the latest scripts anyway.
|
|
||||||
$contents = @file_get_contents("{$cfgdir}/${hook}");
|
|
||||||
if ($contents === FALSE)
|
|
||||||
{
|
|
||||||
$this->deleteDirectory ("{$repodir}/{$project->id}");
|
|
||||||
$this->db->trans_rollback ();
|
|
||||||
$repo_error = TRUE;
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (@file_put_contents (
|
|
||||||
"{$repodir}/${hook}",
|
|
||||||
str_replace('%API%', $api, $contents)) === FALSE)
|
|
||||||
{
|
|
||||||
$this->deleteDirectory ("{$repodir}/{$project->id}");
|
|
||||||
$this->db->trans_rollback ();
|
|
||||||
$repo_error = TRUE;
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// install the hook script to the new project repository
|
|
||||||
if (@chmod ("{$repodir}/{$hook}", 0755) === FALSE ||
|
|
||||||
@symlink ("../../{$hook}", "{$repodir}/{$project->id}/hooks/${hook}") === FALSE)
|
|
||||||
{
|
|
||||||
$this->deleteDirectory ("{$repodir}/{$project->id}");
|
|
||||||
$this->db->trans_rollback ();
|
|
||||||
$repo_error = TRUE;
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->db->trans_commit ();
|
$this->db->trans_commit ();
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -372,7 +331,7 @@ class ProjectModel extends Model
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$repodir = CODEPOT_SVNREPO_DIR;
|
$repodir = CODEPOT_SVNREPO_DIR;
|
||||||
if ($this->deleteDirectory ("{$repodir}/{$project->id}") === FALSE)
|
if (SubversionModel::deleteRepo($project->id, $repodir) === FALSE)
|
||||||
{
|
{
|
||||||
$this->db->trans_rollback ();
|
$this->db->trans_rollback ();
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -446,42 +405,6 @@ class ProjectModel extends Model
|
|||||||
return $query->result ();
|
return $query->result ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function _scandir ($dir)
|
|
||||||
{
|
|
||||||
$files = array ();
|
|
||||||
|
|
||||||
$dh = opendir($dir);
|
|
||||||
while (false !== ($filename = readdir($dh)))
|
|
||||||
{
|
|
||||||
$files[] = $filename;
|
|
||||||
}
|
|
||||||
closedir ($dh);
|
|
||||||
|
|
||||||
return $files;
|
|
||||||
}
|
|
||||||
|
|
||||||
function deleteDirectory($dir)
|
|
||||||
{
|
|
||||||
if (is_link($dir)) return @unlink($dir);
|
|
||||||
if (!file_exists($dir)) return TRUE;
|
|
||||||
if (!is_dir($dir)) return @unlink($dir);
|
|
||||||
|
|
||||||
foreach ($this->_scandir($dir) as $item)
|
|
||||||
{
|
|
||||||
if ($item == '.' || $item == '..') continue;
|
|
||||||
if ($this->deleteDirectory($dir . "/" . $item) === FALSE)
|
|
||||||
{
|
|
||||||
chmod($dir . "/" . $item, 0777);
|
|
||||||
if ($this->deleteDirectory($dir . "/" . $item) === FALSE)
|
|
||||||
return FALSE;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return rmdir($dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
function projectHasMember ($projectid, $userid)
|
function projectHasMember ($projectid, $userid)
|
||||||
{
|
{
|
||||||
$this->db->trans_start ();
|
$this->db->trans_start ();
|
||||||
|
@ -1,22 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class SubversionModel extends Model
|
$CI = &get_instance();
|
||||||
|
$CI->load->model('CodeRepoModel');
|
||||||
|
|
||||||
|
class SubversionModel extends CodeRepoModel
|
||||||
{
|
{
|
||||||
protected $errmsg = '';
|
|
||||||
|
|
||||||
function capture_error ($errno, $errmsg)
|
|
||||||
{
|
|
||||||
$this->errmsg = $errmsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getErrorMessage ()
|
|
||||||
{
|
|
||||||
return $this->errmsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
function SubversionModel ()
|
function SubversionModel ()
|
||||||
{
|
{
|
||||||
parent::Model ();
|
parent::CodeRepoModel ();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _canonical_path($path)
|
private function _canonical_path($path)
|
||||||
@ -343,7 +334,7 @@ class SubversionModel extends Model
|
|||||||
|
|
||||||
function storeFile ($projectid, $path, $committer, $commit_message, $text)
|
function storeFile ($projectid, $path, $committer, $commit_message, $text)
|
||||||
{
|
{
|
||||||
$this->errmsg = '';
|
$this->clearErrorMessage ();
|
||||||
|
|
||||||
//$url = 'file://'.CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}";
|
//$url = 'file://'.CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}";
|
||||||
$canon_path = $this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}");
|
$canon_path = $this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}");
|
||||||
@ -382,7 +373,7 @@ class SubversionModel extends Model
|
|||||||
|
|
||||||
function importFiles ($projectid, $path, $committer, $commit_message, $files, $uploader)
|
function importFiles ($projectid, $path, $committer, $commit_message, $files, $uploader)
|
||||||
{
|
{
|
||||||
$this->errmsg = '';
|
$this->clearErrorMessage ();
|
||||||
|
|
||||||
//$url = 'file://'.CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}";
|
//$url = 'file://'.CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}";
|
||||||
$full_path = CODEPOT_SVNREPO_DIR."/{$projectid}";
|
$full_path = CODEPOT_SVNREPO_DIR."/{$projectid}";
|
||||||
@ -528,7 +519,7 @@ class SubversionModel extends Model
|
|||||||
|
|
||||||
function deleteFiles ($projectid, $path, $committer, $commit_message, $files)
|
function deleteFiles ($projectid, $path, $committer, $commit_message, $files)
|
||||||
{
|
{
|
||||||
$this->errmsg = '';
|
$this->clearErrorMessage ();
|
||||||
|
|
||||||
//$url = 'file://'.CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}";
|
//$url = 'file://'.CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}";
|
||||||
$full_path = CODEPOT_SVNREPO_DIR."/{$projectid}";
|
$full_path = CODEPOT_SVNREPO_DIR."/{$projectid}";
|
||||||
@ -587,7 +578,7 @@ class SubversionModel extends Model
|
|||||||
|
|
||||||
function renameFiles ($projectid, $path, $committer, $commit_message, $files)
|
function renameFiles ($projectid, $path, $committer, $commit_message, $files)
|
||||||
{
|
{
|
||||||
$this->errmsg = '';
|
$this->clearErrorMessage ();
|
||||||
|
|
||||||
//$url = 'file://'.CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}";
|
//$url = 'file://'.CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}";
|
||||||
$full_path = CODEPOT_SVNREPO_DIR."/{$projectid}";
|
$full_path = CODEPOT_SVNREPO_DIR."/{$projectid}";
|
||||||
@ -1316,7 +1307,7 @@ class SubversionModel extends Model
|
|||||||
|
|
||||||
function getRevProp ($projectid, $rev, $prop)
|
function getRevProp ($projectid, $rev, $prop)
|
||||||
{
|
{
|
||||||
$this->errmsg = '';
|
$this->clearErrorMessage ();
|
||||||
$url = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}");
|
$url = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}");
|
||||||
|
|
||||||
set_error_handler (array ($this, 'capture_error'));
|
set_error_handler (array ($this, 'capture_error'));
|
||||||
@ -1327,7 +1318,7 @@ class SubversionModel extends Model
|
|||||||
|
|
||||||
function setRevProp ($projectid, $rev, $prop, $propval, $user)
|
function setRevProp ($projectid, $rev, $prop, $propval, $user)
|
||||||
{
|
{
|
||||||
$this->errmsg = '';
|
$this->clearErrorMessage ();
|
||||||
$url = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}");
|
$url = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}");
|
||||||
|
|
||||||
set_error_handler (array ($this, 'capture_error'));
|
set_error_handler (array ($this, 'capture_error'));
|
||||||
@ -1344,7 +1335,7 @@ class SubversionModel extends Model
|
|||||||
|
|
||||||
function killRevProp ($projectid, $rev, $prop, $user)
|
function killRevProp ($projectid, $rev, $prop, $user)
|
||||||
{
|
{
|
||||||
$this->errmsg = '';
|
$this->clearErrorMessage ();
|
||||||
$url = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}");
|
$url = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}");
|
||||||
|
|
||||||
set_error_handler (array ($this, 'capture_error'));
|
set_error_handler (array ($this, 'capture_error'));
|
||||||
@ -1362,7 +1353,7 @@ class SubversionModel extends Model
|
|||||||
|
|
||||||
function mapRevPropToRev ($projectid, $revprop_name)
|
function mapRevPropToRev ($projectid, $revprop_name)
|
||||||
{
|
{
|
||||||
$this->errmsg = '';
|
$this->clearErrorMessage ();
|
||||||
$url = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}");
|
$url = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}");
|
||||||
|
|
||||||
set_error_handler (array ($this, 'capture_error'));
|
set_error_handler (array ($this, 'capture_error'));
|
||||||
@ -1388,7 +1379,7 @@ class SubversionModel extends Model
|
|||||||
|
|
||||||
function findRevWithRevProp ($projectid, $revprop_name, $revprop_value)
|
function findRevWithRevProp ($projectid, $revprop_name, $revprop_value)
|
||||||
{
|
{
|
||||||
$this->errmsg = '';
|
$this->clearErrorMessage ();
|
||||||
$url = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}");
|
$url = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}");
|
||||||
|
|
||||||
set_error_handler (array ($this, 'capture_error'));
|
set_error_handler (array ($this, 'capture_error'));
|
||||||
@ -1414,7 +1405,7 @@ class SubversionModel extends Model
|
|||||||
|
|
||||||
function listProps ($projectid, $path, $rev)
|
function listProps ($projectid, $path, $rev)
|
||||||
{
|
{
|
||||||
$this->errmsg = '';
|
$this->clearErrorMessage ();
|
||||||
$orgurl = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}");
|
$orgurl = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}");
|
||||||
|
|
||||||
$workurl = ($path == '')? $orgurl: "{$orgurl}@"; // trailing @ for collision prevention
|
$workurl = ($path == '')? $orgurl: "{$orgurl}@"; // trailing @ for collision prevention
|
||||||
@ -1442,7 +1433,7 @@ class SubversionModel extends Model
|
|||||||
|
|
||||||
function getProp ($projectid, $path, $rev, $prop)
|
function getProp ($projectid, $path, $rev, $prop)
|
||||||
{
|
{
|
||||||
$this->errmsg = '';
|
$this->clearErrorMessage ();
|
||||||
$orgurl = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}");
|
$orgurl = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}");
|
||||||
|
|
||||||
$workurl = ($path == '')? $orgurl: "{$orgurl}@"; // trailing @ for collision prevention
|
$workurl = ($path == '')? $orgurl: "{$orgurl}@"; // trailing @ for collision prevention
|
||||||
@ -2210,6 +2201,54 @@ class SubversionModel extends Model
|
|||||||
|
|
||||||
return $tfname;
|
return $tfname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function createRepo ($projectid, $repodir, $cfgdir, $api)
|
||||||
|
{
|
||||||
|
$projdir = "{$repodir}/{$projectid}";
|
||||||
|
if (@svn_repos_create($projdir) === FALSE) return FALSE;
|
||||||
|
|
||||||
|
$hooks = array (
|
||||||
|
"pre-commit",
|
||||||
|
"start-commit",
|
||||||
|
"post-commit",
|
||||||
|
"pre-revprop-change",
|
||||||
|
"post-revprop-change"
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($hooks as $hook)
|
||||||
|
{
|
||||||
|
// copy hook scripts to the top repository directory
|
||||||
|
// overwriting existing scripts are ok as they are
|
||||||
|
// just updated to the latest scripts anyway.
|
||||||
|
$contents = @file_get_contents("{$cfgdir}/${hook}");
|
||||||
|
if ($contents === FALSE)
|
||||||
|
{
|
||||||
|
$this->deleteDirectory ($projdir);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (@file_put_contents("{$repodir}/${hook}", str_replace('%API%', $api, $contents)) === FALSE)
|
||||||
|
{
|
||||||
|
$this->deleteDirectory ($projdir);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// install the hook script to the new project repository
|
||||||
|
if (@chmod("{$repodir}/{$hook}", 0755) === FALSE ||
|
||||||
|
@symlink("../../{$hook}", "{$repodir}/{$projectid}/hooks/${hook}") === FALSE)
|
||||||
|
{
|
||||||
|
$this->deleteDirectory ($projdir);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static function deleteRepo ($projectid, $repodir)
|
||||||
|
{
|
||||||
|
return $this->deleteDirectory("{$repodir}/{$projectid}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Loading…
Reference in New Issue
Block a user