Jump to content

Do anybody know how to write PHP script for connecting Perforce?


reksss

Recommended Posts

 

 

Hello Friends,

 

Im trying to connect Perforce from Linux. I want to get(sync) file from perforce, then need to edit and submit it back to perforce....

 

Do you guys have any sample codings to do so??

 

Waiting for ur reply,

 

Thanks

Rekha

Link to comment
Share on other sites

Hello....

If i run this program i got the below error msg.

 

Run -> edit successfully

[P4.run()] Errors during command execution( "p4 submit -r" )

 

        [Error]: No files to submit from the default changelist.

 

 

Error: No files to submit from the default changelist.

 

 

<?php

$p4 = new P4();
$input_file = "//Consumer/WSE/Dev/SSO-1.0/SSO/QA/edit.txt";

//***********  Connect to Perforce  *************************************
$p4->port = "tw-p4proxy.tw.trendnet.org:1667";
$p4->user = "***";
$p4->client = "WSE_QA_tw-rekha";
$template = "WSE_QA_tw-rekha";
$client_root = "C:/Users/rekha_sokiyan/WSE_QA_tw-rekha";
$client_name = "WSE_QA_tw-rekha";
$p4->connect();
$p4->run_login('******' );


try {

          //***************  SYNC  ********************************************
          $p4->exception_level = 1;
                // Convert client spec into an array
                $client = $p4->fetch_client("-t", $template);
                $client['Root'] = $client_root;
                //print_r($client);
                $p4->save_client($client);
                // File(s) up-to-date is a warning; no exception raised
                if($p4->run_sync($input_file))
                   echo "\nRun -> sync successfully\n";

                //****************  EDIT  ********************************************
                if($p4->run("edit",$input_file))
                   echo "\nRun -> edit successfully\n";
                $p4->client;


                //***************  SUBMIT  *******************************************
                $change = $p4->fetch_change();
                // Files were opened elsewhere and we want to submit a subset that we already know about.
                $myfiles = array(
                                        '//Consumer/WSE/Dev/SSO-1.0/SSO/QA/edit.txt',
                                        '//Consumer/WSE/Dev/SSO-1.0/SSO/QA/test.txt'
                );


                $change['Files'] = $myfiles;
                $p4->input = $change;
                $p4->change = $change;
                $change['Description'] = "My changelist\nSubmitted from P4PHP\n";
                //print_r($change);
                $p4->run_submit("-r",$change);

                $spec = $p4->fetch_change();
                $spec["Description"] = "My changelist\nSubmitted from P4PHP\n";
                //$p4->run_submit($spec);

                //print_r($spec);

                //if($p4->run_submit("-i",$change))
                //   echo "\nRun -> Submitted from P4PHP\n";


//****************  EDIT  ********************************************
                if($p4->run("edit",$input_file))
                   echo "\nRun -> edit successfully\n";
                $p4->client;


                //***************  SUBMIT  *******************************************
                $change = $p4->fetch_change();
                // Files were opened elsewhere and we want to submit a subset that we already know about.
                $myfiles = array(
                                        '//Consumer/WSE/Dev/SSO-1.0/SSO/QA/edit.txt',
                                        '//Consumer/WSE/Dev/SSO-1.0/SSO/QA/test.txt'
                );


                $change['Files'] = $myfiles;
                $p4->input = $change;
                $p4->change = $change;
                $change['Description'] = "My changelist\nSubmitted from P4PHP\n";
                //print_r($change);
                $p4->run_submit("-r",$change);


}catch (P4_Exception $e) {
         print $e->getMessage() . "\n";
         foreach ($p4->errors as $error) {
         print "Error: $error\n";
        }
}
?>                                                                              
[code]

Do anybody help me to fix it?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.