From fa455afca1ebeab4e786352565b4d13aeaab36a5 Mon Sep 17 00:00:00 2001 From: Vova Feldman Date: Sun, 11 Dec 2022 18:44:13 +0200 Subject: [PATCH 1/2] [entities] [cleanup] Removed unused properties. --- .../entities/class-fs-affiliate-terms.php | 38 ------------------- includes/entities/class-fs-billing.php | 14 +------ includes/entities/class-fs-payment.php | 26 ------------- includes/entities/class-fs-plugin-license.php | 7 ---- includes/entities/class-fs-plugin-plan.php | 12 ------ includes/entities/class-fs-plugin-tag.php | 8 ---- includes/entities/class-fs-subscription.php | 32 ---------------- includes/entities/class-fs-user.php | 8 ---- 8 files changed, 1 insertion(+), 144 deletions(-) diff --git a/includes/entities/class-fs-affiliate-terms.php b/includes/entities/class-fs-affiliate-terms.php index b4573a3d3..f6f126d61 100644 --- a/includes/entities/class-fs-affiliate-terms.php +++ b/includes/entities/class-fs-affiliate-terms.php @@ -22,17 +22,6 @@ class FS_AffiliateTerms extends FS_Scope_Entity { * @var string Enum: `affiliation` or `rewards`. Defaults to `affiliation`. */ public $type; - /** - * @var string Enum: `payout` or `credit`. Defaults to `payout`. - */ - public $reward_type; - /** - * If `first`, the referral will be attributed to the first visited source containing the affiliation link that - * was clicked. - * - * @var string Enum: `first` or `last`. Defaults to `first`. - */ - public $referral_attribution; /** * @var int Defaults to `30`, `0` for session cookie, and `null` for endless cookie (until cookies are cleaned). */ @@ -51,39 +40,12 @@ class FS_AffiliateTerms extends FS_Scope_Entity { * the initial upgrade/purchase. */ public $commission_renewals_days; - /** - * @var int Only cents and no percentage. In US cents, e.g.: 100 = $1.00. Defaults to `null`. - */ - public $install_commission; - /** - * @var string Required default target link, e.g.: pricing page. - */ - public $default_url; - /** - * @var string One of the following: 'all', 'new_customer', 'new_user'. - * If 'all' - reward for any user type. - * If 'new_customer' - reward only for new customers. - * If 'new_user' - reward only for new users. - */ - public $reward_customer_type; /** * @var int Defaults to `0` (affiliate only on directly affiliated links). `null` if an affiliate will get * paid for all customers' lifetime payments. If greater than `0`, an affiliate will get paid for all * customer payments for `future_payments_days` days after the initial payment. */ public $future_payments_days; - /** - * @var bool If `true`, allow referrals from social sites. - */ - public $is_social_allowed; - /** - * @var bool If `true`, allow conversions without HTTP referrer header at all. - */ - public $is_app_allowed; - /** - * @var bool If `true`, allow referrals from any site. - */ - public $is_any_site_allowed; /** * @var string $plugin_title Title of the plugin. This is used in case we are showing affiliate form for a Bundle instead of the `plugin` in context. */ diff --git a/includes/entities/class-fs-billing.php b/includes/entities/class-fs-billing.php index bf6840179..23a9e9c0c 100644 --- a/includes/entities/class-fs-billing.php +++ b/includes/entities/class-fs-billing.php @@ -14,14 +14,6 @@ class FS_Billing extends FS_Entity { #region Properties - /** - * @var int - */ - public $entity_id; - /** - * @var string (Enum) Linked entity type. One of: developer, plugin, user, install - */ - public $entity_type; /** * @var string */ @@ -62,10 +54,6 @@ class FS_Billing extends FS_Entity { * @var string */ public $address_city; - /** - * @var string - */ - public $address_country; /** * @var string Two chars country code. */ @@ -75,7 +63,7 @@ class FS_Billing extends FS_Entity { */ public $address_state; /** - * @var number Numeric ZIP code (cab be with leading zeros). + * @var number Numeric ZIP code (can be with leading zeros). */ public $address_zip; diff --git a/includes/entities/class-fs-payment.php b/includes/entities/class-fs-payment.php index 8e3576637..b846a7387 100755 --- a/includes/entities/class-fs-payment.php +++ b/includes/entities/class-fs-payment.php @@ -26,10 +26,6 @@ class FS_Payment extends FS_Entity { * @var number */ public $install_id; - /** - * @var number - */ - public $subscription_id; /** * @var number */ @@ -53,28 +49,6 @@ class FS_Payment extends FS_Entity { * @var number */ public $bound_payment_id; - /** - * @var string - */ - public $external_id; - /** - * @var string - */ - public $gateway; - /** - * @var string ISO 3166-1 alpha-2 - two-letter country code. - * - * @link http://www.wikiwand.com/en/ISO_3166-1_alpha-2 - */ - public $country_code; - /** - * @var string - */ - public $vat_id; - /** - * @var float Actual Tax / VAT in $$$ - */ - public $vat; /** * @var int Payment source. */ diff --git a/includes/entities/class-fs-plugin-license.php b/includes/entities/class-fs-plugin-license.php index e945e51ed..bc5368905 100755 --- a/includes/entities/class-fs-plugin-license.php +++ b/includes/entities/class-fs-plugin-license.php @@ -29,13 +29,6 @@ class FS_Plugin_License extends FS_Entity { * @var number */ public $plan_id; - /** - * @author Leo Fajardo (@leorw) - * @since 2.3.0 - * - * @var string - */ - public $parent_plan_name; /** * @author Leo Fajardo (@leorw) * @since 2.3.0 diff --git a/includes/entities/class-fs-plugin-plan.php b/includes/entities/class-fs-plugin-plan.php index 00a0d747b..cca28606f 100755 --- a/includes/entities/class-fs-plugin-plan.php +++ b/includes/entities/class-fs-plugin-plan.php @@ -35,10 +35,6 @@ class FS_Plugin_Plan extends FS_Entity { * @var string */ public $description; - /** - * @var bool Defaults to true. If true, allow unlimited localhost installs with the same license. - */ - public $is_free_localhost; /** * @var bool Defaults to true. If false, don't block features after license expiry - only block updates and * support. @@ -48,10 +44,6 @@ class FS_Plugin_Plan extends FS_Entity { * @var int */ public $license_type; - /** - * @var bool - */ - public $is_https_support; /** * @var int Trial days. */ @@ -84,10 +76,6 @@ class FS_Plugin_Plan extends FS_Entity { * @var bool Is personal success manager supported with the plan. */ public $is_success_manager; - /** - * @var bool Is featured plan. - */ - public $is_featured; #endregion Properties diff --git a/includes/entities/class-fs-plugin-tag.php b/includes/entities/class-fs-plugin-tag.php index a583a2614..6cbe7d782 100755 --- a/includes/entities/class-fs-plugin-tag.php +++ b/includes/entities/class-fs-plugin-tag.php @@ -31,14 +31,6 @@ class FS_Plugin_Tag extends FS_Entity { * @var string */ public $tested_up_to_version; - /** - * @var bool - */ - public $has_free; - /** - * @var bool - */ - public $has_premium; /** * @var string One of the following: `pending`, `beta`, `unreleased`. */ diff --git a/includes/entities/class-fs-subscription.php b/includes/entities/class-fs-subscription.php index 3556fbd30..668261db4 100755 --- a/includes/entities/class-fs-subscription.php +++ b/includes/entities/class-fs-subscription.php @@ -30,34 +30,10 @@ class FS_Subscription extends FS_Entity { * @var number */ public $license_id; - /** - * @var float - */ - public $total_gross; - /** - * @var float - */ - public $amount_per_cycle; /** * @var int # of months */ public $billing_cycle; - /** - * @var float - */ - public $outstanding_balance; - /** - * @var int - */ - public $failed_payments; - /** - * @var string - */ - public $gateway; - /** - * @var string - */ - public $external_id; /** * @var string|null */ @@ -72,14 +48,6 @@ class FS_Subscription extends FS_Entity { * @var string|null Datetime of the cancellation. */ public $canceled_at; - /** - * @var string|null - */ - public $vat_id; - /** - * @var string Two characters country code - */ - public $country_code; #endregion Properties diff --git a/includes/entities/class-fs-user.php b/includes/entities/class-fs-user.php index a62cfe14a..34f8b4f6b 100755 --- a/includes/entities/class-fs-user.php +++ b/includes/entities/class-fs-user.php @@ -30,14 +30,6 @@ class FS_User extends FS_Scope_Entity { * @var bool */ public $is_verified; - /** - * @var string|null - */ - public $customer_id; - /** - * @var float - */ - public $gross; #endregion Properties From c44af0c13a4e22e20a2504d417e8995834dc6b4f Mon Sep 17 00:00:00 2001 From: Vova Feldman Date: Sun, 11 Dec 2022 18:47:52 +0200 Subject: [PATCH 2/2] [entity-serialization] Serialize entities using JSON while skipping `null` properties to save on storage/RAM. --- includes/entities/class-fs-entity.php | 51 +++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/includes/entities/class-fs-entity.php b/includes/entities/class-fs-entity.php index ce281f45d..df1c1d601 100755 --- a/includes/entities/class-fs-entity.php +++ b/includes/entities/class-fs-entity.php @@ -24,7 +24,7 @@ function fs_get_object_public_vars( $object ) { return get_object_vars( $object ); } - class FS_Entity { + class FS_Entity implements Serializable { /** * @var number */ @@ -156,4 +156,51 @@ static function is_valid_id($id){ public static function get_class_name() { return get_called_class(); } - } \ No newline at end of file + + #-------------------------------------------------------------------------------- + #region Serializable + #-------------------------------------------------------------------------------- + + /** + * @inheritDoc + */ + public function serialize() { + $entity = fs_get_object_public_vars( $this ); + + $compressed = new stdClass(); + foreach ( $entity as $p => $v ) { + if ( ! is_null( $v ) ) { + $compressed->{$p} = $v; + } + } + + return json_encode( $compressed ); + } + + /** + * @inheritDoc + */ + public function unserialize( $data ) { + if ( is_serialized( $data ) ) { + // Backward compatibility. + return unserialize( $data ); + } + + $class_name = get_called_class(); + $entity = new $class_name(); + + $compressed = json_decode( $data, true ); + + if ( ! empty( $compressed ) ) { + foreach ( $compressed as $p => $v ) { + if ( property_exists( $entity, $p ) ) { + $entity->{$p} = $v; + } + } + } + + return $entity; + } + + #endregion + } \ No newline at end of file