src/AppBundle/Entity/EstateFlow.php line 109

Open in your IDE?
  1. <?php
  2. namespace App\AppBundle\Entity;
  3. use DateTime;
  4. class EstateFlow
  5. {
  6.     const STATUS_OK 'ok';
  7.     const STATUS_FAIL 'fail';
  8.     const STATUS_OUTDATED 'outdated';
  9.     const STATUS_PENDING 'pending';
  10.     // const options for status
  11.     const STATUS_OPTIONS = [
  12.         self::STATUS_OK,
  13.         self::STATUS_FAIL,
  14.         self::STATUS_OUTDATED,
  15.         self::STATUS_PENDING
  16.     ];
  17.     
  18.     /**
  19.      *
  20.      * @var integer
  21.      */
  22.     protected $id;
  23.     /**
  24.      *
  25.      * @var ModelEntity
  26.      */
  27.     protected $modelEntity;
  28.     /**
  29.      *
  30.      * @var EstateFlowScenario
  31.      */
  32.     protected $sequence;
  33.     /**
  34.      *
  35.      * @var EstateFlowScenarioTimeline
  36.      */
  37.     protected $timeline;
  38.     /**
  39.      *
  40.      * @var string
  41.      */
  42.     protected $result;
  43.     /**
  44.      *
  45.      * @var DateTime
  46.      */
  47.     protected $createdAt;
  48.     /**
  49.      *
  50.      * @var DateTime
  51.      */
  52.     protected $updatedAt;
  53.     /**
  54.      *
  55.      * @var string
  56.      */
  57.     protected $relatedData;
  58.     /**
  59.      *
  60.      * @var string
  61.      */
  62.     protected $status;  
  63.     /**
  64.      *
  65.      * @var DateTime
  66.      */
  67.     protected $accessedAt;
  68.     /**
  69.      * Constructor
  70.      */
  71.     public function __construct()
  72.     {
  73.     
  74.     }
  75.     /**
  76.      * Get id
  77.      *
  78.      * @return integer
  79.      */
  80.     public function getId(): ?int
  81.     {
  82.         return $this->id;
  83.     }
  84.     public function setResult(string $result): self
  85.     {
  86.         // Ensure the result is properly compressed before storing
  87.         $this->result gzcompress($result9);
  88.         return $this;
  89.     }
  90.     /**
  91.      * Set result with custom compression
  92.      * 
  93.      * @param string $result The uncompressed result data
  94.      * @param int $level Compression level (0-9, default 9)
  95.      * @return self
  96.      */
  97.     public function setResultCompressed(string $resultint $level 9): self
  98.     {
  99.         $this->result gzcompress($result$level);
  100.         return $this;
  101.     }
  102.     /**
  103.      * Set result without compression (for backward compatibility)
  104.      * 
  105.      * @param string $result The result data (will be stored as-is)
  106.      * @return self
  107.      */
  108.     public function setResultUncompressed(string $result): self
  109.     {
  110.         $this->result $result;
  111.         return $this;
  112.     }
  113.     /**
  114.      * 
  115.      * @return String|bool
  116.      */
  117.     public function getResult()
  118.     {
  119.         if ($this->result) {
  120.             try {
  121.                 // Handle different data types that Doctrine might return for BLOB fields
  122.                 $compressedData $this->result;
  123.                 
  124.                 // If it's a stream resource, get its contents
  125.                 if (is_resource($this->result) && get_resource_type($this->result) === 'stream') {
  126.                     $compressedData stream_get_contents($this->result);
  127.                     // Reset stream position if it's seekable
  128.                     if (stream_get_meta_data($this->result)['seekable']) {
  129.                         rewind($this->result);
  130.                     }
  131.                 }
  132.                 
  133.                 // If it's already a string, use it directly
  134.                 if (is_string($compressedData)) {
  135.                     // Try to decompress the data
  136.                     $decompressed gzuncompress($compressedData);
  137.                     if ($decompressed === false) {
  138.                         // If gzuncompress fails, try gzinflate (for gzdeflate compressed data)
  139.                         $decompressed gzinflate($compressedData);
  140.                         if ($decompressed === false) {
  141.                             // If both fail, the data might be corrupted or not compressed
  142.                             error_log(sprintf(
  143.                                 'EstateFlow::getResult() - Both gzuncompress and gzinflate failed for EstateFlow ID %d',
  144.                                 $this->id ?? 'unknown'
  145.                             ));
  146.                             return "";
  147.                         }
  148.                     }
  149.                     return $decompressed;
  150.                 }
  151.                 
  152.                 // If we get here, the data type is unexpected
  153.                 error_log(sprintf(
  154.                     'EstateFlow::getResult() - Unexpected data type for EstateFlow ID %d: %s',
  155.                     $this->id ?? 'unknown',
  156.                     gettype($this->result)
  157.                 ));
  158.                 return "";
  159.                 
  160.             } catch (\Exception $e) {
  161.                 // Log the error using PHP's built-in error_log
  162.                 error_log(sprintf(
  163.                     'EstateFlow::getResult() - Decompression failed for EstateFlow ID %d: %s in %s:%d',
  164.                     $this->id ?? 'unknown',
  165.                     $e->getMessage(),
  166.                     $e->getFile(),
  167.                     $e->getLine()
  168.                 ));
  169.                 
  170.                 // Return empty string as fallback
  171.                 return "";
  172.             }
  173.         }
  174.         return "";
  175.     }
  176.     /**
  177.      * Set createdAt
  178.      *
  179.      * @return \self
  180.      */
  181.     public function setCreatedAt(): self
  182.     {
  183.         if (!$this->createdAt) {
  184.             $this->createdAt = new DateTime();
  185.         }
  186.         return $this;
  187.     }
  188.     /**
  189.      * Get createdAt
  190.      *
  191.      * @return \DateTime|null
  192.      */
  193.     public function getCreatedAt(): ?DateTime
  194.     {
  195.         return $this->createdAt;
  196.     }
  197.     /**
  198.      * Set updatedAt
  199.      *
  200.      * @return \self
  201.      */
  202.     public function setUpdatedAt(): self
  203.     {
  204.         $this->updatedAt = new DateTime();
  205.         return $this;
  206.     }
  207.     /**
  208.      * Get updatedAt
  209.      *
  210.      * @return DateTime
  211.      */
  212.     public function getUpdatedAt(): ?DateTime
  213.     {
  214.         return $this->updatedAt;
  215.     }
  216.     /**
  217.      *
  218.      * @param ModelEntity $modelEntity
  219.      * @return \self
  220.      */
  221.     public function setModelEntity(ModelEntity $modelEntity): self
  222.     {
  223.         $this->modelEntity $modelEntity;
  224.         return $this;
  225.     }
  226.     /**
  227.      * Get ModelEntity
  228.      *
  229.      * @return ModelEntity
  230.      */
  231.     public function getModelEntity(): ?ModelEntity
  232.     {
  233.         return $this->modelEntity;
  234.     }
  235.     /**
  236.      *
  237.      * @param EstateFlowScenario $target
  238.      * @return \self
  239.      */
  240.     public function setSequence(EstateFlowScenario $sequence): self
  241.     {
  242.         $this->sequence $sequence;
  243.         return $this;
  244.     }
  245.     /**
  246.      * Get sequence
  247.      *
  248.      * @return EstateFlowScenario
  249.      */
  250.     public function getSequence(): ?EstateFlowScenario
  251.     {
  252.         return $this->sequence;
  253.     }
  254.     /**
  255.      *
  256.      * @param EstateFlowScenarioTimeline $target
  257.      * @return \self
  258.      */
  259.     public function setTimeline(EstateFlowScenarioTimeline $timeline): self
  260.     {
  261.         $this->timeline $timeline;
  262.         return $this;
  263.     }
  264.     /**
  265.      * Get timeline
  266.      *
  267.      * @return EstateFlowScenarioTimeline
  268.      */
  269.     public function getTimeline(): ?EstateFlowScenarioTimeline
  270.     {
  271.         return $this->timeline;
  272.     }
  273.     // Get relatedData
  274.     public function getRelatedData(): ?string
  275.     {
  276.         return $this->relatedData;
  277.     }       
  278.     // Set relatedData
  279.     public function setRelatedData(string $relatedData): self
  280.     {
  281.         $this->relatedData $relatedData;
  282.         return $this;
  283.     }
  284.     // Get status
  285.     public function getStatus(): ?string
  286.     {
  287.         return $this->status;
  288.     }       
  289.     // Set status
  290.     public function setStatus(string $status): self
  291.     {
  292.         $this->status $status;
  293.         return $this;
  294.     }
  295.     // Get accessedAt
  296.     public function getAccessedAt(): ?DateTime
  297.     {
  298.         return $this->accessedAt;
  299.     }       
  300.     // Set accessedAt
  301.     public function setAccessedAt(?DateTime $accessedAt null): self
  302.     {
  303.         $this->accessedAt $accessedAt ?? new DateTime();
  304.         return $this;
  305.     }
  306. }