Fix phpstan level 6
[MAILPOET-1969]
This commit is contained in:
@ -68,7 +68,7 @@ jobs:
|
|||||||
name: "Set up environment"
|
name: "Set up environment"
|
||||||
command: |
|
command: |
|
||||||
source ./.circleci/setup.bash && setup php7
|
source ./.circleci/setup.bash && setup php7
|
||||||
wget https://github.com/phpstan/phpstan/releases/download/0.11.4/phpstan.phar
|
wget https://github.com/phpstan/phpstan/releases/download/0.11.5/phpstan.phar
|
||||||
- run:
|
- run:
|
||||||
name: "Static analysis"
|
name: "Static analysis"
|
||||||
command: ./do qa:phpstan
|
command: ./do qa:phpstan
|
||||||
|
@ -27,14 +27,14 @@ class CustomFields extends APIEndpoint {
|
|||||||
function delete($data = array()) {
|
function delete($data = array()) {
|
||||||
$id = (isset($data['id']) ? (int)$data['id'] : null);
|
$id = (isset($data['id']) ? (int)$data['id'] : null);
|
||||||
$custom_field = CustomField::findOne($id);
|
$custom_field = CustomField::findOne($id);
|
||||||
if ($custom_field === false) {
|
if ($custom_field instanceof CustomField) {
|
||||||
return $this->errorResponse(array(
|
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This custom field does not exist.', 'mailpoet')
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
$custom_field->delete();
|
$custom_field->delete();
|
||||||
|
|
||||||
return $this->successResponse($custom_field->asArray());
|
return $this->successResponse($custom_field->asArray());
|
||||||
|
} else {
|
||||||
|
return $this->errorResponse(array(
|
||||||
|
APIError::NOT_FOUND => WPFunctions::get()->__('This custom field does not exist.', 'mailpoet')
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,22 +44,20 @@ class CustomFields extends APIEndpoint {
|
|||||||
|
|
||||||
if (!empty($errors)) {
|
if (!empty($errors)) {
|
||||||
return $this->badRequest($errors);
|
return $this->badRequest($errors);
|
||||||
} else {
|
|
||||||
return $this->successResponse(
|
|
||||||
CustomField::findOne($custom_field->id)->asArray()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
$custom_field = CustomField::findOne($custom_field->id);
|
||||||
|
if(!$custom_field instanceof CustomField) return $this->errorResponse();
|
||||||
|
return $this->successResponse($custom_field->asArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
function get($data = array()) {
|
function get($data = array()) {
|
||||||
$id = (isset($data['id']) ? (int)$data['id'] : null);
|
$id = (isset($data['id']) ? (int)$data['id'] : null);
|
||||||
$custom_field = CustomField::findOne($id);
|
$custom_field = CustomField::findOne($id);
|
||||||
if ($custom_field === false) {
|
if ($custom_field instanceof CustomField) {
|
||||||
return $this->errorResponse(array(
|
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This custom field does not exist.', 'mailpoet')
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
return $this->successResponse($custom_field->asArray());
|
return $this->successResponse($custom_field->asArray());
|
||||||
}
|
}
|
||||||
|
return $this->errorResponse(array(
|
||||||
|
APIError::NOT_FOUND => WPFunctions::get()->__('This custom field does not exist.', 'mailpoet')
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,13 +37,12 @@ class Forms extends APIEndpoint {
|
|||||||
function get($data = array()) {
|
function get($data = array()) {
|
||||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||||
$form = Form::findOne($id);
|
$form = Form::findOne($id);
|
||||||
if ($form === false) {
|
if ($form instanceof Form) {
|
||||||
return $this->errorResponse(array(
|
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This form does not exist.', 'mailpoet')
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
return $this->successResponse($form->asArray());
|
return $this->successResponse($form->asArray());
|
||||||
}
|
}
|
||||||
|
return $this->errorResponse(array(
|
||||||
|
APIError::NOT_FOUND => WPFunctions::get()->__('This form does not exist.', 'mailpoet')
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
function listing($data = array()) {
|
function listing($data = array()) {
|
||||||
@ -111,13 +110,12 @@ class Forms extends APIEndpoint {
|
|||||||
$form = Form::createOrUpdate($data);
|
$form = Form::createOrUpdate($data);
|
||||||
$errors = $form->getErrors();
|
$errors = $form->getErrors();
|
||||||
|
|
||||||
if (!empty($errors)) {
|
if (empty($errors)) {
|
||||||
return $this->badRequest($errors);
|
$form = Form::findOne($form->id);
|
||||||
} else {
|
if(!$form instanceof Form) return $this->errorResponse();
|
||||||
return $this->successResponse(
|
return $this->successResponse($form->asArray());
|
||||||
Form::findOne($form->id)->asArray()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
return $this->badRequest($errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
function previewEditor($data = array()) {
|
function previewEditor($data = array()) {
|
||||||
@ -139,19 +137,16 @@ class Forms extends APIEndpoint {
|
|||||||
function exportsEditor($data = array()) {
|
function exportsEditor($data = array()) {
|
||||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||||
$form = Form::findOne($id);
|
$form = Form::findOne($id);
|
||||||
if ($form === false) {
|
if ($form instanceof Form) {
|
||||||
return $this->errorResponse(array(
|
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This form does not exist.', 'mailpoet')
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
$exports = Util\Export::getAll($form->asArray());
|
$exports = Util\Export::getAll($form->asArray());
|
||||||
return $this->successResponse($exports);
|
return $this->successResponse($exports);
|
||||||
}
|
}
|
||||||
|
return $this->errorResponse(array(
|
||||||
|
APIError::NOT_FOUND => WPFunctions::get()->__('This form does not exist.', 'mailpoet')
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveEditor($data = array()) {
|
function saveEditor($data = array()) {
|
||||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
|
||||||
|
|
||||||
$form_id = (isset($data['id']) ? (int)$data['id'] : 0);
|
$form_id = (isset($data['id']) ? (int)$data['id'] : 0);
|
||||||
$name = (isset($data['name']) ? $data['name'] : WPFunctions::get()->__('New form', 'mailpoet'));
|
$name = (isset($data['name']) ? $data['name'] : WPFunctions::get()->__('New form', 'mailpoet'));
|
||||||
$body = (isset($data['body']) ? $data['body'] : array());
|
$body = (isset($data['body']) ? $data['body'] : array());
|
||||||
@ -211,56 +206,62 @@ class Forms extends APIEndpoint {
|
|||||||
|
|
||||||
if (!empty($errors)) {
|
if (!empty($errors)) {
|
||||||
return $this->badRequest($errors);
|
return $this->badRequest($errors);
|
||||||
} else {
|
|
||||||
return $this->successResponse(
|
|
||||||
Form::findOne($form->id)->asArray(),
|
|
||||||
array('is_widget' => $is_widget)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
$form = Form::findOne($form->id);
|
||||||
|
if(!$form instanceof Form) return $this->errorResponse();
|
||||||
|
return $this->successResponse(
|
||||||
|
$form->asArray(),
|
||||||
|
array('is_widget' => $is_widget)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function restore($data = array()) {
|
function restore($data = array()) {
|
||||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||||
$form = Form::findOne($id);
|
$form = Form::findOne($id);
|
||||||
if ($form === false) {
|
if ($form instanceof Form) {
|
||||||
|
$form->restore();
|
||||||
|
$form = Form::findOne($form->id);
|
||||||
|
if(!$form instanceof Form) return $this->errorResponse();
|
||||||
|
return $this->successResponse(
|
||||||
|
$form->asArray(),
|
||||||
|
array('count' => 1)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
return $this->errorResponse(array(
|
return $this->errorResponse(array(
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This form does not exist.', 'mailpoet')
|
APIError::NOT_FOUND => WPFunctions::get()->__('This form does not exist.', 'mailpoet')
|
||||||
));
|
));
|
||||||
} else {
|
|
||||||
$form->restore();
|
|
||||||
return $this->successResponse(
|
|
||||||
Form::findOne($form->id)->asArray(),
|
|
||||||
array('count' => 1)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function trash($data = array()) {
|
function trash($data = array()) {
|
||||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||||
$form = Form::findOne($id);
|
$form = Form::findOne($id);
|
||||||
if ($form === false) {
|
if ($form instanceof Form) {
|
||||||
|
$form->trash();
|
||||||
|
$form = Form::findOne($form->id);
|
||||||
|
if(!$form instanceof Form) return $this->errorResponse();
|
||||||
|
return $this->successResponse(
|
||||||
|
$form->asArray(),
|
||||||
|
array('count' => 1)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
return $this->errorResponse(array(
|
return $this->errorResponse(array(
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This form does not exist.', 'mailpoet')
|
APIError::NOT_FOUND => WPFunctions::get()->__('This form does not exist.', 'mailpoet')
|
||||||
));
|
));
|
||||||
} else {
|
|
||||||
$form->trash();
|
|
||||||
return $this->successResponse(
|
|
||||||
Form::findOne($form->id)->asArray(),
|
|
||||||
array('count' => 1)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete($data = array()) {
|
function delete($data = array()) {
|
||||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||||
$form = Form::findOne($id);
|
$form = Form::findOne($id);
|
||||||
if ($form === false) {
|
if ($form instanceof Form) {
|
||||||
|
$form->delete();
|
||||||
|
|
||||||
|
return $this->successResponse(null, array('count' => 1));
|
||||||
|
} else {
|
||||||
return $this->errorResponse(array(
|
return $this->errorResponse(array(
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This form does not exist.', 'mailpoet')
|
APIError::NOT_FOUND => WPFunctions::get()->__('This form does not exist.', 'mailpoet')
|
||||||
));
|
));
|
||||||
} else {
|
|
||||||
$form->delete();
|
|
||||||
return $this->successResponse(null, array('count' => 1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,11 +269,7 @@ class Forms extends APIEndpoint {
|
|||||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||||
$form = Form::findOne($id);
|
$form = Form::findOne($id);
|
||||||
|
|
||||||
if ($form === false) {
|
if ($form instanceof Form) {
|
||||||
return $this->errorResponse(array(
|
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This form does not exist.', 'mailpoet')
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'name' => sprintf(__('Copy of %s', 'mailpoet'), $form->name)
|
'name' => sprintf(__('Copy of %s', 'mailpoet'), $form->name)
|
||||||
);
|
);
|
||||||
@ -282,11 +279,17 @@ class Forms extends APIEndpoint {
|
|||||||
if (!empty($errors)) {
|
if (!empty($errors)) {
|
||||||
return $this->errorResponse($errors);
|
return $this->errorResponse($errors);
|
||||||
} else {
|
} else {
|
||||||
|
$duplicate = Form::findOne($duplicate->id);
|
||||||
|
if(!$duplicate instanceof Form) return $this->errorResponse();
|
||||||
return $this->successResponse(
|
return $this->successResponse(
|
||||||
Form::findOne($duplicate->id)->asArray(),
|
$duplicate->asArray(),
|
||||||
array('count' => 1)
|
array('count' => 1)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return $this->errorResponse(array(
|
||||||
|
APIError::NOT_FOUND => WPFunctions::get()->__('This form does not exist.', 'mailpoet')
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,9 +45,9 @@ class ImportExport extends APIEndpoint {
|
|||||||
if (!empty($errors)) {
|
if (!empty($errors)) {
|
||||||
return $this->errorResponse($errors);
|
return $this->errorResponse($errors);
|
||||||
} else {
|
} else {
|
||||||
return $this->successResponse(
|
$segment = Segment::findOne($segment->id);
|
||||||
Segment::findOne($segment->id)->asArray()
|
if(!$segment instanceof Segment) return $this->errorResponse();
|
||||||
);
|
return $this->successResponse($segment->asArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,14 +18,14 @@ class NewsletterTemplates extends APIEndpoint {
|
|||||||
function get($data = array()) {
|
function get($data = array()) {
|
||||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||||
$template = NewsletterTemplate::findOne($id);
|
$template = NewsletterTemplate::findOne($id);
|
||||||
if ($template === false) {
|
if ($template instanceof NewsletterTemplate) {
|
||||||
return $this->errorResponse(array(
|
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This template does not exist.', 'mailpoet')
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
return $this->successResponse(
|
return $this->successResponse(
|
||||||
$template->asArray()
|
$template->asArray()
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
return $this->errorResponse(array(
|
||||||
|
APIError::NOT_FOUND => WPFunctions::get()->__('This template does not exist.', 'mailpoet')
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ class NewsletterTemplates extends APIEndpoint {
|
|||||||
ignore_user_abort(true);
|
ignore_user_abort(true);
|
||||||
if (!empty($data['newsletter_id'])) {
|
if (!empty($data['newsletter_id'])) {
|
||||||
$template = NewsletterTemplate::whereEqual('newsletter_id', $data['newsletter_id'])->findOne();
|
$template = NewsletterTemplate::whereEqual('newsletter_id', $data['newsletter_id'])->findOne();
|
||||||
if (!empty($template)) {
|
if ($template instanceof NewsletterTemplate) {
|
||||||
$data['id'] = $template->id;
|
$data['id'] = $template->id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,8 +60,10 @@ class NewsletterTemplates extends APIEndpoint {
|
|||||||
if (!empty($errors)) {
|
if (!empty($errors)) {
|
||||||
return $this->errorResponse($errors);
|
return $this->errorResponse($errors);
|
||||||
} else {
|
} else {
|
||||||
|
$template = NewsletterTemplate::findOne($template->id);
|
||||||
|
if(!$template instanceof NewsletterTemplate) return $this->errorResponse();
|
||||||
return $this->successResponse(
|
return $this->successResponse(
|
||||||
NewsletterTemplate::findOne($template->id)->asArray()
|
$template->asArray()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,13 +71,13 @@ class NewsletterTemplates extends APIEndpoint {
|
|||||||
function delete($data = array()) {
|
function delete($data = array()) {
|
||||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||||
$template = NewsletterTemplate::findOne($id);
|
$template = NewsletterTemplate::findOne($id);
|
||||||
if ($template === false) {
|
if ($template instanceof NewsletterTemplate) {
|
||||||
|
$template->delete();
|
||||||
|
return $this->successResponse(null, array('count' => 1));
|
||||||
|
} else {
|
||||||
return $this->errorResponse(array(
|
return $this->errorResponse(array(
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This template does not exist.', 'mailpoet')
|
APIError::NOT_FOUND => WPFunctions::get()->__('This template does not exist.', 'mailpoet')
|
||||||
));
|
));
|
||||||
} else {
|
|
||||||
$template->delete();
|
|
||||||
return $this->successResponse(null, array('count' => 1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,11 +58,7 @@ class Newsletters extends APIEndpoint {
|
|||||||
function get($data = array()) {
|
function get($data = array()) {
|
||||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||||
$newsletter = Newsletter::findOne($id);
|
$newsletter = Newsletter::findOne($id);
|
||||||
if ($newsletter === false) {
|
if ($newsletter instanceof Newsletter) {
|
||||||
return $this->errorResponse(array(
|
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
$newsletter = $newsletter
|
$newsletter = $newsletter
|
||||||
->withSegments()
|
->withSegments()
|
||||||
->withOptions()
|
->withOptions()
|
||||||
@ -76,6 +72,10 @@ class Newsletters extends APIEndpoint {
|
|||||||
|
|
||||||
$newsletter = $this->wp->applyFilters('mailpoet_api_newsletters_get_after', $newsletter->asArray());
|
$newsletter = $this->wp->applyFilters('mailpoet_api_newsletters_get_after', $newsletter->asArray());
|
||||||
return $this->successResponse($newsletter, ['preview_url' => $preview_url]);
|
return $this->successResponse($newsletter, ['preview_url' => $preview_url]);
|
||||||
|
} else {
|
||||||
|
return $this->errorResponse(array(
|
||||||
|
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ class Newsletters extends APIEndpoint {
|
|||||||
|
|
||||||
if (!empty($data['template_id'])) {
|
if (!empty($data['template_id'])) {
|
||||||
$template = NewsletterTemplate::whereEqual('id', $data['template_id'])->findOne();
|
$template = NewsletterTemplate::whereEqual('id', $data['template_id'])->findOne();
|
||||||
if (!empty($template)) {
|
if ($template instanceof NewsletterTemplate) {
|
||||||
$template = $template->asArray();
|
$template = $template->asArray();
|
||||||
$data['body'] = $template['body'];
|
$data['body'] = $template['body'];
|
||||||
}
|
}
|
||||||
@ -110,6 +110,7 @@ class Newsletters extends APIEndpoint {
|
|||||||
// Re-fetch newsletter to sync changes made by DB
|
// Re-fetch newsletter to sync changes made by DB
|
||||||
// updated_at column use CURRENT_TIMESTAMP for update and this change is not updated automatically by ORM
|
// updated_at column use CURRENT_TIMESTAMP for update and this change is not updated automatically by ORM
|
||||||
$newsletter = Newsletter::findOne($newsletter->id);
|
$newsletter = Newsletter::findOne($newsletter->id);
|
||||||
|
if(!$newsletter instanceof Newsletter) return $this->errorResponse();
|
||||||
|
|
||||||
if (!empty($segments)) {
|
if (!empty($segments)) {
|
||||||
NewsletterSegment::where('newsletter_id', $newsletter->id)
|
NewsletterSegment::where('newsletter_id', $newsletter->id)
|
||||||
@ -146,6 +147,7 @@ class Newsletters extends APIEndpoint {
|
|||||||
}
|
}
|
||||||
// reload newsletter with updated options
|
// reload newsletter with updated options
|
||||||
$newsletter = Newsletter::filter('filterWithOptions', $newsletter->type)->findOne($newsletter->id);
|
$newsletter = Newsletter::filter('filterWithOptions', $newsletter->type)->findOne($newsletter->id);
|
||||||
|
if(!$newsletter instanceof Newsletter) return $this->errorResponse();
|
||||||
// if this is a post notification, process newsletter options and update its schedule
|
// if this is a post notification, process newsletter options and update its schedule
|
||||||
if ($newsletter->type === Newsletter::TYPE_NOTIFICATION) {
|
if ($newsletter->type === Newsletter::TYPE_NOTIFICATION) {
|
||||||
// generate the new schedule from options and get the new "next run" date
|
// generate the new schedule from options and get the new "next run" date
|
||||||
@ -226,54 +228,62 @@ class Newsletters extends APIEndpoint {
|
|||||||
Scheduler::createPostNotificationSendingTask($newsletter);
|
Scheduler::createPostNotificationSendingTask($newsletter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$newsletter = Newsletter::findOne($newsletter->id);
|
||||||
|
if(!$newsletter instanceof Newsletter) return $this->errorResponse();
|
||||||
return $this->successResponse(
|
return $this->successResponse(
|
||||||
Newsletter::findOne($newsletter->id)->asArray()
|
$newsletter->asArray()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function restore($data = array()) {
|
function restore($data = array()) {
|
||||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||||
$newsletter = Newsletter::findOne($id);
|
$newsletter = Newsletter::findOne($id);
|
||||||
if ($newsletter === false) {
|
if ($newsletter instanceof Newsletter) {
|
||||||
|
$newsletter->restore();
|
||||||
|
|
||||||
|
$newsletter = Newsletter::findOne($newsletter->id);
|
||||||
|
if(!$newsletter instanceof Newsletter) return $this->errorResponse();
|
||||||
|
|
||||||
|
return $this->successResponse(
|
||||||
|
$newsletter->asArray(),
|
||||||
|
array('count' => 1)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
return $this->errorResponse(array(
|
return $this->errorResponse(array(
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
||||||
));
|
));
|
||||||
} else {
|
|
||||||
$newsletter->restore();
|
|
||||||
return $this->successResponse(
|
|
||||||
Newsletter::findOne($newsletter->id)->asArray(),
|
|
||||||
array('count' => 1)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function trash($data = array()) {
|
function trash($data = array()) {
|
||||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||||
$newsletter = Newsletter::findOne($id);
|
$newsletter = Newsletter::findOne($id);
|
||||||
if ($newsletter === false) {
|
if ($newsletter instanceof Newsletter) {
|
||||||
|
$newsletter->trash();
|
||||||
|
|
||||||
|
$newsletter = Newsletter::findOne($newsletter->id);
|
||||||
|
if(!$newsletter instanceof Newsletter) return $this->errorResponse();
|
||||||
|
return $this->successResponse(
|
||||||
|
$newsletter->asArray(),
|
||||||
|
array('count' => 1)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
return $this->errorResponse(array(
|
return $this->errorResponse(array(
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
||||||
));
|
));
|
||||||
} else {
|
|
||||||
$newsletter->trash();
|
|
||||||
return $this->successResponse(
|
|
||||||
Newsletter::findOne($newsletter->id)->asArray(),
|
|
||||||
array('count' => 1)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete($data = array()) {
|
function delete($data = array()) {
|
||||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||||
$newsletter = Newsletter::findOne($id);
|
$newsletter = Newsletter::findOne($id);
|
||||||
if ($newsletter === false) {
|
if ($newsletter instanceof Newsletter) {
|
||||||
|
$newsletter->delete();
|
||||||
|
return $this->successResponse(null, array('count' => 1));
|
||||||
|
} else {
|
||||||
return $this->errorResponse(array(
|
return $this->errorResponse(array(
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
||||||
));
|
));
|
||||||
} else {
|
|
||||||
$newsletter->delete();
|
|
||||||
return $this->successResponse(null, array('count' => 1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,11 +291,7 @@ class Newsletters extends APIEndpoint {
|
|||||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||||
$newsletter = Newsletter::findOne($id);
|
$newsletter = Newsletter::findOne($id);
|
||||||
|
|
||||||
if ($newsletter === false) {
|
if ($newsletter instanceof Newsletter) {
|
||||||
return $this->errorResponse(array(
|
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'subject' => sprintf(__('Copy of %s', 'mailpoet'), $newsletter->subject)
|
'subject' => sprintf(__('Copy of %s', 'mailpoet'), $newsletter->subject)
|
||||||
);
|
);
|
||||||
@ -296,11 +302,17 @@ class Newsletters extends APIEndpoint {
|
|||||||
return $this->errorResponse($errors);
|
return $this->errorResponse($errors);
|
||||||
} else {
|
} else {
|
||||||
$this->wp->doAction('mailpoet_api_newsletters_duplicate_after', $newsletter, $duplicate);
|
$this->wp->doAction('mailpoet_api_newsletters_duplicate_after', $newsletter, $duplicate);
|
||||||
|
$duplicate = Newsletter::findOne($duplicate->id);
|
||||||
|
if(!$duplicate instanceof Newsletter) return $this->errorResponse();
|
||||||
return $this->successResponse(
|
return $this->successResponse(
|
||||||
Newsletter::findOne($duplicate->id)->asArray(),
|
$duplicate->asArray(),
|
||||||
array('count' => 1)
|
array('count' => 1)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return $this->errorResponse(array(
|
||||||
|
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,11 +326,7 @@ class Newsletters extends APIEndpoint {
|
|||||||
$id = (isset($data['id'])) ? (int)$data['id'] : false;
|
$id = (isset($data['id'])) ? (int)$data['id'] : false;
|
||||||
$newsletter = Newsletter::findOne($id);
|
$newsletter = Newsletter::findOne($id);
|
||||||
|
|
||||||
if ($newsletter === false) {
|
if ($newsletter instanceof Newsletter) {
|
||||||
return $this->errorResponse(array(
|
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
$newsletter->body = $data['body'];
|
$newsletter->body = $data['body'];
|
||||||
$newsletter->save();
|
$newsletter->save();
|
||||||
$subscriber = Subscriber::getCurrentWPUser();
|
$subscriber = Subscriber::getCurrentWPUser();
|
||||||
@ -330,10 +338,16 @@ class Newsletters extends APIEndpoint {
|
|||||||
// strip protocol to avoid mix content error
|
// strip protocol to avoid mix content error
|
||||||
$preview_url = preg_replace('{^https?:}i', '', $preview_url);
|
$preview_url = preg_replace('{^https?:}i', '', $preview_url);
|
||||||
|
|
||||||
|
$newsletter = Newsletter::findOne($newsletter->id);
|
||||||
|
if(!$newsletter instanceof Newsletter) return $this->errorResponse();
|
||||||
return $this->successResponse(
|
return $this->successResponse(
|
||||||
Newsletter::findOne($newsletter->id)->asArray(),
|
$newsletter->asArray(),
|
||||||
array('preview_url' => $preview_url)
|
array('preview_url' => $preview_url)
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
return $this->errorResponse(array(
|
||||||
|
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,11 +361,7 @@ class Newsletters extends APIEndpoint {
|
|||||||
$id = (isset($data['id'])) ? (int)$data['id'] : false;
|
$id = (isset($data['id'])) ? (int)$data['id'] : false;
|
||||||
$newsletter = Newsletter::findOne($id);
|
$newsletter = Newsletter::findOne($id);
|
||||||
|
|
||||||
if ($newsletter === false) {
|
if ($newsletter instanceof Newsletter) {
|
||||||
return $this->errorResponse(array(
|
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
$renderer = new Renderer($newsletter, $preview = true);
|
$renderer = new Renderer($newsletter, $preview = true);
|
||||||
$rendered_newsletter = $renderer->render();
|
$rendered_newsletter = $renderer->render();
|
||||||
$divider = '***MailPoet***';
|
$divider = '***MailPoet***';
|
||||||
@ -376,7 +386,7 @@ class Newsletters extends APIEndpoint {
|
|||||||
$rendered_newsletter['subject'],
|
$rendered_newsletter['subject'],
|
||||||
$rendered_newsletter['body']['html'],
|
$rendered_newsletter['body']['html'],
|
||||||
$rendered_newsletter['body']['text']
|
$rendered_newsletter['body']['text']
|
||||||
) = explode($divider, $shortcodes->replace($body));
|
) = explode($divider, $shortcodes->replace($body));
|
||||||
$rendered_newsletter['id'] = $newsletter->id;
|
$rendered_newsletter['id'] = $newsletter->id;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -386,7 +396,7 @@ class Newsletters extends APIEndpoint {
|
|||||||
$mailer = false,
|
$mailer = false,
|
||||||
$sender = false,
|
$sender = false,
|
||||||
$reply_to = false
|
$reply_to = false
|
||||||
);
|
);
|
||||||
$extra_params = array('unsubscribe_url' => WPFunctions::get()->homeUrl());
|
$extra_params = array('unsubscribe_url' => WPFunctions::get()->homeUrl());
|
||||||
$result = $mailer->send($rendered_newsletter, $data['subscriber'], $extra_params);
|
$result = $mailer->send($rendered_newsletter, $data['subscriber'], $extra_params);
|
||||||
|
|
||||||
@ -397,8 +407,11 @@ class Newsletters extends APIEndpoint {
|
|||||||
);
|
);
|
||||||
return $this->errorResponse(array(APIError::BAD_REQUEST => $error));
|
return $this->errorResponse(array(APIError::BAD_REQUEST => $error));
|
||||||
} else {
|
} else {
|
||||||
|
$newsletter = Newsletter::findOne($newsletter->id);
|
||||||
|
if(!$newsletter instanceof Newsletter) return $this->errorResponse();
|
||||||
|
|
||||||
return $this->successResponse(
|
return $this->successResponse(
|
||||||
Newsletter::findOne($id)->asArray()
|
$newsletter->asArray()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -406,6 +419,10 @@ class Newsletters extends APIEndpoint {
|
|||||||
$e->getCode() => $e->getMessage()
|
$e->getCode() => $e->getMessage()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return $this->errorResponse(array(
|
||||||
|
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -494,10 +511,10 @@ class Newsletters extends APIEndpoint {
|
|||||||
// try to load template data
|
// try to load template data
|
||||||
$template_id = (isset($data['template']) ? (int)$data['template'] : false);
|
$template_id = (isset($data['template']) ? (int)$data['template'] : false);
|
||||||
$template = NewsletterTemplate::findOne($template_id);
|
$template = NewsletterTemplate::findOne($template_id);
|
||||||
if ($template === false) {
|
if ($template instanceof NewsletterTemplate) {
|
||||||
$newsletter->body = array();
|
|
||||||
} else {
|
|
||||||
$newsletter->body = $template->body;
|
$newsletter->body = $template->body;
|
||||||
|
} else {
|
||||||
|
$newsletter->body = array();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -533,8 +550,10 @@ class Newsletters extends APIEndpoint {
|
|||||||
Scheduler::processPostNotificationSchedule($newsletter);
|
Scheduler::processPostNotificationSchedule($newsletter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$newsletter = Newsletter::findOne($newsletter->id);
|
||||||
|
if(!$newsletter instanceof Newsletter) return $this->errorResponse();
|
||||||
return $this->successResponse(
|
return $this->successResponse(
|
||||||
Newsletter::findOne($newsletter->id)->asArray()
|
$newsletter->asArray()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,12 +40,12 @@ class Segments extends APIEndpoint {
|
|||||||
function get($data = array()) {
|
function get($data = array()) {
|
||||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||||
$segment = Segment::findOne($id);
|
$segment = Segment::findOne($id);
|
||||||
if ($segment === false) {
|
if ($segment instanceof Segment) {
|
||||||
|
return $this->successResponse($segment->asArray());
|
||||||
|
} else {
|
||||||
return $this->errorResponse(array(
|
return $this->errorResponse(array(
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This list does not exist.', 'mailpoet')
|
APIError::NOT_FOUND => WPFunctions::get()->__('This list does not exist.', 'mailpoet')
|
||||||
));
|
));
|
||||||
} else {
|
|
||||||
return $this->successResponse($segment->asArray());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,8 +77,10 @@ class Segments extends APIEndpoint {
|
|||||||
if (!empty($errors)) {
|
if (!empty($errors)) {
|
||||||
return $this->badRequest($errors);
|
return $this->badRequest($errors);
|
||||||
} else {
|
} else {
|
||||||
|
$segment = Segment::findOne($segment->id);
|
||||||
|
if(!$segment instanceof Segment) return $this->errorResponse();
|
||||||
return $this->successResponse(
|
return $this->successResponse(
|
||||||
Segment::findOne($segment->id)->asArray()
|
$segment->asArray()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -86,45 +88,49 @@ class Segments extends APIEndpoint {
|
|||||||
function restore($data = array()) {
|
function restore($data = array()) {
|
||||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||||
$segment = Segment::findOne($id);
|
$segment = Segment::findOne($id);
|
||||||
if ($segment === false) {
|
if ($segment instanceof Segment) {
|
||||||
|
$segment->restore();
|
||||||
|
$segment = Segment::findOne($segment->id);
|
||||||
|
if(!$segment instanceof Segment) return $this->errorResponse();
|
||||||
|
return $this->successResponse(
|
||||||
|
$segment->asArray(),
|
||||||
|
array('count' => 1)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
return $this->errorResponse(array(
|
return $this->errorResponse(array(
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This list does not exist.', 'mailpoet')
|
APIError::NOT_FOUND => WPFunctions::get()->__('This list does not exist.', 'mailpoet')
|
||||||
));
|
));
|
||||||
} else {
|
|
||||||
$segment->restore();
|
|
||||||
return $this->successResponse(
|
|
||||||
Segment::findOne($segment->id)->asArray(),
|
|
||||||
array('count' => 1)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function trash($data = array()) {
|
function trash($data = array()) {
|
||||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||||
$segment = Segment::findOne($id);
|
$segment = Segment::findOne($id);
|
||||||
if ($segment === false) {
|
if ($segment instanceof Segment) {
|
||||||
|
$segment->trash();
|
||||||
|
$segment = Segment::findOne($segment->id);
|
||||||
|
if(!$segment instanceof Segment) return $this->errorResponse();
|
||||||
|
return $this->successResponse(
|
||||||
|
$segment->asArray(),
|
||||||
|
array('count' => 1)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
return $this->errorResponse(array(
|
return $this->errorResponse(array(
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This list does not exist.', 'mailpoet')
|
APIError::NOT_FOUND => WPFunctions::get()->__('This list does not exist.', 'mailpoet')
|
||||||
));
|
));
|
||||||
} else {
|
|
||||||
$segment->trash();
|
|
||||||
return $this->successResponse(
|
|
||||||
Segment::findOne($segment->id)->asArray(),
|
|
||||||
array('count' => 1)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete($data = array()) {
|
function delete($data = array()) {
|
||||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||||
$segment = Segment::findOne($id);
|
$segment = Segment::findOne($id);
|
||||||
if ($segment === false) {
|
if ($segment instanceof Segment) {
|
||||||
|
$segment->delete();
|
||||||
|
return $this->successResponse(null, array('count' => 1));
|
||||||
|
} else {
|
||||||
return $this->errorResponse(array(
|
return $this->errorResponse(array(
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This list does not exist.', 'mailpoet')
|
APIError::NOT_FOUND => WPFunctions::get()->__('This list does not exist.', 'mailpoet')
|
||||||
));
|
));
|
||||||
} else {
|
|
||||||
$segment->delete();
|
|
||||||
return $this->successResponse(null, array('count' => 1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,11 +138,7 @@ class Segments extends APIEndpoint {
|
|||||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||||
$segment = Segment::findOne($id);
|
$segment = Segment::findOne($id);
|
||||||
|
|
||||||
if ($segment === false) {
|
if ($segment instanceof Segment) {
|
||||||
return $this->errorResponse(array(
|
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This list does not exist.', 'mailpoet')
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'name' => sprintf(__('Copy of %s', 'mailpoet'), $segment->name)
|
'name' => sprintf(__('Copy of %s', 'mailpoet'), $segment->name)
|
||||||
);
|
);
|
||||||
@ -146,11 +148,17 @@ class Segments extends APIEndpoint {
|
|||||||
if (!empty($errors)) {
|
if (!empty($errors)) {
|
||||||
return $this->errorResponse($errors);
|
return $this->errorResponse($errors);
|
||||||
} else {
|
} else {
|
||||||
|
$duplicate = Segment::findOne($duplicate->id);
|
||||||
|
if(!$duplicate instanceof Segment) return $this->errorResponse();
|
||||||
return $this->successResponse(
|
return $this->successResponse(
|
||||||
Segment::findOne($duplicate->id)->asArray(),
|
$duplicate->asArray(),
|
||||||
array('count' => 1)
|
array('count' => 1)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return $this->errorResponse(array(
|
||||||
|
APIError::NOT_FOUND => WPFunctions::get()->__('This list does not exist.', 'mailpoet')
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ class SendingQueue extends APIEndpoint {
|
|||||||
// check that the newsletter exists
|
// check that the newsletter exists
|
||||||
$newsletter = Newsletter::findOneWithOptions($newsletter_id);
|
$newsletter = Newsletter::findOneWithOptions($newsletter_id);
|
||||||
|
|
||||||
if ($newsletter === false) {
|
if (!$newsletter instanceof Newsletter) {
|
||||||
return $this->errorResponse(array(
|
return $this->errorResponse(array(
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
||||||
));
|
));
|
||||||
@ -59,7 +59,7 @@ class SendingQueue extends APIEndpoint {
|
|||||||
->where('queues.newsletter_id', $newsletter->id)
|
->where('queues.newsletter_id', $newsletter->id)
|
||||||
->where('tasks.status', SendingQueueModel::STATUS_SCHEDULED)
|
->where('tasks.status', SendingQueueModel::STATUS_SCHEDULED)
|
||||||
->findOne();
|
->findOne();
|
||||||
if ($scheduled_queue) {
|
if ($scheduled_queue instanceof SendingQueueModel) {
|
||||||
$queue = SendingTask::createFromQueue($scheduled_queue);
|
$queue = SendingTask::createFromQueue($scheduled_queue);
|
||||||
} else {
|
} else {
|
||||||
$queue = SendingTask::create();
|
$queue = SendingTask::create();
|
||||||
@ -108,11 +108,7 @@ class SendingQueue extends APIEndpoint {
|
|||||||
);
|
);
|
||||||
$newsletter = Newsletter::findOne($newsletter_id);
|
$newsletter = Newsletter::findOne($newsletter_id);
|
||||||
|
|
||||||
if ($newsletter === false) {
|
if ($newsletter instanceof Newsletter) {
|
||||||
return $this->errorResponse(array(
|
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
$queue = $newsletter->getQueue();
|
$queue = $newsletter->getQueue();
|
||||||
|
|
||||||
if ($queue === false) {
|
if ($queue === false) {
|
||||||
@ -125,6 +121,10 @@ class SendingQueue extends APIEndpoint {
|
|||||||
$newsletter->getQueue()->asArray()
|
$newsletter->getQueue()->asArray()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return $this->errorResponse(array(
|
||||||
|
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,11 +134,7 @@ class SendingQueue extends APIEndpoint {
|
|||||||
: false
|
: false
|
||||||
);
|
);
|
||||||
$newsletter = Newsletter::findOne($newsletter_id);
|
$newsletter = Newsletter::findOne($newsletter_id);
|
||||||
if ($newsletter === false) {
|
if ($newsletter instanceof Newsletter) {
|
||||||
return $this->errorResponse(array(
|
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
$queue = $newsletter->getQueue();
|
$queue = $newsletter->getQueue();
|
||||||
|
|
||||||
if ($queue === false) {
|
if ($queue === false) {
|
||||||
@ -151,6 +147,10 @@ class SendingQueue extends APIEndpoint {
|
|||||||
$newsletter->getQueue()->asArray()
|
$newsletter->getQueue()->asArray()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return $this->errorResponse(array(
|
||||||
|
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ class Subscribers extends APIEndpoint {
|
|||||||
|
|
||||||
$recaptcha = $this->settings->get('re_captcha');
|
$recaptcha = $this->settings->get('re_captcha');
|
||||||
|
|
||||||
if (!$form) {
|
if (!$form instanceof Form) {
|
||||||
return $this->badRequest(array(
|
return $this->badRequest(array(
|
||||||
APIError::BAD_REQUEST => WPFunctions::get()->__('Please specify a valid form ID.', 'mailpoet')
|
APIError::BAD_REQUEST => WPFunctions::get()->__('Please specify a valid form ID.', 'mailpoet')
|
||||||
));
|
));
|
||||||
@ -266,45 +266,49 @@ class Subscribers extends APIEndpoint {
|
|||||||
function restore($data = array()) {
|
function restore($data = array()) {
|
||||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||||
$subscriber = Subscriber::findOne($id);
|
$subscriber = Subscriber::findOne($id);
|
||||||
if ($subscriber === false) {
|
if ($subscriber instanceof Subscriber) {
|
||||||
|
$subscriber->restore();
|
||||||
|
$subscriber = Subscriber::findOne($subscriber->id);
|
||||||
|
if(!$subscriber instanceof Subscriber) return $this->errorResponse();
|
||||||
|
return $this->successResponse(
|
||||||
|
$subscriber->asArray(),
|
||||||
|
array('count' => 1)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
return $this->errorResponse(array(
|
return $this->errorResponse(array(
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This subscriber does not exist.', 'mailpoet')
|
APIError::NOT_FOUND => WPFunctions::get()->__('This subscriber does not exist.', 'mailpoet')
|
||||||
));
|
));
|
||||||
} else {
|
|
||||||
$subscriber->restore();
|
|
||||||
return $this->successResponse(
|
|
||||||
Subscriber::findOne($subscriber->id)->asArray(),
|
|
||||||
array('count' => 1)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function trash($data = array()) {
|
function trash($data = array()) {
|
||||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||||
$subscriber = Subscriber::findOne($id);
|
$subscriber = Subscriber::findOne($id);
|
||||||
if ($subscriber === false) {
|
if ($subscriber instanceof Subscriber) {
|
||||||
|
$subscriber->trash();
|
||||||
|
$subscriber = Subscriber::findOne($subscriber->id);
|
||||||
|
if(!$subscriber instanceof Subscriber) return $this->errorResponse();
|
||||||
|
return $this->successResponse(
|
||||||
|
$subscriber->asArray(),
|
||||||
|
array('count' => 1)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
return $this->errorResponse(array(
|
return $this->errorResponse(array(
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This subscriber does not exist.', 'mailpoet')
|
APIError::NOT_FOUND => WPFunctions::get()->__('This subscriber does not exist.', 'mailpoet')
|
||||||
));
|
));
|
||||||
} else {
|
|
||||||
$subscriber->trash();
|
|
||||||
return $this->successResponse(
|
|
||||||
Subscriber::findOne($subscriber->id)->asArray(),
|
|
||||||
array('count' => 1)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete($data = array()) {
|
function delete($data = array()) {
|
||||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||||
$subscriber = Subscriber::findOne($id);
|
$subscriber = Subscriber::findOne($id);
|
||||||
if ($subscriber === false) {
|
if ($subscriber instanceof Subscriber) {
|
||||||
|
$subscriber->delete();
|
||||||
|
return $this->successResponse(null, array('count' => 1));
|
||||||
|
} else {
|
||||||
return $this->errorResponse(array(
|
return $this->errorResponse(array(
|
||||||
APIError::NOT_FOUND => WPFunctions::get()->__('This subscriber does not exist.', 'mailpoet')
|
APIError::NOT_FOUND => WPFunctions::get()->__('This subscriber does not exist.', 'mailpoet')
|
||||||
));
|
));
|
||||||
} else {
|
|
||||||
$subscriber->delete();
|
|
||||||
return $this->successResponse(null, array('count' => 1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,6 +268,9 @@ class API {
|
|||||||
|
|
||||||
// reload list to get the saved created|updated|delete dates/other fields
|
// reload list to get the saved created|updated|delete dates/other fields
|
||||||
$new_list = Segment::findOne($new_list->id);
|
$new_list = Segment::findOne($new_list->id);
|
||||||
|
if (!$new_list instanceof Segment) {
|
||||||
|
throw new \Exception(WPFunctions::get()->__('Failed to add list', 'mailpoet'));
|
||||||
|
}
|
||||||
|
|
||||||
return $new_list->asArray();
|
return $new_list->asArray();
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace MailPoet\Config;
|
namespace MailPoet\Config;
|
||||||
use MailPoet\WP\Functions as WPFunctions;
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
use WP_Role;
|
||||||
|
|
||||||
class Capabilities {
|
class Capabilities {
|
||||||
const MEMBERS_CAP_GROUP_NAME = 'mailpoet';
|
const MEMBERS_CAP_GROUP_NAME = 'mailpoet';
|
||||||
@ -35,7 +36,7 @@ class Capabilities {
|
|||||||
if (!isset($role_objects[$role])) {
|
if (!isset($role_objects[$role])) {
|
||||||
$role_objects[$role] = WPFunctions::get()->getRole($role);
|
$role_objects[$role] = WPFunctions::get()->getRole($role);
|
||||||
}
|
}
|
||||||
if (!is_object($role_objects[$role])) continue;
|
if (!$role_objects[$role] instanceof WP_Role) continue;
|
||||||
$role_objects[$role]->add_cap($name);
|
$role_objects[$role]->add_cap($name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,7 +50,7 @@ class Capabilities {
|
|||||||
if (!isset($role_objects[$role])) {
|
if (!isset($role_objects[$role])) {
|
||||||
$role_objects[$role] = WPFunctions::get()->getRole($role);
|
$role_objects[$role] = WPFunctions::get()->getRole($role);
|
||||||
}
|
}
|
||||||
if (!is_object($role_objects[$role])) continue;
|
if (!$role_objects[$role] instanceof WP_Role) continue;
|
||||||
$role_objects[$role]->remove_cap($name);
|
$role_objects[$role]->remove_cap($name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -748,7 +748,7 @@ class Menu {
|
|||||||
function formEditor() {
|
function formEditor() {
|
||||||
$id = (isset($_GET['id']) ? (int)$_GET['id'] : 0);
|
$id = (isset($_GET['id']) ? (int)$_GET['id'] : 0);
|
||||||
$form = Form::findOne($id);
|
$form = Form::findOne($id);
|
||||||
if ($form !== false) {
|
if ($form instanceof Form) {
|
||||||
$form = $form->asArray();
|
$form = $form->asArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,9 +121,13 @@ class Renderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getAssetManifest($manifest_file) {
|
function getAssetManifest($manifest_file) {
|
||||||
return (is_readable($manifest_file)) ?
|
if (is_readable($manifest_file)) {
|
||||||
json_decode(file_get_contents($manifest_file), true) :
|
$contents = file_get_contents($manifest_file);
|
||||||
false;
|
if (is_string($contents)) {
|
||||||
|
return json_decode($contents, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getJsAsset($asset) {
|
function getJsAsset($asset) {
|
||||||
|
@ -47,7 +47,10 @@ class RequirementsChecker {
|
|||||||
);
|
);
|
||||||
$results = array();
|
$results = array();
|
||||||
foreach ($available_tests as $test) {
|
foreach ($available_tests as $test) {
|
||||||
$results[$test] = call_user_func(array($this, 'check' . $test));
|
$callback = [$this, 'check' . $test];
|
||||||
|
if (is_callable($callback)) {
|
||||||
|
$results[$test] = call_user_func($callback);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
@ -28,9 +28,9 @@ class Updater {
|
|||||||
function init() {
|
function init() {
|
||||||
WPFunctions::get()->addFilter('pre_set_site_transient_update_plugins', array($this, 'checkForUpdate'));
|
WPFunctions::get()->addFilter('pre_set_site_transient_update_plugins', array($this, 'checkForUpdate'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkForUpdate($update_transient) {
|
function checkForUpdate($update_transient) {
|
||||||
if (!is_object($update_transient)) {
|
if (!$update_transient instanceof \stdClass) {
|
||||||
$update_transient = new \stdClass;
|
$update_transient = new \stdClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +121,9 @@ class Newsletter {
|
|||||||
if (!$queue_errors) {
|
if (!$queue_errors) {
|
||||||
// verify that the rendered body was successfully saved
|
// verify that the rendered body was successfully saved
|
||||||
$queue = SendingQueueModel::findOne($queue->id);
|
$queue = SendingQueueModel::findOne($queue->id);
|
||||||
$queue_errors = ($queue->validate() !== true);
|
if ($queue instanceof SendingQueueModel) {
|
||||||
|
$queue_errors = ($queue->validate() !== true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ($queue_errors) {
|
if ($queue_errors) {
|
||||||
$this->stopNewsletterPreProcessing(sprintf('QUEUE-%d-SAVE', $queue->id));
|
$this->stopNewsletterPreProcessing(sprintf('QUEUE-%d-SAVE', $queue->id));
|
||||||
|
@ -9,6 +9,7 @@ use MailPoet\Mailer\Mailer;
|
|||||||
use MailPoet\Models\Newsletter;
|
use MailPoet\Models\Newsletter;
|
||||||
use MailPoet\Models\NewsletterLink;
|
use MailPoet\Models\NewsletterLink;
|
||||||
use MailPoet\Models\ScheduledTask;
|
use MailPoet\Models\ScheduledTask;
|
||||||
|
use MailPoet\Models\StatsNotification;
|
||||||
use MailPoet\Settings\SettingsController;
|
use MailPoet\Settings\SettingsController;
|
||||||
use MailPoet\Tasks\Sending;
|
use MailPoet\Tasks\Sending;
|
||||||
use MailPoet\WP\Functions as WPFunctions;
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
@ -81,8 +82,11 @@ class Worker {
|
|||||||
|
|
||||||
private function getNewsletter(ScheduledTask $task) {
|
private function getNewsletter(ScheduledTask $task) {
|
||||||
$statsNotificationModel = $task->statsNotification()->findOne();
|
$statsNotificationModel = $task->statsNotification()->findOne();
|
||||||
|
if (!$statsNotificationModel instanceof StatsNotification) {
|
||||||
|
throw new \Exception('Newsletter not found');
|
||||||
|
}
|
||||||
$newsletter = $statsNotificationModel->newsletter()->findOne();
|
$newsletter = $statsNotificationModel->newsletter()->findOne();
|
||||||
if (!$newsletter) {
|
if (!$newsletter instanceof Newsletter) {
|
||||||
throw new \Exception('Newsletter not found');
|
throw new \Exception('Newsletter not found');
|
||||||
}
|
}
|
||||||
return $newsletter
|
return $newsletter
|
||||||
|
@ -20,10 +20,13 @@ class BulkActionController {
|
|||||||
unset($data['action']);
|
unset($data['action']);
|
||||||
|
|
||||||
$action_class = $this->factory->getActionClass($model_class, $bulk_action_method);
|
$action_class = $this->factory->getActionClass($model_class, $bulk_action_method);
|
||||||
|
$callback = [$action_class, $bulk_action_method];
|
||||||
|
|
||||||
return call_user_func_array(
|
if (is_callable($callback)) {
|
||||||
array($action_class, $bulk_action_method),
|
return call_user_func_array(
|
||||||
array($this->handler->getSelection($model_class, $data['listing']), $data)
|
$callback,
|
||||||
);
|
array($this->handler->getSelection($model_class, $data['listing']), $data)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,8 @@ if (!defined('ABSPATH')) exit;
|
|||||||
* @method $this useIdColumn($id_column)
|
* @method $this useIdColumn($id_column)
|
||||||
* @method $this|bool findOne($id=null)
|
* @method $this|bool findOne($id=null)
|
||||||
* @method static static|bool findOne($id=null)
|
* @method static static|bool findOne($id=null)
|
||||||
* @method array|\IdiormResultSet findMany()
|
* @method array findMany()
|
||||||
* @method static array|\IdiormResultSet findMany()
|
* @method static array findMany()
|
||||||
* @method \IdiormResultSet findResultSet()
|
* @method \IdiormResultSet findResultSet()
|
||||||
* @method array findArray()
|
* @method array findArray()
|
||||||
* @method static array findArray()
|
* @method static array findArray()
|
||||||
@ -162,7 +162,7 @@ class Model extends \Sudzy\ValidModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($model === false) {
|
if ($model === false) {
|
||||||
if (!empty($onCreate)) {
|
if (!empty($onCreate) && is_callable($onCreate)) {
|
||||||
$data = $onCreate($data);
|
$data = $onCreate($data);
|
||||||
}
|
}
|
||||||
$model = static::create();
|
$model = static::create();
|
||||||
|
@ -26,7 +26,10 @@ class ModelValidator extends \Sudzy\Engine {
|
|||||||
$_this = $this;
|
$_this = $this;
|
||||||
foreach ($this->validators as $validator => $action) {
|
foreach ($this->validators as $validator => $action) {
|
||||||
$this->addValidator($validator, function($params) use ($action, $_this) {
|
$this->addValidator($validator, function($params) use ($action, $_this) {
|
||||||
return call_user_func(array($_this, $action), $params);
|
$callback = [$_this, $action];
|
||||||
|
if (is_callable($callback)) {
|
||||||
|
return call_user_func($callback, $params);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,8 @@ if (!defined('ABSPATH')) exit;
|
|||||||
* @property string $subject
|
* @property string $subject
|
||||||
* @property string $body
|
* @property string $body
|
||||||
* @property string|null $schedule
|
* @property string|null $schedule
|
||||||
|
* @property boolean|null $isScheduled
|
||||||
|
* @property string|null $scheduledAt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Newsletter extends Model {
|
class Newsletter extends Model {
|
||||||
|
@ -218,7 +218,7 @@ class Subscriber extends Model {
|
|||||||
return self::filter('withoutSegments');
|
return self::filter('withoutSegments');
|
||||||
} else {
|
} else {
|
||||||
$segment = Segment::findOne($value);
|
$segment = Segment::findOne($value);
|
||||||
if ($segment !== false) {
|
if ($segment instanceof Segment) {
|
||||||
return $segment->subscribers();
|
return $segment->subscribers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -459,10 +459,10 @@ class Subscriber extends Model {
|
|||||||
->where('subscriber_id', $this->id())
|
->where('subscriber_id', $this->id())
|
||||||
->findOne();
|
->findOne();
|
||||||
|
|
||||||
if ($custom_field === false) {
|
if ($custom_field instanceof SubscriberCustomField) {
|
||||||
return $default;
|
|
||||||
} else {
|
|
||||||
return $custom_field->value;
|
return $custom_field->value;
|
||||||
|
} else {
|
||||||
|
return $default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -495,7 +495,10 @@ class Subscriber extends Model {
|
|||||||
|
|
||||||
function setUnconfirmedData(array $subscriber_data) {
|
function setUnconfirmedData(array $subscriber_data) {
|
||||||
$subscriber_data = self::filterOutReservedColumns($subscriber_data);
|
$subscriber_data = self::filterOutReservedColumns($subscriber_data);
|
||||||
$this->unconfirmed_data = json_encode($subscriber_data);
|
$encoded = json_encode($subscriber_data);
|
||||||
|
if (is_string($encoded)) {
|
||||||
|
$this->unconfirmed_data = $encoded;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUnconfirmedData() {
|
function getUnconfirmedData() {
|
||||||
@ -511,7 +514,7 @@ class Subscriber extends Model {
|
|||||||
$segment_id = (isset($data['segment_id']) ? (int)$data['segment_id'] : 0);
|
$segment_id = (isset($data['segment_id']) ? (int)$data['segment_id'] : 0);
|
||||||
$segment = Segment::findOne($segment_id);
|
$segment = Segment::findOne($segment_id);
|
||||||
|
|
||||||
if ($segment === false) return false;
|
if (!$segment instanceof Segment) return false;
|
||||||
|
|
||||||
$count = parent::bulkAction($orm,
|
$count = parent::bulkAction($orm,
|
||||||
function($subscriber_ids) use($segment) {
|
function($subscriber_ids) use($segment) {
|
||||||
@ -531,7 +534,7 @@ class Subscriber extends Model {
|
|||||||
$segment_id = (isset($data['segment_id']) ? (int)$data['segment_id'] : 0);
|
$segment_id = (isset($data['segment_id']) ? (int)$data['segment_id'] : 0);
|
||||||
$segment = Segment::findOne($segment_id);
|
$segment = Segment::findOne($segment_id);
|
||||||
|
|
||||||
if ($segment === false) return false;
|
if (!$segment instanceof Segment) return false;
|
||||||
|
|
||||||
$count = parent::bulkAction($orm,
|
$count = parent::bulkAction($orm,
|
||||||
function($subscriber_ids) use($segment) {
|
function($subscriber_ids) use($segment) {
|
||||||
@ -552,7 +555,7 @@ class Subscriber extends Model {
|
|||||||
$segment_id = (isset($data['segment_id']) ? (int)$data['segment_id'] : 0);
|
$segment_id = (isset($data['segment_id']) ? (int)$data['segment_id'] : 0);
|
||||||
$segment = Segment::findOne($segment_id);
|
$segment = Segment::findOne($segment_id);
|
||||||
|
|
||||||
if ($segment === false) return false;
|
if (!$segment instanceof Segment) return false;
|
||||||
|
|
||||||
$count = $orm->count();
|
$count = $orm->count();
|
||||||
|
|
||||||
|
@ -15,10 +15,10 @@ class SubscriberCustomField extends Model {
|
|||||||
|
|
||||||
static function createOrUpdate($data = array()) {
|
static function createOrUpdate($data = array()) {
|
||||||
$custom_field = CustomField::findOne($data['custom_field_id']);
|
$custom_field = CustomField::findOne($data['custom_field_id']);
|
||||||
if ($custom_field === false) {
|
if ($custom_field instanceof CustomField) {
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
$custom_field = $custom_field->asArray();
|
$custom_field = $custom_field->asArray();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($custom_field['type'] === 'date') {
|
if ($custom_field['type'] === 'date') {
|
||||||
|
@ -179,7 +179,7 @@ class Links {
|
|||||||
->findOne();
|
->findOne();
|
||||||
// convert either only link shortcodes or all hashes links if "convert all"
|
// convert either only link shortcodes or all hashes links if "convert all"
|
||||||
// option is specified
|
// option is specified
|
||||||
if ($newsletter_link &&
|
if (($newsletter_link instanceof NewsletterLink) &&
|
||||||
(preg_match('/\[link:/', $newsletter_link->url) || $convert_all)
|
(preg_match('/\[link:/', $newsletter_link->url) || $convert_all)
|
||||||
) {
|
) {
|
||||||
$content = str_replace($link, $newsletter_link->url, $content);
|
$content = str_replace($link, $newsletter_link->url, $content);
|
||||||
|
@ -55,13 +55,13 @@ class Router {
|
|||||||
return $this->terminateRequest(self::RESPONE_FORBIDDEN, WPFunctions::get()->__('You do not have the required permissions.', 'mailpoet'));
|
return $this->terminateRequest(self::RESPONE_FORBIDDEN, WPFunctions::get()->__('You do not have the required permissions.', 'mailpoet'));
|
||||||
}
|
}
|
||||||
WPFunctions::get()->doAction('mailpoet_conflict_resolver_router_url_query_parameters');
|
WPFunctions::get()->doAction('mailpoet_conflict_resolver_router_url_query_parameters');
|
||||||
return call_user_func(
|
$callback = [
|
||||||
[
|
$endpoint,
|
||||||
$endpoint,
|
$this->endpoint_action,
|
||||||
$this->endpoint_action,
|
];
|
||||||
],
|
if (is_callable($callback)) {
|
||||||
$this->data
|
return call_user_func($callback, $this->data);
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static function decodeRequestData($data) {
|
static function decodeRequestData($data) {
|
||||||
|
@ -26,14 +26,14 @@ class BulkAction {
|
|||||||
throw new \InvalidArgumentException('Missing segment id');
|
throw new \InvalidArgumentException('Missing segment id');
|
||||||
}
|
}
|
||||||
$segment = Segment::findOne($this->data['listing']['filter']['segment']);
|
$segment = Segment::findOne($this->data['listing']['filter']['segment']);
|
||||||
if ($segment) {
|
if ($segment instanceof Segment) {
|
||||||
$segment = $segment->asArray();
|
$segment = $segment->asArray();
|
||||||
}
|
}
|
||||||
return $this->applySegment($segment);
|
return $this->applySegment($segment);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $segment
|
* @param array|bool $segment
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
|
@ -23,7 +23,7 @@ class SubscribersListings {
|
|||||||
throw new \InvalidArgumentException('Missing segment id');
|
throw new \InvalidArgumentException('Missing segment id');
|
||||||
}
|
}
|
||||||
$segment = Segment::findOne($data['filter']['segment']);
|
$segment = Segment::findOne($data['filter']['segment']);
|
||||||
return $this->getListings($data, $segment ?: null);
|
return $this->getListings($data, $segment instanceof Segment ? $segment : null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ class SettingsController {
|
|||||||
|
|
||||||
private function fetchValue($key) {
|
private function fetchValue($key) {
|
||||||
$setting = Setting::where('name', $key)->findOne();
|
$setting = Setting::where('name', $key)->findOne();
|
||||||
if ($setting === false) {
|
if (!$setting instanceof Setting) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (is_serialized($setting->value)) {
|
if (is_serialized($setting->value)) {
|
||||||
|
@ -59,6 +59,7 @@ class Export {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function process() {
|
function process() {
|
||||||
|
$processed_subscribers = 0;
|
||||||
$this->default_subscribers_getter->reset();
|
$this->default_subscribers_getter->reset();
|
||||||
try {
|
try {
|
||||||
if (is_writable($this->export_path) === false) {
|
if (is_writable($this->export_path) === false) {
|
||||||
@ -67,12 +68,13 @@ class Export {
|
|||||||
if (!extension_loaded('zip')) {
|
if (!extension_loaded('zip')) {
|
||||||
throw new \Exception(__('Export requires a ZIP extension to be installed on the host.', 'mailpoet'));
|
throw new \Exception(__('Export requires a ZIP extension to be installed on the host.', 'mailpoet'));
|
||||||
}
|
}
|
||||||
$processed_subscribers = call_user_func(
|
$callback = [
|
||||||
array(
|
$this,
|
||||||
$this,
|
'generate' . strtoupper($this->export_format_option)
|
||||||
'generate' . strtoupper($this->export_format_option)
|
];
|
||||||
)
|
if (is_callable($callback)) {
|
||||||
);
|
$processed_subscribers = call_user_func($callback);
|
||||||
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
throw new \Exception($e->getMessage());
|
throw new \Exception($e->getMessage());
|
||||||
}
|
}
|
||||||
|
@ -235,7 +235,10 @@ class Sending {
|
|||||||
|
|
||||||
public function __call($name, $args) {
|
public function __call($name, $args) {
|
||||||
$obj = method_exists($this->queue, $name) ? $this->queue : $this->task;
|
$obj = method_exists($this->queue, $name) ? $this->queue : $this->task;
|
||||||
return call_user_func_array(array($obj, $name), $args);
|
$callback = [$obj, $name];
|
||||||
|
if (is_callable($callback)) {
|
||||||
|
return call_user_func_array($callback, $args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function isQueueProperty($prop) {
|
private function isQueueProperty($prop) {
|
||||||
|
@ -73,7 +73,7 @@ class State
|
|||||||
$queue = $newsletter = null;
|
$queue = $newsletter = null;
|
||||||
if ($task->type === Sending::TASK_TYPE) {
|
if ($task->type === Sending::TASK_TYPE) {
|
||||||
$queue = SendingQueue::where('task_id', $task->id)->findOne();
|
$queue = SendingQueue::where('task_id', $task->id)->findOne();
|
||||||
$newsletter = $queue ? $queue->newsletter()->findOne() : null;
|
$newsletter = $queue instanceof SendingQueue ? $queue->newsletter()->findOne() : null;
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
'id' => (int)$task->id,
|
'id' => (int)$task->id,
|
||||||
|
@ -92,7 +92,7 @@ class I18n extends AbstractExtension {
|
|||||||
$date = strtotime($date);
|
$date = strtotime($date);
|
||||||
}
|
}
|
||||||
|
|
||||||
return WPFunctions::get()->getDateFromGmt(date('Y-m-d H:i:s', $date), $date_format);
|
return WPFunctions::get()->getDateFromGmt(date('Y-m-d H:i:s', (int)$date), $date_format);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setTextDomain($args = array()) {
|
private function setTextDomain($args = array()) {
|
||||||
|
@ -51,12 +51,14 @@ if (!class_exists('ProgressBar', false)) {
|
|||||||
* @return array|false Array of counters
|
* @return array|false Array of counters
|
||||||
*/
|
*/
|
||||||
private function readProgress() {
|
private function readProgress() {
|
||||||
if (file_exists($this->filename)) {
|
if (!file_exists($this->filename)) {
|
||||||
$json_content = file_get_contents($this->filename);
|
|
||||||
return json_decode($json_content);
|
|
||||||
} else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
$json_content = file_get_contents($this->filename);
|
||||||
|
if (is_string($json_content)) {
|
||||||
|
return json_decode($json_content);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,7 +37,10 @@ class Engine
|
|||||||
|
|
||||||
public function executeOne($check, $val, $params=array())
|
public function executeOne($check, $val, $params=array())
|
||||||
{
|
{
|
||||||
return call_user_func(__NAMESPACE__ .'\Engine::'.$check, $val, $params);
|
$callback = __NAMESPACE__ .'\Engine::'.$check;
|
||||||
|
if (is_callable($callback)) {
|
||||||
|
return call_user_func($callback, $val, $params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -201,7 +201,7 @@ class XLSXWriter
|
|||||||
$max_cell_tag = '<dimension ref="A1:' . $max_cell . '"/>';
|
$max_cell_tag = '<dimension ref="A1:' . $max_cell . '"/>';
|
||||||
$padding_length = $sheet->max_cell_tag_end - $sheet->max_cell_tag_start - strlen($max_cell_tag);
|
$padding_length = $sheet->max_cell_tag_end - $sheet->max_cell_tag_start - strlen($max_cell_tag);
|
||||||
$sheet->file_writer->fseek($sheet->max_cell_tag_start);
|
$sheet->file_writer->fseek($sheet->max_cell_tag_start);
|
||||||
$sheet->file_writer->write($max_cell_tag.str_repeat(" ", $padding_length));
|
$sheet->file_writer->write($max_cell_tag . str_repeat(" ", (int)$padding_length));
|
||||||
$sheet->file_writer->close();
|
$sheet->file_writer->close();
|
||||||
$sheet->finalized=true;
|
$sheet->finalized=true;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\WP;
|
namespace MailPoet\WP;
|
||||||
|
|
||||||
|
use WP_Error;
|
||||||
|
|
||||||
class Functions {
|
class Functions {
|
||||||
|
|
||||||
static private $instance;
|
static private $instance;
|
||||||
@ -240,14 +242,16 @@ class Functions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string|array $deprecated
|
* @param string|array $args
|
||||||
|
* @param string|array $deprecated
|
||||||
|
* @return array|int|WP_Error
|
||||||
*/
|
*/
|
||||||
function getTerms($args = array(), $deprecated = '') {
|
function getTerms($args = array(), $deprecated = '') {
|
||||||
return get_terms($args, $deprecated);
|
return get_terms($args, $deprecated);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int|boolean $user_id
|
* @param int|boolean $user_id
|
||||||
*/
|
*/
|
||||||
function getTheAuthorMeta($field = '', $user_id = false) {
|
function getTheAuthorMeta($field = '', $user_id = false) {
|
||||||
return get_the_author_meta($field, $user_id);
|
return get_the_author_meta($field, $user_id);
|
||||||
|
Reference in New Issue
Block a user