|
|
|
@ -40,8 +40,11 @@ class Envelope |
|
|
|
/** |
|
|
|
/** |
|
|
|
* A place to store the raw envelope when it is closed. |
|
|
|
* A place to store the raw envelope when it is closed. |
|
|
|
* |
|
|
|
* |
|
|
|
* It follows the format 'type:content', where type is the wrapper plugin |
|
|
|
* It follows the format 'type,origin_branch_id:content', where: |
|
|
|
* machine name and content is the real blob as generated by the plugin. |
|
|
|
* - 'type': the wrapper plugin machine name. |
|
|
|
|
|
|
|
* - 'origin_branch_id': The branch id of the branch where the blob was |
|
|
|
|
|
|
|
* generated. |
|
|
|
|
|
|
|
* - 'content': is the real blob as generated by the plugin. |
|
|
|
* |
|
|
|
* |
|
|
|
* @var string |
|
|
|
* @var string |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -58,16 +61,25 @@ class Envelope |
|
|
|
* @var WrapperPluginInterface |
|
|
|
* @var WrapperPluginInterface |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected $wrapperPlugin; |
|
|
|
protected $wrapperPlugin; |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* The branch id where the related envelope comes from if any. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @var int |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected $originBranchId = false; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Basic constructor. |
|
|
|
* Basic constructor. |
|
|
|
* |
|
|
|
* |
|
|
|
|
|
|
|
* @param WrapperPluginInterface $wrapper_plugin |
|
|
|
|
|
|
|
* A ChamiloLMS\WrapperPluginInterface object. |
|
|
|
* @param array $data |
|
|
|
* @param array $data |
|
|
|
* Information to build the object. The supported array keys are: |
|
|
|
* Information to build the object. The supported array keys are: |
|
|
|
* - 'transactions': An array of ChamiloLMS\Transaction\TransactionLog |
|
|
|
* - 'transactions': An array of ChamiloLMS\Transaction\TransactionLog |
|
|
|
* objects to include. |
|
|
|
* objects to include. Required if 'blob' is not passed. |
|
|
|
* - 'blob': A string containing the envelope in raw form. |
|
|
|
* - 'blob': A string containing the envelope in raw form. Required if |
|
|
|
* - 'wrapper_plugin': A ChamiloLMS\WrapperPluginInterface object. |
|
|
|
* 'transactions' is not passed. |
|
|
|
|
|
|
|
* - 'origin_branch_id': Associated branch id if any. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function __construct(WrapperPluginInterface $wrapper_plugin, $data) |
|
|
|
public function __construct(WrapperPluginInterface $wrapper_plugin, $data) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -83,6 +95,9 @@ class Envelope |
|
|
|
$this->blob = $data['blob']; |
|
|
|
$this->blob = $data['blob']; |
|
|
|
$this->state |= self::STATE_CLOSED; |
|
|
|
$this->state |= self::STATE_CLOSED; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!empty($data['origin_branch_id'])) { |
|
|
|
|
|
|
|
$this->originBranchId = $data['origin_branch_id']; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -95,7 +110,7 @@ class Envelope |
|
|
|
if ($this->state & self::STATE_OPEN) { |
|
|
|
if ($this->state & self::STATE_OPEN) { |
|
|
|
return $this->transactions; |
|
|
|
return $this->transactions; |
|
|
|
} |
|
|
|
} |
|
|
|
return NULL; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -108,7 +123,30 @@ class Envelope |
|
|
|
if ($this->state & self::STATE_CLOSED) { |
|
|
|
if ($this->state & self::STATE_CLOSED) { |
|
|
|
return $this->blob; |
|
|
|
return $this->blob; |
|
|
|
} |
|
|
|
} |
|
|
|
return NULL; |
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Get related branch id. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return mixed |
|
|
|
|
|
|
|
* Branch id if defined or null if not available. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public function getOriginBranchId() { |
|
|
|
|
|
|
|
if (!empty($this->originBranchId)) { |
|
|
|
|
|
|
|
return $this->originBranchId; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Set related branch id. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param integer $branch_id |
|
|
|
|
|
|
|
* Related branch id. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public function setOriginBranchId($branch_id) { |
|
|
|
|
|
|
|
$this->originBranchId = $branch_id; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -117,20 +155,26 @@ class Envelope |
|
|
|
* @param string $blob |
|
|
|
* @param string $blob |
|
|
|
* A raw blob. |
|
|
|
* A raw blob. |
|
|
|
* |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
* @throws Exception |
|
|
|
* The envelope wrapper plugin machine type or false if it is not |
|
|
|
* Cannot identify the blob correctly. |
|
|
|
* possible to determine it. |
|
|
|
* |
|
|
|
|
|
|
|
* @return array |
|
|
|
|
|
|
|
* An array with the metadata. Contains the following keys: |
|
|
|
|
|
|
|
* - 'type': The wrapper plugin machine name. |
|
|
|
|
|
|
|
* - 'origin_branch_id': The branch where the blob was generated. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static function identifyBlobType($blob) { |
|
|
|
public static function identifyBlobMetadata($blob) { |
|
|
|
$position = strpos($blob, ':'); |
|
|
|
$position = strpos($blob, ':'); |
|
|
|
if ($position === FALSE) { |
|
|
|
if ($position === FALSE) { |
|
|
|
return FALSE; |
|
|
|
throw new Exception('blob identify: Cannot find ":" on the blob.'); |
|
|
|
} |
|
|
|
} |
|
|
|
$blob_type = substr($blob, 0, $position); |
|
|
|
$blob_metadata = substr($blob, 0, $position); |
|
|
|
if ($blob_type === FALSE) { |
|
|
|
if ($blob_metadata === FALSE) { |
|
|
|
return FALSE; |
|
|
|
throw new Exception('blob identify: Cannot extract correctly the blob metadata.'); |
|
|
|
} |
|
|
|
} |
|
|
|
return $blob_type; |
|
|
|
list($blob_type, $origin_branch_id) = explode(',', $blob_metadata); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return array('blob_type' => $blob_type, 'origin_branch_id' => $origin_branch_id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -145,7 +189,7 @@ class Envelope |
|
|
|
} |
|
|
|
} |
|
|
|
try { |
|
|
|
try { |
|
|
|
$this->prepare(); |
|
|
|
$this->prepare(); |
|
|
|
$this->blob = sprintf('%s:%s', $this->wrapperPlugin->getMachineName(), $this->wrapperPlugin->wrap($this->transactions)); |
|
|
|
$this->blob = sprintf('%s,%d:%s', $this->wrapperPlugin->getMachineName(), $this->getOriginBranchId(), $this->wrapperPlugin->wrap($this->transactions)); |
|
|
|
$this->state |= self::STATE_CLOSED; |
|
|
|
$this->state |= self::STATE_CLOSED; |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception $exception) { |
|
|
|
catch (Exception $exception) { |
|
|
|
|