|
Perforce Chronicle 2012.2/486814
API Documentation
|
Encapsulates everything needed for Records to read from and write to storage. More...
Public Member Functions | |
| beginBatch ($description) | |
| Start a batch. | |
| commitBatch ($description=null, $options=null) | |
| Commit the batch. | |
| getBasePath () | |
| Get the base path in Perforce under which records should be read from and written to. | |
| getBatchId () | |
| Get the id of the current batch. | |
| getConnection () | |
| Get the connection object to use to communicate with Perforce. | |
| getProperties () | |
| Get all properties of this adapter. | |
| getProperty ($name) | |
| Get a particular property value of this adapter. | |
| hasProperty ($name) | |
| Check if adapter has a particular property. | |
| inBatch () | |
| Determine if we are currently in a batch on this storage adapter. | |
| revertBatch () | |
| Reverts all files in the pending change corresponding to the batch id. | |
| setBasePath ($path) | |
| Set the base path in Perforce under which records should be read from and written to. | |
| setBatchDescription ($description) | |
| Change the description of the current batch. | |
| setConnection ($p4) | |
| Set the Perforce connection to use to communicate with the Perforce backend. | |
| setProperties (array $properties) | |
| Set adapter properties. | |
| setProperty ($name, $value) | |
| Set a particular property of this adapter. | |
Public Attributes | |
| const | COMMIT_THROW_CONFLICT = "throw" |
Protected Attributes | |
| $_basePath = null | |
| $_batchId = null | |
| $_connection = null | |
| $_properties = array() | |
Encapsulates everything needed for Records to read from and write to storage.
Specifically, a p4 connection, a base path in perforce, and a prefix for sequence counters.
| P4Cms_Record_Adapter::beginBatch | ( | $ | description | ) |
Start a batch.
Changes made to records will be placed in a numbered pending change and will not be submitted until the batch is committed.
Batches cannot be nested. Attempting to begin a batch while in a batch will result in an exception.
| string | $description | required - a description of the batch. |
| P4Cms_Record_Exception | if already in a batch. |
Reimplemented in P4Cms_Record_DeferredAdapter.
{
if ($this->inBatch()) {
throw new P4Cms_Record_Exception(
"Cannot begin batch. Already in a batch."
);
}
// create a new pending change.
$change = new P4_Change($this->getConnection());
$change->setDescription($description)->save();
return $this->_batchId = $change->getId();
}
| P4Cms_Record_Adapter::commitBatch | ( | $ | description = null, |
| $ | options = null |
||
| ) |
Commit the batch.
Submits the pending change corresponding to the batch id.
| string | $description | optional - a final description of the batch. |
| null | string | array | $options | optional - passing the SAVE_THROW_CONFLICTS flag will cause exceptions on conflict; default behaviour is to crush any conflicts. |
| P4Cms_Record_Exception | if not in a batch. |
Reimplemented in P4Cms_Record_DeferredAdapter.
{
if (!$this->inBatch()) {
throw new P4Cms_Record_Exception(
"Cannot commit batch. Not in a batch."
);
}
// submit the change identified by batch id.
$change = P4_Change::fetch(
$this->getBatchId(),
$this->getConnection()
);
try {
// default option is to 'accept yours' but we switch to
// null if SAVE_THROW_CONFLICTS flag is passed.
$resolveFlag = P4_Change::RESOLVE_ACCEPT_YOURS;
if (in_array(static::COMMIT_THROW_CONFLICT, (array)$options)) {
$resolveFlag = null;
}
$change->submit($description, $resolveFlag);
} catch (P4_Connection_CommandException $e) {
// ignore exception if change is empty - otherwise rethrow.
if (count($change->getFiles()) == 0) {
$change->delete();
} else {
throw $e;
}
}
// clear the batch id.
$this->_batchId = null;
return $this;
}
| P4Cms_Record_Adapter::getBasePath | ( | ) |
Get the base path in Perforce under which records should be read from and written to.
| P4Cms_Record_Exception | if no base path is set. |
Reimplemented in P4Cms_Record_DeferredAdapter.
{
if (!is_string($this->_basePath) || !strlen($this->_basePath)) {
throw new P4Cms_Record_Exception(
"Cannot get base path. No base path is set."
);
}
return $this->_basePath;
}
| P4Cms_Record_Adapter::getBatchId | ( | ) |
Get the id of the current batch.
The batch id corresponds to a pending changelist in Perforce.
| P4Cms_Record_Exception | if not in a batch. |
Reimplemented in P4Cms_Record_DeferredAdapter.
{
if (!$this->inBatch()) {
throw new P4Cms_Record_Exception(
"Cannot get batch id. Not in a batch."
);
}
return (int) $this->_batchId;
}
| P4Cms_Record_Adapter::getConnection | ( | ) |
Get the connection object to use to communicate with Perforce.
| P4Cms_Record_Exception | if no valid connection is set. |
Reimplemented in P4Cms_Record_DeferredAdapter.
{
if (!$this->_connection instanceof P4_Connection_Abstract) {
throw new P4Cms_Record_Exception(
"Cannot get connection. No valid p4 connection has been set."
);
}
return $this->_connection;
}
| P4Cms_Record_Adapter::getProperties | ( | ) |
Get all properties of this adapter.
Reimplemented in P4Cms_Record_DeferredAdapter.
{
return $this->_properties;
}
| P4Cms_Record_Adapter::getProperty | ( | $ | name | ) |
Get a particular property value of this adapter.
| string | $name | name of the property to get the value of |
| P4Cms_Record_Exception | if the property name does not exist |
Reimplemented in P4Cms_Record_DeferredAdapter.
{
// return property value if it was set, otherwise throw an exception
if ($this->hasProperty($name)) {
return $this->_properties[$name];
}
throw new P4Cms_Record_Exception(
"Cannot find adapter property '$name'. Property was not set."
);
}
| P4Cms_Record_Adapter::hasProperty | ( | $ | name | ) |
Check if adapter has a particular property.
| string | $name | the property name to check for the existence of |
Reimplemented in P4Cms_Record_DeferredAdapter.
{
return array_key_exists($name, $this->_properties);
}
| P4Cms_Record_Adapter::inBatch | ( | ) |
Determine if we are currently in a batch on this storage adapter.
Reimplemented in P4Cms_Record_DeferredAdapter.
{
$id = $this->_batchId;
return (int) $id > 0;
}
| P4Cms_Record_Adapter::revertBatch | ( | ) |
Reverts all files in the pending change corresponding to the batch id.
| P4Cms_Record_Exception | if not in a batch. |
Reimplemented in P4Cms_Record_DeferredAdapter.
{
if (!$this->inBatch()) {
throw new P4Cms_Record_Exception(
"Cannot revert batch. Not in a batch."
);
}
// revert the change identified by batch id.
$change = P4_Change::fetch(
$this->getBatchId(),
$this->getConnection()
);
$change->revert()
->delete();
// clear the batch id.
$this->_batchId = null;
return $this;
}
| P4Cms_Record_Adapter::setBasePath | ( | $ | path | ) |
Set the base path in Perforce under which records should be read from and written to.
| string | $path | the record storage base path. |
| P4Cms_Record_Exception | if the base path is not a valid string. |
Reimplemented in P4Cms_Record_DeferredAdapter.
{
if (!is_string($path) || !strlen($path)) {
throw new P4Cms_Record_Exception(
"Cannot set base path. Given path is not a valid string."
);
}
$this->_basePath = $path;
return $this;
}
| P4Cms_Record_Adapter::setBatchDescription | ( | $ | description | ) |
Change the description of the current batch.
| string | $description | the description of the current batch. |
Reimplemented in P4Cms_Record_DeferredAdapter.
{
$change = P4_Change::fetch(
$this->getBatchId(),
$this->getConnection()
);
$change->setDescription($description)
->save();
return $this;
}
| P4Cms_Record_Adapter::setConnection | ( | $ | p4 | ) |
Set the Perforce connection to use to communicate with the Perforce backend.
| P4_Connection_Abstract | $p4 | the p4 connection to use. |
| P4Cms_Record_Exception | if the connection object is invalid. |
Reimplemented in P4Cms_Record_DeferredAdapter.
{
if (!$p4 instanceof P4_Connection_Abstract) {
throw new P4Cms_Record_Exception(
"Cannot set connection. The given argument is not a valid p4 connection."
);
}
$this->_connection = $p4;
return $this;
}
| P4Cms_Record_Adapter::setProperties | ( | array $ | properties | ) |
Set adapter properties.
| array | $properties | array with properties to set |
Reimplemented in P4Cms_Record_DeferredAdapter.
{
$this->_properties = $properties;
return $this;
}
| P4Cms_Record_Adapter::setProperty | ( | $ | name, |
| $ | value | ||
| ) |
Set a particular property of this adapter.
| string | $name | name of the property to set the value of |
| mixed | $value | value to set |
Reimplemented in P4Cms_Record_DeferredAdapter.
{
$this->_properties[$name] = $value;
return $this;
}
P4Cms_Record_Adapter::$_basePath = null [protected] |
P4Cms_Record_Adapter::$_batchId = null [protected] |
P4Cms_Record_Adapter::$_connection = null [protected] |
P4Cms_Record_Adapter::$_properties = array() [protected] |
| const P4Cms_Record_Adapter::COMMIT_THROW_CONFLICT = "throw" |