Add resend action
This commit is contained in:
committed by
M. Shull
parent
e046e84332
commit
1cd0b0696a
@ -96,6 +96,20 @@ StatsLink.propTypes = {
|
||||
};
|
||||
|
||||
const ListingItem = ({error, failed, taskId, processed, email, subscriberId, lastName, firstName}) => {
|
||||
const resend = () => {
|
||||
MailPoet.Ajax.post({
|
||||
api_version: window.mailpoet_api_version,
|
||||
endpoint: 'sending_task_subscribers',
|
||||
action: 'resend',
|
||||
data: {taskId, subscriberId},
|
||||
})
|
||||
.done(res => window.mailpoet_listing.forceUpdate())
|
||||
.fail((res) => MailPoet.Notice.error(
|
||||
res.errors.map(error => error.message),
|
||||
{ scroll: true }
|
||||
));
|
||||
}
|
||||
|
||||
const rowClasses = classNames(
|
||||
'manage-column',
|
||||
'column-primary',
|
||||
@ -104,7 +118,19 @@ const ListingItem = ({error, failed, taskId, processed, email, subscriberId, las
|
||||
let status = MailPoet.I18n.t('unprocessed');
|
||||
if (processed === '1') {
|
||||
if (failed === '1') {
|
||||
status = MailPoet.I18n.t('failed');
|
||||
status = (
|
||||
<span>
|
||||
{MailPoet.I18n.t('failed')}
|
||||
<br/>
|
||||
<a
|
||||
className="button"
|
||||
href="javascript:;"
|
||||
onClick={resend}
|
||||
>
|
||||
{MailPoet.I18n.t('resend')}
|
||||
</a>
|
||||
</span>
|
||||
);
|
||||
} else {
|
||||
status = MailPoet.I18n.t('sent');
|
||||
}
|
||||
@ -115,7 +141,7 @@ const ListingItem = ({error, failed, taskId, processed, email, subscriberId, las
|
||||
<strong>
|
||||
<a
|
||||
className="row-title"
|
||||
href={`admin.php?page=mailpoet-subscribers#/edit/1`}
|
||||
href={`admin.php?page=mailpoet-subscribers#/edit/${subscriberId}`}
|
||||
>
|
||||
{ email }
|
||||
</a>
|
||||
|
@ -4,21 +4,22 @@ namespace MailPoet\API\JSON\v1;
|
||||
|
||||
use MailPoet\Listing;
|
||||
use MailPoet\Cron\CronHelper;
|
||||
use MailPoet\Config\AccessControl;
|
||||
use MailPoet\Models\ScheduledTask;
|
||||
use MailPoet\Models\Newsletter;
|
||||
use MailPoet\Models\SendingQueue;
|
||||
use MailPoet\Models\ScheduledTask;
|
||||
use MailPoet\Config\AccessControl;
|
||||
use MailPoet\API\JSON\Error as APIError;
|
||||
use MailPoet\Settings\SettingsController;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
use MailPoet\Tasks\Sending as SendingTask;
|
||||
use MailPoet\Models\ScheduledTaskSubscriber;
|
||||
use MailPoet\API\JSON\Endpoint as APIEndpoint;
|
||||
|
||||
if (!defined('ABSPATH')) exit;
|
||||
|
||||
class SendingTaskSubscribers extends APIEndpoint {
|
||||
public $permissions = array(
|
||||
public $permissions = [
|
||||
'global' => AccessControl::PERMISSION_MANAGE_EMAILS
|
||||
);
|
||||
];
|
||||
|
||||
/** @var Listing\Handler */
|
||||
private $listing_handler;
|
||||
@ -29,7 +30,7 @@ class SendingTaskSubscribers extends APIEndpoint {
|
||||
/** @var WPFunctions */
|
||||
private $wp;
|
||||
|
||||
public function __construct(
|
||||
function __construct(
|
||||
Listing\Handler $listing_handler,
|
||||
SettingsController $settings,
|
||||
WPFunctions $wp
|
||||
@ -39,15 +40,15 @@ class SendingTaskSubscribers extends APIEndpoint {
|
||||
$this->wp = $wp;
|
||||
}
|
||||
|
||||
public function listing($data = array()) {
|
||||
function listing($data = []) {
|
||||
$newsletter_id = !empty($data['params']['id']) ? (int)$data['params']['id'] : false;
|
||||
$tasks_ids = SendingQueue::select('task_id')
|
||||
->where('newsletter_id', $newsletter_id)
|
||||
->findArray();
|
||||
if (empty($tasks_ids)) {
|
||||
return $this->errorResponse(array(
|
||||
return $this->errorResponse([
|
||||
APIError::NOT_FOUND => __('This newsletter is not being sent to any subcriber yet.', 'mailpoet')
|
||||
));
|
||||
]);
|
||||
}
|
||||
$data['params']['task_ids'] = array_map(function($item) {
|
||||
return $item['task_id'];
|
||||
@ -59,7 +60,7 @@ class SendingTaskSubscribers extends APIEndpoint {
|
||||
$items[] = $item->asArray();
|
||||
}
|
||||
|
||||
return $this->successResponse($items, array(
|
||||
return $this->successResponse($items, [
|
||||
'count' => $listing_data['count'],
|
||||
'filters' => $listing_data['filters'],
|
||||
'groups' => $listing_data['groups'],
|
||||
@ -67,6 +68,35 @@ class SendingTaskSubscribers extends APIEndpoint {
|
||||
'mta_method' => $this->settings->get('mta.method'),
|
||||
'cron_accessible' => CronHelper::isDaemonAccessible(),
|
||||
'current_time' => $this->wp->currentTime('mysql')
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
function resend($data = []) {
|
||||
$task_id = !empty($data['taskId']) ? (int)$data['taskId'] : false;
|
||||
$subscriber_id = !empty($data['subscriberId']) ? (int)$data['subscriberId'] : false;
|
||||
$task_subscriber = ScheduledTaskSubscriber::where('task_id', $task_id)
|
||||
->where('subscriber_id', $subscriber_id)
|
||||
->findOne();
|
||||
$task = ScheduledTask::findOne($task_id);
|
||||
$sending_queue = SendingQueue::where('task_id', $task_id)->findOne();
|
||||
if (!$task || !$task_subscriber || !$sending_queue || $task_subscriber->failed !== '1') {
|
||||
return $this->errorResponse([
|
||||
APIError::NOT_FOUND => __('Failed sending task not found!', 'mailpoet')
|
||||
]);
|
||||
}
|
||||
$newsletter = Newsletter::findOne($sending_queue->newsletter_id);
|
||||
|
||||
$task_subscriber->error = '';
|
||||
$task_subscriber->failed = 0;
|
||||
$task_subscriber->processed = 0;
|
||||
$task_subscriber->save();
|
||||
|
||||
$task->status = null;
|
||||
$task->save();
|
||||
|
||||
$newsletter->status = Newsletter::STATUS_SENDING;
|
||||
$newsletter->save();
|
||||
|
||||
return $this->successResponse([]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user