TechFanDan
TechFanDan

Reputation: 3478

Commiting files to SVN using PHP - one function, two pages and two different result

My problem is that I'm calling the same function using two different pages (located in different folders) and getting two different results. The goal is to submit content in a textarea, save it to a file and then commit this file.

Here is my file structure

\svntest\folio\00123\svn.php
\svntest\folio\00456\my_file.php
\svntest\test.php
\svntest\svncmd\commit.bat

The content of commit.bat

svn ci -m "hello" %1

The content of \svntest\folio\00123\svn.php:

if($_POST){

    if( strlen($_POST['show_revision']) ){

        $f = dirname(__FILE__);
        $f .= '\\..\\..\\'.$file;
        svn_save_file($_POST['show_revision'], $f);

        svn_commit_file();
    }

    //header('location: svn.php');
}


<form method="post">
<fieldset><legend>Page Content</legend>
<div>
<textarea cols="50" rows="10" id="txtarea" name="txtarea"></textarea>
</div>
<div><input type="submit" value="Save"/></div>
</form>

The content of \svntest\test.php:

svn_commit_file();

The function svn_commit_file():

function svn_commit_file(){
    $cmd = '"C:\\Documents and Settings\\me\\Desktop\\xampp\\htdocs\\xampp\\LearnPHP\\svntest\\svncmd\\commit.bat" "folio\\00456\\my_file.php"';
    $out = system($cmd, $r);
}

What doesn't work

file: \svntest\folio\00123\svn.php

result: no svn commit message, nothing gets output from the system() call...

What works

file: \svntest\test.php

result: svn commit message is obtained and version added to SVN

Since everything is hardcoded in svn_commit_file(), I fail to see where the problem lies.

Upvotes: 1

Views: 264

Answers (2)

bmk
bmk

Reputation: 14147

I think you should specify an absolute path for your file to be checked in. The current working directory differs between test.php and folio\00123\svn.php.

function svn_commit_file(){
    $cmd = '"C:\\Documents and Settings\\me\\Desktop\\xampp\\htdocs\\xampp\\LearnPHP\\svntest\\svncmd\\commit.bat" "C:\\Documents and Settings\\me\\Desktop\\xampp\\htdocs\\xampp\\LearnPHP\\svntest\\folio\\00456\\my_file.php"';
    $out = system($cmd, $r);
}

Upvotes: 2

Saiyam Patel
Saiyam Patel

Reputation: 1161

may be issue with path

pass the $_SERVER['DOCUMENT_ROOT'] in svn_commit_file() function

svn_commit_file($_SERVER['DOCUMENT_ROOT']);

based on this full physical path run svn commit command... probably work fine

thanks

Upvotes: 0

Related Questions