dongqiaozhe5070
dongqiaozhe5070
2012-08-15 18:34

PHP,Subversion和克隆然后提交目录结构

已采纳

I have an interesting problem that I am hoping somebody might be able to help me solve. I have a subversion repository which I use to store the source code for a very large PHP site. Here are some details about my setup that are important:

  • The dev version ot the site lives on the server at /var/www/sitename-dev, and was created by doing an svn checkout from the repository.
  • A live version of the site lives at /var/www/sitename, and was also created with svn checkout.
  • There is a post-commit hook set up on the repository that will run an svn update on the dev site after every commit, and an svn update on the live site if the commit log entry contains a special deployment keyword.
  • All of the above works wonderfully and has improved the productivity of my team considerably.

The purpose of the site is to provide a set of core functionality that many companies need, and let each company who purchases our product have their own specially branded site that provides our functionality. This is accomplished using the Smarty templating engine (which is excellent). Each branded site shares the same core files (therefore fixing a bug in a core file fixes it for every site), and has a directory structure for templates located in /resources/site. Each file in /resources/site is needed, but the contents will vary from site to site.

What I want to be able to do is create a form in the administrator section of the site that will create a new branded site as a clone of the /resources/site directory of an existing default site (in the local copy in /var/www), and add it to the subversion repository (add/commit). This will allow us to start redoing the template immediately after our next svn update.

Here is what I have so far:

public function addNewSiteHandle($handleName){
    try{
        $resourceRoot = "/var/www/site";
        echo "Resource Root = ".$resourceRoot."<br />";
        $resourceRoot .= "/resources";
        echo "Resource Root = ".$resourceRoot."<br />";
        $this->recursiveCopy($resourceRoot."/rtx", $resourceRoot."/".$handleName);
        $files = array();
        foreach(scandir($resourceRoot."/".$handleName) as $file){
            if($file != "." && $file != ".." && $file != ".svn"){
                echo "Processing \"$file\"<br />";
                svn_add($resourceRoot."/".$handleName."/".$file, true, true);
                array_push($files, $resourceRoot."/".$handleName."/".$file);
            }
        }
        svn_commit("Handle \"$handleName\" added through the Website.", $files);
    }
    catch(Exception $e){
        error_log($e->getMessage());
    }
}

This complains with the error:

[Wed Aug 15 14:31:01 2012] [error] [client 192.168.1.x] PHP Warning: svn_add(): svn error(s) occured 155007 (Path is not a working copy directory) '/var/www/site/resources/testtt43' is not a working copy in /var/www/site/Subversion.class.php on line 76, referer: http://b1.festivadev.com/cloneTest.html

I know the site is a working copy directory, so I'm not sure what the problem is. Any ideas?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • douvcpx6526 douvcpx6526 9年前

    Your script copies the entire site directory including .svn subdirectories. You should not copy these .svn directories or recursively delete them from copied directories after copying. After that SVN add & commit should work properly.

    点赞 评论 复制链接分享