Add a button for recalculating score
[MAILPOET-3525]
This commit is contained in:
@ -67,6 +67,7 @@
|
||||
// this violation has been added by a formed employee and we don't know how that works any more, so ignore
|
||||
"files": [
|
||||
"assets/js/src/settings/pages/advanced/reinstall.tsx",
|
||||
"assets/js/src/settings/pages/advanced/recalculate_subscriber_score.tsx",
|
||||
"assets/js/src/settings/pages/key_activation/key_activation.tsx",
|
||||
"assets/js/src/settings/pages/send_with/other/activate_or_cancel.tsx",
|
||||
"assets/js/src/settings/pages/send_with/send_with_choice.tsx"
|
||||
|
@ -9,6 +9,7 @@ import ShareData from './share_data';
|
||||
import { Libs3rdParty } from './libs_3rd_party';
|
||||
import Captcha from './captcha';
|
||||
import Reinstall from './reinstall';
|
||||
import { RecalculateSubscriberScore } from './recalculate_subscriber_score';
|
||||
import Logging from './logging';
|
||||
import BounceAddress from './bounce_address';
|
||||
|
||||
@ -20,6 +21,7 @@ export default function Advanced() {
|
||||
<Roles />
|
||||
<Tracking />
|
||||
<Transactional />
|
||||
<RecalculateSubscriberScore />
|
||||
<InactiveSubscribers />
|
||||
<ShareData />
|
||||
<Libs3rdParty />
|
||||
|
@ -0,0 +1,36 @@
|
||||
import React from 'react';
|
||||
|
||||
import Button from 'common/button/button';
|
||||
import { t } from 'common/functions';
|
||||
import { GlobalContext } from 'context';
|
||||
import { useAction } from 'settings/store/hooks';
|
||||
import { Label, Inputs } from 'settings/components';
|
||||
|
||||
export function RecalculateSubscriberScore(): JSX.Element {
|
||||
const recalculateSubscribersScore = useAction('recalculateSubscribersScore');
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const { notices } = React.useContext<any>(GlobalContext);
|
||||
const onClick = async (): Promise<void> => {
|
||||
await recalculateSubscribersScore();
|
||||
notices.info(<p>{t('recalculateSubscribersScoreNotice')}</p>, { scroll: true });
|
||||
};
|
||||
return (
|
||||
<>
|
||||
<Label
|
||||
title={t('recalculateSubscribersScoreTitle')}
|
||||
description={t('recalculateSubscribersScoreDescription')}
|
||||
htmlFor=""
|
||||
/>
|
||||
<Inputs>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
variant="light"
|
||||
dimension="small"
|
||||
>
|
||||
{t('recalculateSubscribersScoreNow')}
|
||||
</Button>
|
||||
</Inputs>
|
||||
</>
|
||||
);
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
export * from './settings';
|
||||
export * from './mss_and_premium';
|
||||
export { default as reinstall } from './reinstall';
|
||||
export { recalculateSubscribersScore } from './recalculate_subscribers_score';
|
||||
export { default as sendTestEmail } from './send_test_email';
|
||||
export { default as openWoocommerceCustomizer } from './open_woocommerce_customizer';
|
||||
|
@ -0,0 +1,16 @@
|
||||
import MailPoet from 'mailpoet';
|
||||
|
||||
export function* recalculateSubscribersScore(): Generator<{
|
||||
type: string;
|
||||
endpoint: string;
|
||||
action: string;
|
||||
}> {
|
||||
MailPoet.Modal.loading(true);
|
||||
yield {
|
||||
type: 'CALL_API',
|
||||
endpoint: 'settings',
|
||||
action: 'recalculateSubscribersScore',
|
||||
};
|
||||
MailPoet.Modal.loading(false);
|
||||
return { type: 'SAVE_DONE' };
|
||||
}
|
@ -6,12 +6,17 @@ use MailPoet\API\JSON\Endpoint as APIEndpoint;
|
||||
use MailPoet\API\JSON\Error as APIError;
|
||||
use MailPoet\Config\AccessControl;
|
||||
use MailPoet\Config\ServicesChecker;
|
||||
use MailPoet\Cron\Workers\SubscribersEngagementScore;
|
||||
use MailPoet\Entities\ScheduledTaskEntity;
|
||||
use MailPoet\Mailer\MailerLog;
|
||||
use MailPoet\Services\AuthorizedEmailsController;
|
||||
use MailPoet\Services\Bridge;
|
||||
use MailPoet\Settings\SettingsController;
|
||||
use MailPoet\Statistics\StatisticsOpensRepository;
|
||||
use MailPoet\WooCommerce\TransactionalEmails;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
use MailPoetVendor\Carbon\Carbon;
|
||||
use MailPoetVendor\Doctrine\ORM\EntityManager;
|
||||
|
||||
class Settings extends APIEndpoint {
|
||||
|
||||
@ -30,15 +35,31 @@ class Settings extends APIEndpoint {
|
||||
/** @var ServicesChecker */
|
||||
private $servicesChecker;
|
||||
|
||||
/** @var WPFunctions */
|
||||
private $wp;
|
||||
|
||||
public $permissions = [
|
||||
'global' => AccessControl::PERMISSION_MANAGE_SETTINGS,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var EntityManager
|
||||
*/
|
||||
private $entityManager;
|
||||
|
||||
/**
|
||||
* @var StatisticsOpensRepository
|
||||
*/
|
||||
private $statisticsOpensRepository;
|
||||
|
||||
public function __construct(
|
||||
SettingsController $settings,
|
||||
Bridge $bridge,
|
||||
AuthorizedEmailsController $authorizedEmailsController,
|
||||
TransactionalEmails $wcTransactionalEmails,
|
||||
WPFunctions $wp,
|
||||
EntityManager $entityManager,
|
||||
StatisticsOpensRepository $statisticsOpensRepository,
|
||||
ServicesChecker $servicesChecker
|
||||
) {
|
||||
$this->settings = $settings;
|
||||
@ -46,6 +67,9 @@ class Settings extends APIEndpoint {
|
||||
$this->authorizedEmailsController = $authorizedEmailsController;
|
||||
$this->wcTransactionalEmails = $wcTransactionalEmails;
|
||||
$this->servicesChecker = $servicesChecker;
|
||||
$this->wp = $wp;
|
||||
$this->entityManager = $entityManager;
|
||||
$this->statisticsOpensRepository = $statisticsOpensRepository;
|
||||
}
|
||||
|
||||
public function get() {
|
||||
@ -81,6 +105,17 @@ class Settings extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
public function recalculateSubscribersScore() {
|
||||
$this->statisticsOpensRepository->resetSubscribersScoreCalculation();
|
||||
$task = new ScheduledTaskEntity();
|
||||
$task->setType(SubscribersEngagementScore::TASK_TYPE);
|
||||
$task->setScheduledAt(Carbon::createFromTimestamp($this->wp->currentTime('timestamp')));
|
||||
$task->setStatus(ScheduledTaskEntity::STATUS_SCHEDULED);
|
||||
$this->entityManager->persist($task);
|
||||
$this->entityManager->flush();
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
public function setAuthorizedFromAddress($data = []) {
|
||||
$address = $data['address'] ?? null;
|
||||
if (!$address) {
|
||||
|
@ -47,4 +47,11 @@ class StatisticsOpensRepository extends Repository {
|
||||
$subscriber->setEngagementScore($score);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
public function resetSubscribersScoreCalculation() {
|
||||
$this->entityManager->createQueryBuilder()->update(SubscriberEntity::class, 's')
|
||||
->set('s.engagementScoreUpdatedAt', ':verified')
|
||||
->setParameter('verified', null)
|
||||
->getQuery()->execute();
|
||||
}
|
||||
}
|
||||
|
@ -150,6 +150,10 @@
|
||||
'yourReCaptchaSecret': __('Your reCAPTCHA Secret Key'),
|
||||
'fillReCaptchaKeys': __('Please fill the reCAPTCHA keys.'),
|
||||
'disable': __('Disable'),
|
||||
'recalculateSubscribersScoreTitle': __('Recalculate Subscriber Scores'),
|
||||
'recalculateSubscribersScoreDescription': __('MailPoet will recalculate subscriber engagement scores for all subscribers. This may take some time to complete.'),
|
||||
'recalculateSubscribersScoreNow': __('Update now…'),
|
||||
'recalculateSubscribersScoreNotice': __('Subscriber score recalculation has been scheduled and will start soon. It may take some time to complete.'),
|
||||
'reinstallTitle': __('Reinstall from scratch'),
|
||||
'reinstallDescription': __('Want to start from the beginning? This will completely delete MailPoet and reinstall it from scratch. Remember: you will lose all of your data!'),
|
||||
'reinstallNow': __('Reinstall now...'),
|
||||
|
Reference in New Issue
Block a user