|
|
@ -25,21 +25,27 @@ class Perforce {
|
|
|
|
protected $p4branch;
|
|
|
|
protected $p4branch;
|
|
|
|
protected $process;
|
|
|
|
protected $process;
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct($depot, $branch, $port, $path, ProcessExecutor $process = null, $p4user = null, $p4password = null) {
|
|
|
|
public function __construct($repoConfig, $port, $path, ProcessExecutor $process = NULL) {
|
|
|
|
$this->p4depot = $depot;
|
|
|
|
|
|
|
|
$this->p4branch = $branch;
|
|
|
|
|
|
|
|
$this->p4port = $port;
|
|
|
|
$this->p4port = $port;
|
|
|
|
$this->path = $path;
|
|
|
|
$this->path = $path;
|
|
|
|
$this->process = $process ? : new ProcessExecutor;
|
|
|
|
$this->process = $process ? : new ProcessExecutor;
|
|
|
|
$fs = new Filesystem();
|
|
|
|
$fs = new Filesystem();
|
|
|
|
$fs->ensureDirectoryExists($path);
|
|
|
|
$fs->ensureDirectoryExists($path);
|
|
|
|
if (isset($p4user)){
|
|
|
|
|
|
|
|
$this->p4user = $p4user;
|
|
|
|
if (isset($repoConfig['depot'])) {
|
|
|
|
} else {
|
|
|
|
$this->p4depot = $repoConfig['depot'];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($repoConfig['branch'])) {
|
|
|
|
|
|
|
|
$this->p4branch = $repoConfig['branch'];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($repoConfig['p4user'])) {
|
|
|
|
|
|
|
|
$this->p4user = $repoConfig['p4user'];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
$this->p4user = $this->getP4variable("P4USER");
|
|
|
|
$this->p4user = $this->getP4variable("P4USER");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isset($p4password)){
|
|
|
|
if (isset($repoConfig['p4password'])) {
|
|
|
|
$this->p4password = $p4password;
|
|
|
|
$this->p4password = $repoConfig['p4password'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -47,6 +53,10 @@ class Perforce {
|
|
|
|
return mt_rand(1000, 9999);
|
|
|
|
return mt_rand(1000, 9999);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function isWindows(){
|
|
|
|
|
|
|
|
return defined('PHP_WINDOWS_VERSION_BUILD');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function executeCommand($command) {
|
|
|
|
protected function executeCommand($command) {
|
|
|
|
$result = "";
|
|
|
|
$result = "";
|
|
|
|
$this->process->execute($command, $result);
|
|
|
|
$this->process->execute($command, $result);
|
|
|
@ -72,6 +82,10 @@ class Perforce {
|
|
|
|
return $this->p4port;
|
|
|
|
return $this->p4port;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function isStream() {
|
|
|
|
|
|
|
|
return (strcmp($this->p4depotType, "stream") === 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function getStream() {
|
|
|
|
protected function getStream() {
|
|
|
|
if (!isset($this->p4stream)) {
|
|
|
|
if (!isset($this->p4stream)) {
|
|
|
|
if ($this->isStream()) {
|
|
|
|
if ($this->isStream()) {
|
|
|
@ -107,19 +121,25 @@ class Perforce {
|
|
|
|
|
|
|
|
|
|
|
|
public function queryP4User(IOInterface $io) {
|
|
|
|
public function queryP4User(IOInterface $io) {
|
|
|
|
$this->getUser();
|
|
|
|
$this->getUser();
|
|
|
|
if (strlen($this->p4user) <= 0) {
|
|
|
|
if (strlen($this->p4user) > 0) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->p4user = $this->getP4variable("P4USER");
|
|
|
|
|
|
|
|
if (strlen($this->p4user) > 0) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
$this->p4user = $io->ask("Enter P4 User:");
|
|
|
|
$this->p4user = $io->ask("Enter P4 User:");
|
|
|
|
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
|
|
|
|
if ($this->isWindows()) {
|
|
|
|
$command = "p4 set P4USER=$this->p4user";
|
|
|
|
$command = "p4 set P4USER=$this->p4user";
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
$command = "export P4USER=$this->p4user";
|
|
|
|
$command = "export P4USER=$this->p4user";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$result = $this->executeCommand($command);
|
|
|
|
$result = $this->executeCommand($command);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function getP4variable($name) {
|
|
|
|
protected function getP4variable($name) {
|
|
|
|
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
|
|
|
|
if ($this->isWindows()) {
|
|
|
|
$command = "p4 set";
|
|
|
|
$command = "p4 set";
|
|
|
|
$result = $this->executeCommand($command);
|
|
|
|
$result = $this->executeCommand($command);
|
|
|
|
$resArray = explode("\n", $result);
|
|
|
|
$resArray = explode("\n", $result);
|
|
|
@ -127,21 +147,24 @@ class Perforce {
|
|
|
|
$fields = explode("=", $line);
|
|
|
|
$fields = explode("=", $line);
|
|
|
|
if (strcmp($name, $fields[0]) == 0) {
|
|
|
|
if (strcmp($name, $fields[0]) == 0) {
|
|
|
|
$index = strpos($fields[1], " ");
|
|
|
|
$index = strpos($fields[1], " ");
|
|
|
|
if ($index === false){
|
|
|
|
if ($index === FALSE) {
|
|
|
|
$value = $fields[1];
|
|
|
|
$value = $fields[1];
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
$value = substr($fields[1], 0, $index);
|
|
|
|
$value = substr($fields[1], 0, $index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$value = trim($value);
|
|
|
|
$value = trim($value);
|
|
|
|
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
$command = 'echo $' . $name;
|
|
|
|
$command = 'echo $' . $name;
|
|
|
|
$result = trim($this->executeCommand($command));
|
|
|
|
$result = trim($this->executeCommand($command));
|
|
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function queryP4Password(IOInterface $io) {
|
|
|
|
protected function queryP4Password(IOInterface $io) {
|
|
|
@ -153,11 +176,8 @@ class Perforce {
|
|
|
|
$password = $io->askAndHideAnswer("Enter password for Perforce user " . $this->getUser() . ": ");
|
|
|
|
$password = $io->askAndHideAnswer("Enter password for Perforce user " . $this->getUser() . ": ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->p4password = $password;
|
|
|
|
$this->p4password = $password;
|
|
|
|
return $password;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function isStream() {
|
|
|
|
return $password;
|
|
|
|
return (strcmp($this->p4depotType, "stream") === 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function generateP4Command($command, $useClient = TRUE) {
|
|
|
|
protected function generateP4Command($command, $useClient = TRUE) {
|
|
|
@ -179,6 +199,7 @@ class Perforce {
|
|
|
|
if ($index === FALSE) {
|
|
|
|
if ($index === FALSE) {
|
|
|
|
return FALSE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -250,9 +271,10 @@ class Perforce {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$line = fgets($pipe);
|
|
|
|
$line = fgets($pipe);
|
|
|
|
while ($line != false){
|
|
|
|
while ($line != FALSE) {
|
|
|
|
$line = fgets($pipe);
|
|
|
|
$line = fgets($pipe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -265,7 +287,7 @@ class Perforce {
|
|
|
|
$command = $this->generateP4Command(" login -a");
|
|
|
|
$command = $this->generateP4Command(" login -a");
|
|
|
|
$process = proc_open($command, $descriptorspec, $pipes);
|
|
|
|
$process = proc_open($command, $descriptorspec, $pipes);
|
|
|
|
if (!is_resource($process)) {
|
|
|
|
if (!is_resource($process)) {
|
|
|
|
return false;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fwrite($pipes[0], $password);
|
|
|
|
fwrite($pipes[0], $password);
|
|
|
|
fclose($pipes[0]);
|
|
|
|
fclose($pipes[0]);
|
|
|
@ -286,10 +308,11 @@ class Perforce {
|
|
|
|
$this->queryP4User($io);
|
|
|
|
$this->queryP4User($io);
|
|
|
|
if (!$this->isLoggedIn()) {
|
|
|
|
if (!$this->isLoggedIn()) {
|
|
|
|
$password = $this->queryP4Password($io);
|
|
|
|
$password = $this->queryP4Password($io);
|
|
|
|
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
|
|
|
|
if ($this->isWindows()) {
|
|
|
|
$this->windowsLogin($password);
|
|
|
|
$this->windowsLogin($password);
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
$command = "echo $password | ".$this->generateP4Command(" login -a", false);
|
|
|
|
else {
|
|
|
|
|
|
|
|
$command = "echo $password | " . $this->generateP4Command(" login -a", FALSE);
|
|
|
|
$this->executeCommand($command);
|
|
|
|
$this->executeCommand($command);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -392,6 +415,7 @@ class Perforce {
|
|
|
|
$tags[$fields[1]] = $this->getStream() . "@" . $fields[1];
|
|
|
|
$tags[$fields[1]] = $this->getStream() . "@" . $fields[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $tags;
|
|
|
|
return $tags;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|