Files
piratepoet/lib/Entities/DynamicSegmentFilterData.php
Jan Lysý b816c6389f Add BC compatibility for getters
If a migration to new columns wasn't executed correctly, we want to be sure that getters return the correct value.
[MAILPOET-3910]
2021-11-04 14:52:21 +03:00

79 lines
1.9 KiB
PHP

<?php declare(strict_types = 1);
namespace MailPoet\Entities;
use MailPoet\Segments\DynamicSegments\Filters\UserRole;
use MailPoetVendor\Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Embeddable()
*/
class DynamicSegmentFilterData {
const TYPE_USER_ROLE = 'userRole';
const TYPE_EMAIL = 'email';
const TYPE_WOOCOMMERCE = 'woocommerce';
const TYPE_WOOCOMMERCE_SUBSCRIPTION = 'woocommerceSubscription';
public const CONNECT_TYPE_AND = 'and';
public const CONNECT_TYPE_OR = 'or';
/**
* @ORM\Column(type="serialized_array")
* @var array|null
*/
private $filterData;
/**
* @ORM\Column(type="string", nullable=true)
* @var string|null
*/
private $filterType;
/**
* @ORM\Column(type="string", nullable=true)
* @var string|null
*/
private $action;
public function __construct(
string $filterType,
string $action,
array $filterData = []
) {
$this->filterType = $filterType;
$this->action = $action;
$this->filterData = $filterData;
}
public function getData(): ?array {
return $this->filterData;
}
/**
* @return mixed|null
*/
public function getParam(string $name) {
return $this->filterData[$name] ?? null;
}
public function getFilterType(): ?string {
if ($this->filterType) {
return $this->filterType;
}
// When a new column is empty, we try to get the value from serialized data
return $filterData['segmentType'] ?? null;
}
public function getAction(): ?string {
if ($this->action) {
return $this->action;
}
// When a new column is empty, we try to get the value from serialized data
// BC compatibility, the wordpress user role segment didn't have action
if ($this->getFilterType() === self::TYPE_USER_ROLE && !isset($this->filterData['action'])) {
return UserRole::TYPE;
}
return $this->filterData['action'] ?? null;
}
}