Perforce Chronicle 2012.2/486814
API Documentation
|
A 'pub-sub' record is a record that can be modified via pub/sub. More...
Public Member Functions | |
delete ($description=null) | |
Extend basic delete to allow third-party participation via pub/sub. | |
save ($description=null, $options=null) | |
Extend basic save to allow third-party participation via pub/sub. | |
Static Public Member Functions | |
static | count (P4Cms_Record_Query $query=null, P4Cms_Record_Adapter $adapter=null) |
Extended basic count to provide a 'query' pub/sub topic. | |
static | fetchAll ($query=null, P4Cms_Record_Adapter $adapter=null) |
Extended basic fetchAll to provide a 'query' pub/sub topic. | |
static | getTopic () |
Get the topic for publishing this record. | |
static | hasTopic () |
Check if a topic has been set for this form. | |
Public Attributes | |
const | SAVE_SKIP_PUBSUB = 'skipPubSub' |
Static Protected Attributes | |
static | $_topic = null |
A 'pub-sub' record is a record that can be modified via pub/sub.
Topics published:
<record-topic>.preSave - do work (e.g. manipulate record) before it is saved <record-topic>.postSave - do work after record is saved, but before it is committed <record-topic>.query - influence query options for fetch/fetchAll/count/exists
static P4Cms_Record_PubSubRecord::count | ( | P4Cms_Record_Query $ | query = null , |
P4Cms_Record_Adapter $ | adapter = null |
||
) | [static] |
Extended basic count to provide a 'query' pub/sub topic.
P4Cms_Record_Query | $query | optional - query options to augment result. |
P4Cms_Record_Adapter | $adapter | optional - storage adapter to use. |
Reimplemented from P4Cms_Record.
{ $query = static::_normalizeQuery($query); // if no adapter given, use default. $adapter = $adapter ?: static::getDefaultAdapter(); // give third-parties a change to influence query. P4Cms_PubSub::publish( static::getTopic() . P4Cms_PubSub::TOPIC_DELIMITER . "query", $query, $adapter ); return parent::count($query, $adapter); }
P4Cms_Record_PubSubRecord::delete | ( | $ | description = null | ) |
Extend basic delete to allow third-party participation via pub/sub.
string | $description | optional - a description of the change. |
Reimplemented from P4Cms_Record.
Reimplemented in P4Cms_Content.
{ // ensure we have a change description. $description = $description ?: $this->_generateSubmitDescription(); // start the batch $adapter = $this->getAdapter(); $batch = !$adapter->inBatch() ? $adapter->beginBatch($description) : false; // wrap in a try/catch so we can cleanup if something goes wrong. try { // allow third-parties to interact with record prior to delete. P4Cms_PubSub::publish( static::getTopic() . P4Cms_PubSub::TOPIC_DELIMITER . "delete", $this ); // now let parent do a normal delete. parent::delete($description); } catch (Exception $e) { if ($batch) { $adapter->revertBatch(); } throw $e; } // commit the batch. if ($batch) { $adapter->commitBatch(); } return $this; }
static P4Cms_Record_PubSubRecord::fetchAll | ( | $ | query = null , |
P4Cms_Record_Adapter $ | adapter = null |
||
) | [static] |
Extended basic fetchAll to provide a 'query' pub/sub topic.
P4Cms_Record_Query | array | null | $query | optional - query options to augment result. |
P4Cms_Record_Adapter | $adapter | optional - storage adapter to use. |
Reimplemented from P4Cms_Record.
{ $query = static::_normalizeQuery($query); // if no adapter given, use default. $adapter = $adapter ?: static::getDefaultAdapter(); // give third-parties a change to influence query. P4Cms_PubSub::publish( static::getTopic() . P4Cms_PubSub::TOPIC_DELIMITER . "query", $query, $adapter ); return parent::fetchAll($query, $adapter); }
static P4Cms_Record_PubSubRecord::getTopic | ( | ) | [static] |
Get the topic for publishing this record.
InvalidArgumentException | if no topic is set. |
{ if (static::$_topic === null) { throw new P4Cms_Record_Exception("No topic set for this record"); } return static::$_topic; }
static P4Cms_Record_PubSubRecord::hasTopic | ( | ) | [static] |
Check if a topic has been set for this form.
{
return !is_null(static::$_topic);
}
P4Cms_Record_PubSubRecord::save | ( | $ | description = null , |
$ | options = null |
||
) |
Extend basic save to allow third-party participation via pub/sub.
Two topics are published:
preSave - fires after batch is started, but before record is saved postSave - fires after record is saved, but before batch is committed
The entire operation is wrapped in a batch (unless there is already a batch underway). The batch will be committed automatically unless an exception occurs, in which case the batch will be reverted.
string | $description | optional - a description of the change. |
null | string | array | $options | optional - augment save behavior: |
SAVE_THROW_CONFLICTS - throw exceptions on conflicts, default is to silently overwrite SAVE_SKIP_PUBSUB - don't publish pre/post save topics
Reimplemented from P4Cms_Record.
Reimplemented in P4Cms_Content.
{ // if we are skipping pub/sub, let parent take care of everything. if (in_array(static::SAVE_SKIP_PUBSUB, (array) $options)) { return parent::save($description, $options); } // ensure we have a save description. $description = $description ?: $this->_generateSubmitDescription(); // start the batch $adapter = $this->getAdapter(); $batch = !$adapter->inBatch() ? $adapter->beginBatch($description) : false; // wrap in a try/catch so we can cleanup if something goes wrong. try { // allow third-parties to manipulate record prior to save. P4Cms_PubSub::publish( static::getTopic() . P4Cms_PubSub::TOPIC_DELIMITER . "preSave", $this ); // now let parent do a normal save. parent::save($description, $options); // allow third-parties to interact with record post save. P4Cms_PubSub::publish( static::getTopic() . P4Cms_PubSub::TOPIC_DELIMITER . "postSave", $this ); } catch (Exception $e) { if ($batch) { $adapter->revertBatch(); } throw $e; } // commit the batch. if ($batch) { $adapter->commitBatch(null, $options); } return $this; }
P4Cms_Record_PubSubRecord::$_topic = null [static, protected] |
Reimplemented in P4Cms_Content.
const P4Cms_Record_PubSubRecord::SAVE_SKIP_PUBSUB = 'skipPubSub' |