Deprecate CustomField model as it is not used anymore
[MAILPOET-5763]
This commit is contained in:
@@ -9,8 +9,10 @@ use MailPoet\Util\DateConverter;
|
|||||||
* @property string $name
|
* @property string $name
|
||||||
* @property string $type
|
* @property string $type
|
||||||
* @property string|array|null $params
|
* @property string|array|null $params
|
||||||
|
*
|
||||||
|
* @deprecated This model is deprecated. Use \MailPoet\CustomFields\CustomFieldsRepository and
|
||||||
|
* \MailPoet\Entities\CustomFieldEntity instead. This class can be removed after 2024-05-30.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class CustomField extends Model {
|
class CustomField extends Model {
|
||||||
public static $_table = MP_CUSTOM_FIELDS_TABLE; // phpcs:ignore PSR2.Classes.PropertyDeclaration
|
public static $_table = MP_CUSTOM_FIELDS_TABLE; // phpcs:ignore PSR2.Classes.PropertyDeclaration
|
||||||
const TYPE_DATE = CustomFieldEntity::TYPE_DATE;
|
const TYPE_DATE = CustomFieldEntity::TYPE_DATE;
|
||||||
@@ -20,7 +22,11 @@ class CustomField extends Model {
|
|||||||
const TYPE_CHECKBOX = CustomFieldEntity::TYPE_CHECKBOX;
|
const TYPE_CHECKBOX = CustomFieldEntity::TYPE_CHECKBOX;
|
||||||
const TYPE_SELECT = CustomFieldEntity::TYPE_SELECT;
|
const TYPE_SELECT = CustomFieldEntity::TYPE_SELECT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
|
self::deprecationError(__METHOD__);
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->addValidations('name', [
|
$this->addValidations('name', [
|
||||||
'required' => __('Please specify a name.', 'mailpoet'),
|
'required' => __('Please specify a name.', 'mailpoet'),
|
||||||
@@ -30,7 +36,11 @@ class CustomField extends Model {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
public function asArray() {
|
public function asArray() {
|
||||||
|
self::deprecationError(__METHOD__);
|
||||||
$model = parent::asArray();
|
$model = parent::asArray();
|
||||||
|
|
||||||
if (isset($model['params'])) {
|
if (isset($model['params'])) {
|
||||||
@@ -41,7 +51,11 @@ class CustomField extends Model {
|
|||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
public function save() {
|
public function save() {
|
||||||
|
self::deprecationError(__METHOD__);
|
||||||
if (is_null($this->params)) {
|
if (is_null($this->params)) {
|
||||||
$this->params = [];
|
$this->params = [];
|
||||||
}
|
}
|
||||||
@@ -53,7 +67,11 @@ class CustomField extends Model {
|
|||||||
return parent::save();
|
return parent::save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
public function formatValue($value = null) {
|
public function formatValue($value = null) {
|
||||||
|
self::deprecationError(__METHOD__);
|
||||||
// format custom field data depending on type
|
// format custom field data depending on type
|
||||||
if (is_array($value) && $this->type === self::TYPE_DATE) {
|
if (is_array($value) && $this->type === self::TYPE_DATE) {
|
||||||
$customFieldData = $this->asArray();
|
$customFieldData = $this->asArray();
|
||||||
@@ -122,7 +140,11 @@ class CustomField extends Model {
|
|||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
public function subscribers() {
|
public function subscribers() {
|
||||||
|
self::deprecationError(__METHOD__);
|
||||||
return $this->hasManyThrough(
|
return $this->hasManyThrough(
|
||||||
__NAMESPACE__ . '\Subscriber',
|
__NAMESPACE__ . '\Subscriber',
|
||||||
__NAMESPACE__ . '\SubscriberCustomField',
|
__NAMESPACE__ . '\SubscriberCustomField',
|
||||||
@@ -131,11 +153,38 @@ class CustomField extends Model {
|
|||||||
)->selectExpr(MP_SUBSCRIBER_CUSTOM_FIELD_TABLE . '.value');
|
)->selectExpr(MP_SUBSCRIBER_CUSTOM_FIELD_TABLE . '.value');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
public static function createOrUpdate($data = []) {
|
public static function createOrUpdate($data = []) {
|
||||||
|
self::deprecationError(__METHOD__);
|
||||||
// set name as label by default
|
// set name as label by default
|
||||||
if (empty($data['params']['label']) && isset($data['name'])) {
|
if (empty($data['params']['label']) && isset($data['name'])) {
|
||||||
$data['params']['label'] = $data['name'];
|
$data['params']['label'] = $data['name'];
|
||||||
}
|
}
|
||||||
return parent::_createOrUpdate($data);
|
return parent::_createOrUpdate($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated This is here for displaying the deprecation warning for properties.
|
||||||
|
*/
|
||||||
|
public function __get($key) {
|
||||||
|
self::deprecationError('property "' . $key . '"');
|
||||||
|
return parent::__get($key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated This is here for displaying the deprecation warning for static calls.
|
||||||
|
*/
|
||||||
|
public static function __callStatic($name, $arguments) {
|
||||||
|
self::deprecationError($name);
|
||||||
|
return parent::__callStatic($name, $arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function deprecationError($methodName) {
|
||||||
|
trigger_error(
|
||||||
|
'Calling ' . esc_html($methodName) . ' is deprecated and will be removed. Use \MailPoet\CustomFields\CustomFieldsRepository and \MailPoet\Entities\CustomFieldEntity instead.',
|
||||||
|
E_USER_DEPRECATED
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user