Fix phpstan level 6
[MAILPOET-1969]
This commit is contained in:
@ -68,7 +68,7 @@ jobs:
|
||||
name: "Set up environment"
|
||||
command: |
|
||||
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:
|
||||
name: "Static analysis"
|
||||
command: ./do qa:phpstan
|
||||
|
@ -27,14 +27,14 @@ class CustomFields extends APIEndpoint {
|
||||
function delete($data = array()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : null);
|
||||
$custom_field = CustomField::findOne($id);
|
||||
if ($custom_field === false) {
|
||||
return $this->errorResponse(array(
|
||||
APIError::NOT_FOUND => WPFunctions::get()->__('This custom field does not exist.', 'mailpoet')
|
||||
));
|
||||
} else {
|
||||
if ($custom_field instanceof CustomField) {
|
||||
$custom_field->delete();
|
||||
|
||||
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)) {
|
||||
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()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : null);
|
||||
$custom_field = CustomField::findOne($id);
|
||||
if ($custom_field === false) {
|
||||
if ($custom_field instanceof CustomField) {
|
||||
return $this->successResponse($custom_field->asArray());
|
||||
}
|
||||
return $this->errorResponse(array(
|
||||
APIError::NOT_FOUND => WPFunctions::get()->__('This custom field does not exist.', 'mailpoet')
|
||||
));
|
||||
} else {
|
||||
return $this->successResponse($custom_field->asArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,13 +37,12 @@ class Forms extends APIEndpoint {
|
||||
function get($data = array()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$form = Form::findOne($id);
|
||||
if ($form === false) {
|
||||
if ($form instanceof Form) {
|
||||
return $this->successResponse($form->asArray());
|
||||
}
|
||||
return $this->errorResponse(array(
|
||||
APIError::NOT_FOUND => WPFunctions::get()->__('This form does not exist.', 'mailpoet')
|
||||
));
|
||||
} else {
|
||||
return $this->successResponse($form->asArray());
|
||||
}
|
||||
}
|
||||
|
||||
function listing($data = array()) {
|
||||
@ -111,13 +110,12 @@ class Forms extends APIEndpoint {
|
||||
$form = Form::createOrUpdate($data);
|
||||
$errors = $form->getErrors();
|
||||
|
||||
if (!empty($errors)) {
|
||||
return $this->badRequest($errors);
|
||||
} else {
|
||||
return $this->successResponse(
|
||||
Form::findOne($form->id)->asArray()
|
||||
);
|
||||
if (empty($errors)) {
|
||||
$form = Form::findOne($form->id);
|
||||
if(!$form instanceof Form) return $this->errorResponse();
|
||||
return $this->successResponse($form->asArray());
|
||||
}
|
||||
return $this->badRequest($errors);
|
||||
}
|
||||
|
||||
function previewEditor($data = array()) {
|
||||
@ -139,19 +137,16 @@ class Forms extends APIEndpoint {
|
||||
function exportsEditor($data = array()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$form = Form::findOne($id);
|
||||
if ($form === false) {
|
||||
return $this->errorResponse(array(
|
||||
APIError::NOT_FOUND => WPFunctions::get()->__('This form does not exist.', 'mailpoet')
|
||||
));
|
||||
} else {
|
||||
if ($form instanceof Form) {
|
||||
$exports = Util\Export::getAll($form->asArray());
|
||||
return $this->successResponse($exports);
|
||||
}
|
||||
return $this->errorResponse(array(
|
||||
APIError::NOT_FOUND => WPFunctions::get()->__('This form does not exist.', 'mailpoet')
|
||||
));
|
||||
}
|
||||
|
||||
function saveEditor($data = array()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
|
||||
$form_id = (isset($data['id']) ? (int)$data['id'] : 0);
|
||||
$name = (isset($data['name']) ? $data['name'] : WPFunctions::get()->__('New form', 'mailpoet'));
|
||||
$body = (isset($data['body']) ? $data['body'] : array());
|
||||
@ -211,56 +206,62 @@ class Forms extends APIEndpoint {
|
||||
|
||||
if (!empty($errors)) {
|
||||
return $this->badRequest($errors);
|
||||
} else {
|
||||
}
|
||||
$form = Form::findOne($form->id);
|
||||
if(!$form instanceof Form) return $this->errorResponse();
|
||||
return $this->successResponse(
|
||||
Form::findOne($form->id)->asArray(),
|
||||
$form->asArray(),
|
||||
array('is_widget' => $is_widget)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function restore($data = array()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$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(
|
||||
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()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$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(
|
||||
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()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$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(
|
||||
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);
|
||||
$form = Form::findOne($id);
|
||||
|
||||
if ($form === false) {
|
||||
return $this->errorResponse(array(
|
||||
APIError::NOT_FOUND => WPFunctions::get()->__('This form does not exist.', 'mailpoet')
|
||||
));
|
||||
} else {
|
||||
if ($form instanceof Form) {
|
||||
$data = array(
|
||||
'name' => sprintf(__('Copy of %s', 'mailpoet'), $form->name)
|
||||
);
|
||||
@ -282,11 +279,17 @@ class Forms extends APIEndpoint {
|
||||
if (!empty($errors)) {
|
||||
return $this->errorResponse($errors);
|
||||
} else {
|
||||
$duplicate = Form::findOne($duplicate->id);
|
||||
if(!$duplicate instanceof Form) return $this->errorResponse();
|
||||
return $this->successResponse(
|
||||
Form::findOne($duplicate->id)->asArray(),
|
||||
$duplicate->asArray(),
|
||||
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)) {
|
||||
return $this->errorResponse($errors);
|
||||
} else {
|
||||
return $this->successResponse(
|
||||
Segment::findOne($segment->id)->asArray()
|
||||
);
|
||||
$segment = Segment::findOne($segment->id);
|
||||
if(!$segment instanceof Segment) return $this->errorResponse();
|
||||
return $this->successResponse($segment->asArray());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,14 +18,14 @@ class NewsletterTemplates extends APIEndpoint {
|
||||
function get($data = array()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$template = NewsletterTemplate::findOne($id);
|
||||
if ($template === false) {
|
||||
return $this->errorResponse(array(
|
||||
APIError::NOT_FOUND => WPFunctions::get()->__('This template does not exist.', 'mailpoet')
|
||||
));
|
||||
} else {
|
||||
if ($template instanceof NewsletterTemplate) {
|
||||
return $this->successResponse(
|
||||
$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);
|
||||
if (!empty($data['newsletter_id'])) {
|
||||
$template = NewsletterTemplate::whereEqual('newsletter_id', $data['newsletter_id'])->findOne();
|
||||
if (!empty($template)) {
|
||||
if ($template instanceof NewsletterTemplate) {
|
||||
$data['id'] = $template->id;
|
||||
}
|
||||
}
|
||||
@ -60,8 +60,10 @@ class NewsletterTemplates extends APIEndpoint {
|
||||
if (!empty($errors)) {
|
||||
return $this->errorResponse($errors);
|
||||
} else {
|
||||
$template = NewsletterTemplate::findOne($template->id);
|
||||
if(!$template instanceof NewsletterTemplate) return $this->errorResponse();
|
||||
return $this->successResponse(
|
||||
NewsletterTemplate::findOne($template->id)->asArray()
|
||||
$template->asArray()
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -69,13 +71,13 @@ class NewsletterTemplates extends APIEndpoint {
|
||||
function delete($data = array()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$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(
|
||||
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()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$newsletter = Newsletter::findOne($id);
|
||||
if ($newsletter === false) {
|
||||
return $this->errorResponse(array(
|
||||
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
||||
));
|
||||
} else {
|
||||
if ($newsletter instanceof Newsletter) {
|
||||
$newsletter = $newsletter
|
||||
->withSegments()
|
||||
->withOptions()
|
||||
@ -76,6 +72,10 @@ class Newsletters extends APIEndpoint {
|
||||
|
||||
$newsletter = $this->wp->applyFilters('mailpoet_api_newsletters_get_after', $newsletter->asArray());
|
||||
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'])) {
|
||||
$template = NewsletterTemplate::whereEqual('id', $data['template_id'])->findOne();
|
||||
if (!empty($template)) {
|
||||
if ($template instanceof NewsletterTemplate) {
|
||||
$template = $template->asArray();
|
||||
$data['body'] = $template['body'];
|
||||
}
|
||||
@ -110,6 +110,7 @@ class Newsletters extends APIEndpoint {
|
||||
// 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
|
||||
$newsletter = Newsletter::findOne($newsletter->id);
|
||||
if(!$newsletter instanceof Newsletter) return $this->errorResponse();
|
||||
|
||||
if (!empty($segments)) {
|
||||
NewsletterSegment::where('newsletter_id', $newsletter->id)
|
||||
@ -146,6 +147,7 @@ class Newsletters extends APIEndpoint {
|
||||
}
|
||||
// reload newsletter with updated options
|
||||
$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 ($newsletter->type === Newsletter::TYPE_NOTIFICATION) {
|
||||
// generate the new schedule from options and get the new "next run" date
|
||||
@ -226,54 +228,62 @@ class Newsletters extends APIEndpoint {
|
||||
Scheduler::createPostNotificationSendingTask($newsletter);
|
||||
}
|
||||
|
||||
|
||||
$newsletter = Newsletter::findOne($newsletter->id);
|
||||
if(!$newsletter instanceof Newsletter) return $this->errorResponse();
|
||||
return $this->successResponse(
|
||||
Newsletter::findOne($newsletter->id)->asArray()
|
||||
$newsletter->asArray()
|
||||
);
|
||||
}
|
||||
|
||||
function restore($data = array()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$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(
|
||||
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()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$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(
|
||||
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()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$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(
|
||||
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);
|
||||
$newsletter = Newsletter::findOne($id);
|
||||
|
||||
if ($newsletter === false) {
|
||||
return $this->errorResponse(array(
|
||||
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
||||
));
|
||||
} else {
|
||||
if ($newsletter instanceof Newsletter) {
|
||||
$data = array(
|
||||
'subject' => sprintf(__('Copy of %s', 'mailpoet'), $newsletter->subject)
|
||||
);
|
||||
@ -296,11 +302,17 @@ class Newsletters extends APIEndpoint {
|
||||
return $this->errorResponse($errors);
|
||||
} else {
|
||||
$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(
|
||||
Newsletter::findOne($duplicate->id)->asArray(),
|
||||
$duplicate->asArray(),
|
||||
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;
|
||||
$newsletter = Newsletter::findOne($id);
|
||||
|
||||
if ($newsletter === false) {
|
||||
return $this->errorResponse(array(
|
||||
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
||||
));
|
||||
} else {
|
||||
if ($newsletter instanceof Newsletter) {
|
||||
$newsletter->body = $data['body'];
|
||||
$newsletter->save();
|
||||
$subscriber = Subscriber::getCurrentWPUser();
|
||||
@ -330,10 +338,16 @@ class Newsletters extends APIEndpoint {
|
||||
// strip protocol to avoid mix content error
|
||||
$preview_url = preg_replace('{^https?:}i', '', $preview_url);
|
||||
|
||||
$newsletter = Newsletter::findOne($newsletter->id);
|
||||
if(!$newsletter instanceof Newsletter) return $this->errorResponse();
|
||||
return $this->successResponse(
|
||||
Newsletter::findOne($newsletter->id)->asArray(),
|
||||
$newsletter->asArray(),
|
||||
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;
|
||||
$newsletter = Newsletter::findOne($id);
|
||||
|
||||
if ($newsletter === false) {
|
||||
return $this->errorResponse(array(
|
||||
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
||||
));
|
||||
} else {
|
||||
if ($newsletter instanceof Newsletter) {
|
||||
$renderer = new Renderer($newsletter, $preview = true);
|
||||
$rendered_newsletter = $renderer->render();
|
||||
$divider = '***MailPoet***';
|
||||
@ -397,8 +407,11 @@ class Newsletters extends APIEndpoint {
|
||||
);
|
||||
return $this->errorResponse(array(APIError::BAD_REQUEST => $error));
|
||||
} else {
|
||||
$newsletter = Newsletter::findOne($newsletter->id);
|
||||
if(!$newsletter instanceof Newsletter) return $this->errorResponse();
|
||||
|
||||
return $this->successResponse(
|
||||
Newsletter::findOne($id)->asArray()
|
||||
$newsletter->asArray()
|
||||
);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
@ -406,6 +419,10 @@ class Newsletters extends APIEndpoint {
|
||||
$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
|
||||
$template_id = (isset($data['template']) ? (int)$data['template'] : false);
|
||||
$template = NewsletterTemplate::findOne($template_id);
|
||||
if ($template === false) {
|
||||
$newsletter->body = array();
|
||||
} else {
|
||||
if ($template instanceof NewsletterTemplate) {
|
||||
$newsletter->body = $template->body;
|
||||
} else {
|
||||
$newsletter->body = array();
|
||||
}
|
||||
}
|
||||
|
||||
@ -533,8 +550,10 @@ class Newsletters extends APIEndpoint {
|
||||
Scheduler::processPostNotificationSchedule($newsletter);
|
||||
}
|
||||
|
||||
$newsletter = Newsletter::findOne($newsletter->id);
|
||||
if(!$newsletter instanceof Newsletter) return $this->errorResponse();
|
||||
return $this->successResponse(
|
||||
Newsletter::findOne($newsletter->id)->asArray()
|
||||
$newsletter->asArray()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -40,12 +40,12 @@ class Segments extends APIEndpoint {
|
||||
function get($data = array()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$segment = Segment::findOne($id);
|
||||
if ($segment === false) {
|
||||
if ($segment instanceof Segment) {
|
||||
return $this->successResponse($segment->asArray());
|
||||
} else {
|
||||
return $this->errorResponse(array(
|
||||
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)) {
|
||||
return $this->badRequest($errors);
|
||||
} else {
|
||||
$segment = Segment::findOne($segment->id);
|
||||
if(!$segment instanceof Segment) return $this->errorResponse();
|
||||
return $this->successResponse(
|
||||
Segment::findOne($segment->id)->asArray()
|
||||
$segment->asArray()
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -86,45 +88,49 @@ class Segments extends APIEndpoint {
|
||||
function restore($data = array()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$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(
|
||||
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()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$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(
|
||||
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()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$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(
|
||||
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);
|
||||
$segment = Segment::findOne($id);
|
||||
|
||||
if ($segment === false) {
|
||||
return $this->errorResponse(array(
|
||||
APIError::NOT_FOUND => WPFunctions::get()->__('This list does not exist.', 'mailpoet')
|
||||
));
|
||||
} else {
|
||||
if ($segment instanceof Segment) {
|
||||
$data = array(
|
||||
'name' => sprintf(__('Copy of %s', 'mailpoet'), $segment->name)
|
||||
);
|
||||
@ -146,11 +148,17 @@ class Segments extends APIEndpoint {
|
||||
if (!empty($errors)) {
|
||||
return $this->errorResponse($errors);
|
||||
} else {
|
||||
$duplicate = Segment::findOne($duplicate->id);
|
||||
if(!$duplicate instanceof Segment) return $this->errorResponse();
|
||||
return $this->successResponse(
|
||||
Segment::findOne($duplicate->id)->asArray(),
|
||||
$duplicate->asArray(),
|
||||
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
|
||||
$newsletter = Newsletter::findOneWithOptions($newsletter_id);
|
||||
|
||||
if ($newsletter === false) {
|
||||
if (!$newsletter instanceof Newsletter) {
|
||||
return $this->errorResponse(array(
|
||||
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('tasks.status', SendingQueueModel::STATUS_SCHEDULED)
|
||||
->findOne();
|
||||
if ($scheduled_queue) {
|
||||
if ($scheduled_queue instanceof SendingQueueModel) {
|
||||
$queue = SendingTask::createFromQueue($scheduled_queue);
|
||||
} else {
|
||||
$queue = SendingTask::create();
|
||||
@ -108,11 +108,7 @@ class SendingQueue extends APIEndpoint {
|
||||
);
|
||||
$newsletter = Newsletter::findOne($newsletter_id);
|
||||
|
||||
if ($newsletter === false) {
|
||||
return $this->errorResponse(array(
|
||||
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
||||
));
|
||||
} else {
|
||||
if ($newsletter instanceof Newsletter) {
|
||||
$queue = $newsletter->getQueue();
|
||||
|
||||
if ($queue === false) {
|
||||
@ -125,6 +121,10 @@ class SendingQueue extends APIEndpoint {
|
||||
$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
|
||||
);
|
||||
$newsletter = Newsletter::findOne($newsletter_id);
|
||||
if ($newsletter === false) {
|
||||
return $this->errorResponse(array(
|
||||
APIError::NOT_FOUND => WPFunctions::get()->__('This newsletter does not exist.', 'mailpoet')
|
||||
));
|
||||
} else {
|
||||
if ($newsletter instanceof Newsletter) {
|
||||
$queue = $newsletter->getQueue();
|
||||
|
||||
if ($queue === false) {
|
||||
@ -151,6 +147,10 @@ class SendingQueue extends APIEndpoint {
|
||||
$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');
|
||||
|
||||
if (!$form) {
|
||||
if (!$form instanceof Form) {
|
||||
return $this->badRequest(array(
|
||||
APIError::BAD_REQUEST => WPFunctions::get()->__('Please specify a valid form ID.', 'mailpoet')
|
||||
));
|
||||
@ -266,45 +266,49 @@ class Subscribers extends APIEndpoint {
|
||||
function restore($data = array()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$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(
|
||||
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()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$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(
|
||||
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()) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$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(
|
||||
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
|
||||
$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();
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace MailPoet\Config;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
use WP_Role;
|
||||
|
||||
class Capabilities {
|
||||
const MEMBERS_CAP_GROUP_NAME = 'mailpoet';
|
||||
@ -35,7 +36,7 @@ class Capabilities {
|
||||
if (!isset($role_objects[$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);
|
||||
}
|
||||
}
|
||||
@ -49,7 +50,7 @@ class Capabilities {
|
||||
if (!isset($role_objects[$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);
|
||||
}
|
||||
}
|
||||
|
@ -748,7 +748,7 @@ class Menu {
|
||||
function formEditor() {
|
||||
$id = (isset($_GET['id']) ? (int)$_GET['id'] : 0);
|
||||
$form = Form::findOne($id);
|
||||
if ($form !== false) {
|
||||
if ($form instanceof Form) {
|
||||
$form = $form->asArray();
|
||||
}
|
||||
|
||||
|
@ -121,9 +121,13 @@ class Renderer {
|
||||
}
|
||||
|
||||
function getAssetManifest($manifest_file) {
|
||||
return (is_readable($manifest_file)) ?
|
||||
json_decode(file_get_contents($manifest_file), true) :
|
||||
false;
|
||||
if (is_readable($manifest_file)) {
|
||||
$contents = file_get_contents($manifest_file);
|
||||
if (is_string($contents)) {
|
||||
return json_decode($contents, true);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function getJsAsset($asset) {
|
||||
|
@ -47,7 +47,10 @@ class RequirementsChecker {
|
||||
);
|
||||
$results = array();
|
||||
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;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class Updater {
|
||||
}
|
||||
|
||||
function checkForUpdate($update_transient) {
|
||||
if (!is_object($update_transient)) {
|
||||
if (!$update_transient instanceof \stdClass) {
|
||||
$update_transient = new \stdClass;
|
||||
}
|
||||
|
||||
|
@ -121,8 +121,10 @@ class Newsletter {
|
||||
if (!$queue_errors) {
|
||||
// verify that the rendered body was successfully saved
|
||||
$queue = SendingQueueModel::findOne($queue->id);
|
||||
if ($queue instanceof SendingQueueModel) {
|
||||
$queue_errors = ($queue->validate() !== true);
|
||||
}
|
||||
}
|
||||
if ($queue_errors) {
|
||||
$this->stopNewsletterPreProcessing(sprintf('QUEUE-%d-SAVE', $queue->id));
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ use MailPoet\Mailer\Mailer;
|
||||
use MailPoet\Models\Newsletter;
|
||||
use MailPoet\Models\NewsletterLink;
|
||||
use MailPoet\Models\ScheduledTask;
|
||||
use MailPoet\Models\StatsNotification;
|
||||
use MailPoet\Settings\SettingsController;
|
||||
use MailPoet\Tasks\Sending;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
@ -81,8 +82,11 @@ class Worker {
|
||||
|
||||
private function getNewsletter(ScheduledTask $task) {
|
||||
$statsNotificationModel = $task->statsNotification()->findOne();
|
||||
if (!$statsNotificationModel instanceof StatsNotification) {
|
||||
throw new \Exception('Newsletter not found');
|
||||
}
|
||||
$newsletter = $statsNotificationModel->newsletter()->findOne();
|
||||
if (!$newsletter) {
|
||||
if (!$newsletter instanceof Newsletter) {
|
||||
throw new \Exception('Newsletter not found');
|
||||
}
|
||||
return $newsletter
|
||||
|
@ -20,10 +20,13 @@ class BulkActionController {
|
||||
unset($data['action']);
|
||||
|
||||
$action_class = $this->factory->getActionClass($model_class, $bulk_action_method);
|
||||
$callback = [$action_class, $bulk_action_method];
|
||||
|
||||
if (is_callable($callback)) {
|
||||
return call_user_func_array(
|
||||
array($action_class, $bulk_action_method),
|
||||
$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|bool findOne($id=null)
|
||||
* @method static static|bool findOne($id=null)
|
||||
* @method array|\IdiormResultSet findMany()
|
||||
* @method static array|\IdiormResultSet findMany()
|
||||
* @method array findMany()
|
||||
* @method static array findMany()
|
||||
* @method \IdiormResultSet findResultSet()
|
||||
* @method array findArray()
|
||||
* @method static array findArray()
|
||||
@ -162,7 +162,7 @@ class Model extends \Sudzy\ValidModel {
|
||||
}
|
||||
|
||||
if ($model === false) {
|
||||
if (!empty($onCreate)) {
|
||||
if (!empty($onCreate) && is_callable($onCreate)) {
|
||||
$data = $onCreate($data);
|
||||
}
|
||||
$model = static::create();
|
||||
|
@ -26,7 +26,10 @@ class ModelValidator extends \Sudzy\Engine {
|
||||
$_this = $this;
|
||||
foreach ($this->validators as $validator => $action) {
|
||||
$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 $body
|
||||
* @property string|null $schedule
|
||||
* @property boolean|null $isScheduled
|
||||
* @property string|null $scheduledAt
|
||||
*/
|
||||
|
||||
class Newsletter extends Model {
|
||||
|
@ -218,7 +218,7 @@ class Subscriber extends Model {
|
||||
return self::filter('withoutSegments');
|
||||
} else {
|
||||
$segment = Segment::findOne($value);
|
||||
if ($segment !== false) {
|
||||
if ($segment instanceof Segment) {
|
||||
return $segment->subscribers();
|
||||
}
|
||||
}
|
||||
@ -459,10 +459,10 @@ class Subscriber extends Model {
|
||||
->where('subscriber_id', $this->id())
|
||||
->findOne();
|
||||
|
||||
if ($custom_field === false) {
|
||||
return $default;
|
||||
} else {
|
||||
if ($custom_field instanceof SubscriberCustomField) {
|
||||
return $custom_field->value;
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
@ -495,7 +495,10 @@ class Subscriber extends Model {
|
||||
|
||||
function setUnconfirmedData(array $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() {
|
||||
@ -511,7 +514,7 @@ class Subscriber extends Model {
|
||||
$segment_id = (isset($data['segment_id']) ? (int)$data['segment_id'] : 0);
|
||||
$segment = Segment::findOne($segment_id);
|
||||
|
||||
if ($segment === false) return false;
|
||||
if (!$segment instanceof Segment) return false;
|
||||
|
||||
$count = parent::bulkAction($orm,
|
||||
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 = Segment::findOne($segment_id);
|
||||
|
||||
if ($segment === false) return false;
|
||||
if (!$segment instanceof Segment) return false;
|
||||
|
||||
$count = parent::bulkAction($orm,
|
||||
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 = Segment::findOne($segment_id);
|
||||
|
||||
if ($segment === false) return false;
|
||||
if (!$segment instanceof Segment) return false;
|
||||
|
||||
$count = $orm->count();
|
||||
|
||||
|
@ -15,10 +15,10 @@ class SubscriberCustomField extends Model {
|
||||
|
||||
static function createOrUpdate($data = array()) {
|
||||
$custom_field = CustomField::findOne($data['custom_field_id']);
|
||||
if ($custom_field === false) {
|
||||
return false;
|
||||
} else {
|
||||
if ($custom_field instanceof CustomField) {
|
||||
$custom_field = $custom_field->asArray();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($custom_field['type'] === 'date') {
|
||||
|
@ -179,7 +179,7 @@ class Links {
|
||||
->findOne();
|
||||
// convert either only link shortcodes or all hashes links if "convert all"
|
||||
// option is specified
|
||||
if ($newsletter_link &&
|
||||
if (($newsletter_link instanceof NewsletterLink) &&
|
||||
(preg_match('/\[link:/', $newsletter_link->url) || $convert_all)
|
||||
) {
|
||||
$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'));
|
||||
}
|
||||
WPFunctions::get()->doAction('mailpoet_conflict_resolver_router_url_query_parameters');
|
||||
return call_user_func(
|
||||
[
|
||||
$callback = [
|
||||
$endpoint,
|
||||
$this->endpoint_action,
|
||||
],
|
||||
$this->data
|
||||
);
|
||||
];
|
||||
if (is_callable($callback)) {
|
||||
return call_user_func($callback, $this->data);
|
||||
}
|
||||
}
|
||||
|
||||
static function decodeRequestData($data) {
|
||||
|
@ -26,14 +26,14 @@ class BulkAction {
|
||||
throw new \InvalidArgumentException('Missing segment id');
|
||||
}
|
||||
$segment = Segment::findOne($this->data['listing']['filter']['segment']);
|
||||
if ($segment) {
|
||||
if ($segment instanceof Segment) {
|
||||
$segment = $segment->asArray();
|
||||
}
|
||||
return $this->applySegment($segment);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $segment
|
||||
* @param array|bool $segment
|
||||
*
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
|
@ -23,7 +23,7 @@ class SubscribersListings {
|
||||
throw new \InvalidArgumentException('Missing segment id');
|
||||
}
|
||||
$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) {
|
||||
$setting = Setting::where('name', $key)->findOne();
|
||||
if ($setting === false) {
|
||||
if (!$setting instanceof Setting) {
|
||||
return null;
|
||||
}
|
||||
if (is_serialized($setting->value)) {
|
||||
|
@ -59,6 +59,7 @@ class Export {
|
||||
}
|
||||
|
||||
function process() {
|
||||
$processed_subscribers = 0;
|
||||
$this->default_subscribers_getter->reset();
|
||||
try {
|
||||
if (is_writable($this->export_path) === false) {
|
||||
@ -67,12 +68,13 @@ class Export {
|
||||
if (!extension_loaded('zip')) {
|
||||
throw new \Exception(__('Export requires a ZIP extension to be installed on the host.', 'mailpoet'));
|
||||
}
|
||||
$processed_subscribers = call_user_func(
|
||||
array(
|
||||
$callback = [
|
||||
$this,
|
||||
'generate' . strtoupper($this->export_format_option)
|
||||
)
|
||||
);
|
||||
];
|
||||
if (is_callable($callback)) {
|
||||
$processed_subscribers = call_user_func($callback);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw new \Exception($e->getMessage());
|
||||
}
|
||||
|
@ -235,7 +235,10 @@ class Sending {
|
||||
|
||||
public function __call($name, $args) {
|
||||
$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) {
|
||||
|
@ -73,7 +73,7 @@ class State
|
||||
$queue = $newsletter = null;
|
||||
if ($task->type === Sending::TASK_TYPE) {
|
||||
$queue = SendingQueue::where('task_id', $task->id)->findOne();
|
||||
$newsletter = $queue ? $queue->newsletter()->findOne() : null;
|
||||
$newsletter = $queue instanceof SendingQueue ? $queue->newsletter()->findOne() : null;
|
||||
}
|
||||
return [
|
||||
'id' => (int)$task->id,
|
||||
|
@ -92,7 +92,7 @@ class I18n extends AbstractExtension {
|
||||
$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()) {
|
||||
|
@ -51,12 +51,14 @@ if (!class_exists('ProgressBar', false)) {
|
||||
* @return array|false Array of counters
|
||||
*/
|
||||
private function readProgress() {
|
||||
if (file_exists($this->filename)) {
|
||||
$json_content = file_get_contents($this->filename);
|
||||
return json_decode($json_content);
|
||||
} else {
|
||||
if (!file_exists($this->filename)) {
|
||||
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())
|
||||
{
|
||||
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 . '"/>';
|
||||
$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->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->finalized=true;
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace MailPoet\WP;
|
||||
|
||||
use WP_Error;
|
||||
|
||||
class Functions {
|
||||
|
||||
static private $instance;
|
||||
@ -240,7 +242,9 @@ class Functions {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|array $args
|
||||
* @param string|array $deprecated
|
||||
* @return array|int|WP_Error
|
||||
*/
|
||||
function getTerms($args = array(), $deprecated = '') {
|
||||
return get_terms($args, $deprecated);
|
||||
|
Reference in New Issue
Block a user