diff --git a/codepot/src/codepot/models/Makefile.am b/codepot/src/codepot/models/Makefile.am index 78b97d06..c7329989 100644 --- a/codepot/src/codepot/models/Makefile.am +++ b/codepot/src/codepot/models/Makefile.am @@ -1,6 +1,7 @@ wwwdir=$(WWWDIR)/codepot/models www_DATA = \ codemodel.php \ + coderepomodel.php \ dbloginmodel.php \ filemodel.php \ gitmodel.php \ diff --git a/codepot/src/codepot/models/Makefile.in b/codepot/src/codepot/models/Makefile.in index 54e18050..dcce62c4 100644 --- a/codepot/src/codepot/models/Makefile.in +++ b/codepot/src/codepot/models/Makefile.in @@ -146,6 +146,7 @@ target_alias = @target_alias@ wwwdir = $(WWWDIR)/codepot/models www_DATA = \ codemodel.php \ + coderepomodel.php \ dbloginmodel.php \ filemodel.php \ gitmodel.php \ diff --git a/codepot/src/codepot/models/gitmodel.php b/codepot/src/codepot/models/gitmodel.php index e74ab389..ff41c266 100644 --- a/codepot/src/codepot/models/gitmodel.php +++ b/codepot/src/codepot/models/gitmodel.php @@ -1,22 +1,13 @@ load->model('CodeRepoModel'); + +class GitModel extends CodeRepoModel { - protected $errmsg = ''; - - function capture_error ($errno, $errmsg) - { - $this->errmsg = $errmsg; - } - - function getErrorMessage () - { - return $this->errmsg; - } - function GitModel () { - parent::Model (); + parent::CodeRepoModel (); } private function _canonical_path($path) diff --git a/codepot/src/codepot/models/projectmodel.php b/codepot/src/codepot/models/projectmodel.php index 79cc5aff..14ed2a5c 100644 --- a/codepot/src/codepot/models/projectmodel.php +++ b/codepot/src/codepot/models/projectmodel.php @@ -1,5 +1,8 @@ load->model('SubversionModel'); + class ProjectModel extends Model { function ProjectModel () @@ -194,57 +197,13 @@ class ProjectModel extends Model $cfgdir = CODEPOT_CFG_DIR; $repodir = CODEPOT_SVNREPO_DIR; - // create repository - if (@svn_repos_create ("{$repodir}/{$project->id}") === FALSE) + if (SubversionModel::createRepo($project->id, $repodir, $cfgdir, $api) === FALSE) { $this->db->trans_rollback (); $repo_error = TRUE; 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 (); return TRUE; } @@ -372,7 +331,7 @@ class ProjectModel extends Model else { $repodir = CODEPOT_SVNREPO_DIR; - if ($this->deleteDirectory ("{$repodir}/{$project->id}") === FALSE) + if (SubversionModel::deleteRepo($project->id, $repodir) === FALSE) { $this->db->trans_rollback (); return FALSE; @@ -446,42 +405,6 @@ class ProjectModel extends Model 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) { $this->db->trans_start (); diff --git a/codepot/src/codepot/models/subversionmodel.php b/codepot/src/codepot/models/subversionmodel.php index 235ae6f9..3ed4d975 100644 --- a/codepot/src/codepot/models/subversionmodel.php +++ b/codepot/src/codepot/models/subversionmodel.php @@ -1,22 +1,13 @@ load->model('CodeRepoModel'); + +class SubversionModel extends CodeRepoModel { - protected $errmsg = ''; - - function capture_error ($errno, $errmsg) - { - $this->errmsg = $errmsg; - } - - function getErrorMessage () - { - return $this->errmsg; - } - function SubversionModel () { - parent::Model (); + parent::CodeRepoModel (); } private function _canonical_path($path) @@ -343,7 +334,7 @@ class SubversionModel extends Model function storeFile ($projectid, $path, $committer, $commit_message, $text) { - $this->errmsg = ''; + $this->clearErrorMessage (); //$url = 'file://'.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) { - $this->errmsg = ''; + $this->clearErrorMessage (); //$url = 'file://'.CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}"; $full_path = CODEPOT_SVNREPO_DIR."/{$projectid}"; @@ -528,7 +519,7 @@ class SubversionModel extends Model function deleteFiles ($projectid, $path, $committer, $commit_message, $files) { - $this->errmsg = ''; + $this->clearErrorMessage (); //$url = 'file://'.CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}"; $full_path = CODEPOT_SVNREPO_DIR."/{$projectid}"; @@ -587,7 +578,7 @@ class SubversionModel extends Model function renameFiles ($projectid, $path, $committer, $commit_message, $files) { - $this->errmsg = ''; + $this->clearErrorMessage (); //$url = 'file://'.CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}"; $full_path = CODEPOT_SVNREPO_DIR."/{$projectid}"; @@ -1316,7 +1307,7 @@ class SubversionModel extends Model function getRevProp ($projectid, $rev, $prop) { - $this->errmsg = ''; + $this->clearErrorMessage (); $url = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}"); set_error_handler (array ($this, 'capture_error')); @@ -1327,7 +1318,7 @@ class SubversionModel extends Model function setRevProp ($projectid, $rev, $prop, $propval, $user) { - $this->errmsg = ''; + $this->clearErrorMessage (); $url = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}"); set_error_handler (array ($this, 'capture_error')); @@ -1344,7 +1335,7 @@ class SubversionModel extends Model function killRevProp ($projectid, $rev, $prop, $user) { - $this->errmsg = ''; + $this->clearErrorMessage (); $url = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}"); set_error_handler (array ($this, 'capture_error')); @@ -1362,7 +1353,7 @@ class SubversionModel extends Model function mapRevPropToRev ($projectid, $revprop_name) { - $this->errmsg = ''; + $this->clearErrorMessage (); $url = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}"); set_error_handler (array ($this, 'capture_error')); @@ -1388,7 +1379,7 @@ class SubversionModel extends Model function findRevWithRevProp ($projectid, $revprop_name, $revprop_value) { - $this->errmsg = ''; + $this->clearErrorMessage (); $url = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}"); set_error_handler (array ($this, 'capture_error')); @@ -1414,7 +1405,7 @@ class SubversionModel extends Model function listProps ($projectid, $path, $rev) { - $this->errmsg = ''; + $this->clearErrorMessage (); $orgurl = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}"); $workurl = ($path == '')? $orgurl: "{$orgurl}@"; // trailing @ for collision prevention @@ -1442,7 +1433,7 @@ class SubversionModel extends Model function getProp ($projectid, $path, $rev, $prop) { - $this->errmsg = ''; + $this->clearErrorMessage (); $orgurl = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}"); $workurl = ($path == '')? $orgurl: "{$orgurl}@"; // trailing @ for collision prevention @@ -2210,6 +2201,54 @@ class SubversionModel extends Model 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}"); + } } ?>