<?php
namespace App\AppBundle\Entity;
use DateTime;
class EstateFlow
{
const STATUS_OK = 'ok';
const STATUS_FAIL = 'fail';
const STATUS_OUTDATED = 'outdated';
const STATUS_PENDING = 'pending';
// const options for status
const STATUS_OPTIONS = [
self::STATUS_OK,
self::STATUS_FAIL,
self::STATUS_OUTDATED,
self::STATUS_PENDING
];
/**
*
* @var integer
*/
protected $id;
/**
*
* @var ModelEntity
*/
protected $modelEntity;
/**
*
* @var EstateFlowScenario
*/
protected $sequence;
/**
*
* @var EstateFlowScenarioTimeline
*/
protected $timeline;
/**
*
* @var string
*/
protected $result;
/**
*
* @var DateTime
*/
protected $createdAt;
/**
*
* @var DateTime
*/
protected $updatedAt;
/**
*
* @var string
*/
protected $relatedData;
/**
*
* @var string
*/
protected $status;
/**
*
* @var DateTime
*/
protected $accessedAt;
/**
* Constructor
*/
public function __construct()
{
}
/**
* Get id
*
* @return integer
*/
public function getId(): ?int
{
return $this->id;
}
public function setResult(string $result): self
{
// Ensure the result is properly compressed before storing
$this->result = gzcompress($result, 9);
return $this;
}
/**
* Set result with custom compression
*
* @param string $result The uncompressed result data
* @param int $level Compression level (0-9, default 9)
* @return self
*/
public function setResultCompressed(string $result, int $level = 9): self
{
$this->result = gzcompress($result, $level);
return $this;
}
/**
* Set result without compression (for backward compatibility)
*
* @param string $result The result data (will be stored as-is)
* @return self
*/
public function setResultUncompressed(string $result): self
{
$this->result = $result;
return $this;
}
/**
*
* @return String|bool
*/
public function getResult()
{
if ($this->result) {
try {
// Handle different data types that Doctrine might return for BLOB fields
$compressedData = $this->result;
// If it's a stream resource, get its contents
if (is_resource($this->result) && get_resource_type($this->result) === 'stream') {
$compressedData = stream_get_contents($this->result);
// Reset stream position if it's seekable
if (stream_get_meta_data($this->result)['seekable']) {
rewind($this->result);
}
}
// If it's already a string, use it directly
if (is_string($compressedData)) {
// Try to decompress the data
$decompressed = gzuncompress($compressedData);
if ($decompressed === false) {
// If gzuncompress fails, try gzinflate (for gzdeflate compressed data)
$decompressed = gzinflate($compressedData);
if ($decompressed === false) {
// If both fail, the data might be corrupted or not compressed
error_log(sprintf(
'EstateFlow::getResult() - Both gzuncompress and gzinflate failed for EstateFlow ID %d',
$this->id ?? 'unknown'
));
return "";
}
}
return $decompressed;
}
// If we get here, the data type is unexpected
error_log(sprintf(
'EstateFlow::getResult() - Unexpected data type for EstateFlow ID %d: %s',
$this->id ?? 'unknown',
gettype($this->result)
));
return "";
} catch (\Exception $e) {
// Log the error using PHP's built-in error_log
error_log(sprintf(
'EstateFlow::getResult() - Decompression failed for EstateFlow ID %d: %s in %s:%d',
$this->id ?? 'unknown',
$e->getMessage(),
$e->getFile(),
$e->getLine()
));
// Return empty string as fallback
return "";
}
}
return "";
}
/**
* Set createdAt
*
* @return \self
*/
public function setCreatedAt(): self
{
if (!$this->createdAt) {
$this->createdAt = new DateTime();
}
return $this;
}
/**
* Get createdAt
*
* @return \DateTime|null
*/
public function getCreatedAt(): ?DateTime
{
return $this->createdAt;
}
/**
* Set updatedAt
*
* @return \self
*/
public function setUpdatedAt(): self
{
$this->updatedAt = new DateTime();
return $this;
}
/**
* Get updatedAt
*
* @return DateTime
*/
public function getUpdatedAt(): ?DateTime
{
return $this->updatedAt;
}
/**
*
* @param ModelEntity $modelEntity
* @return \self
*/
public function setModelEntity(ModelEntity $modelEntity): self
{
$this->modelEntity = $modelEntity;
return $this;
}
/**
* Get ModelEntity
*
* @return ModelEntity
*/
public function getModelEntity(): ?ModelEntity
{
return $this->modelEntity;
}
/**
*
* @param EstateFlowScenario $target
* @return \self
*/
public function setSequence(EstateFlowScenario $sequence): self
{
$this->sequence = $sequence;
return $this;
}
/**
* Get sequence
*
* @return EstateFlowScenario
*/
public function getSequence(): ?EstateFlowScenario
{
return $this->sequence;
}
/**
*
* @param EstateFlowScenarioTimeline $target
* @return \self
*/
public function setTimeline(EstateFlowScenarioTimeline $timeline): self
{
$this->timeline = $timeline;
return $this;
}
/**
* Get timeline
*
* @return EstateFlowScenarioTimeline
*/
public function getTimeline(): ?EstateFlowScenarioTimeline
{
return $this->timeline;
}
// Get relatedData
public function getRelatedData(): ?string
{
return $this->relatedData;
}
// Set relatedData
public function setRelatedData(string $relatedData): self
{
$this->relatedData = $relatedData;
return $this;
}
// Get status
public function getStatus(): ?string
{
return $this->status;
}
// Set status
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
// Get accessedAt
public function getAccessedAt(): ?DateTime
{
return $this->accessedAt;
}
// Set accessedAt
public function setAccessedAt(?DateTime $accessedAt = null): self
{
$this->accessedAt = $accessedAt ?? new DateTime();
return $this;
}
}