Apply new limit to new users

I refactored the SubscribersFeature class so that it's easily
unit tested. Computing the subscribers count in the constructor
is better then computing it on every call to check().

[MAILPOET-2394]
This commit is contained in:
Amine Ben hammou
2019-11-26 00:30:48 +01:00
committed by Jack Kitterhing
parent 53e0934a87
commit 042557aafa
4 changed files with 75 additions and 47 deletions

View File

@ -3,18 +3,32 @@
namespace MailPoet\Util\License\Features;
use MailPoet\Models\Subscriber as SubscriberModel;
use MailPoet\Settings\SettingsController;
use MailPoet\Util\License\License;
class Subscribers {
public $license;
const SUBSCRIBERS_LIMIT = 2000;
const SUBSCRIBERS_OLD_LIMIT = 2000;
const SUBSCRIBERS_NEW_LIMIT = 1000;
const NEW_LIMIT_DATE = '2019-11-00';
function __construct($license = false) {
private $license;
/** @var int */
private $installation_time;
/** @var int */
private $subscribers_count;
function __construct(SettingsController $settings, $license = false) {
$this->license = ($license) ? $license : License::getLicense();
$this->installation_time = strtotime($settings->get('installed_at'));
$this->subscribers_count = SubscriberModel::getTotalSubscribers();
}
function check($subscribers_limit = self::SUBSCRIBERS_LIMIT) {
function check() {
if ($this->license) return false;
return SubscriberModel::getTotalSubscribers() > $subscribers_limit;
$old_user = $this->installation_time < strtotime(self::NEW_LIMIT_DATE);
$subscribers_limit = $old_user ? self::SUBSCRIBERS_OLD_LIMIT : self::SUBSCRIBERS_NEW_LIMIT;
return $this->subscribers_count > $subscribers_limit;
}
}