Define default variable values in cases when they can be undefined

This commit is contained in:
Tautvidas Sipavičius
2019-01-23 21:29:46 +02:00
parent 3bfba7c642
commit 44bc27df90
6 changed files with 16 additions and 5 deletions

View File

@ -172,6 +172,7 @@ class Forms extends APIEndpoint {
// check if the user gets to pick his own lists // check if the user gets to pick his own lists
// or if it's selected by the admin // or if it's selected by the admin
$has_segment_selection = false; $has_segment_selection = false;
$list_selection = [];
foreach($body as $i => $block) { foreach($body as $i => $block) {
if($block['type'] === 'segment') { if($block['type'] === 'segment') {
$has_segment_selection = true; $has_segment_selection = true;

View File

@ -24,6 +24,9 @@ class Migration extends SimpleWorker {
function prepareTask(ScheduledTask $task) { function prepareTask(ScheduledTask $task) {
$unmigrated_columns = self::checkUnmigratedColumnsExist(); $unmigrated_columns = self::checkUnmigratedColumnsExist();
$unmigrated_queues_count = 0;
$unmigrated_queue_subscribers = [];
if($unmigrated_columns) { if($unmigrated_columns) {
$unmigrated_queues_count = $this->getUnmigratedQueues()->count(); $unmigrated_queues_count = $this->getUnmigratedQueues()->count();
$unmigrated_queue_subscribers = $this->getTaskIdsForUnmigratedSubscribers(); $unmigrated_queue_subscribers = $this->getTaskIdsForUnmigratedSubscribers();

View File

@ -5,6 +5,7 @@ class Html {
static function render($block) { static function render($block) {
$html = ''; $html = '';
$text = '';
if(isset($block['params']['text']) && $block['params']['text']) { if(isset($block['params']['text']) && $block['params']['text']) {
$text = html_entity_decode($block['params']['text'], ENT_QUOTES); $text = html_entity_decode($block['params']['text'], ENT_QUOTES);

View File

@ -147,7 +147,7 @@ class Scheduler {
} }
static function createPostNotificationSendingTask($newsletter) { static function createPostNotificationSendingTask($newsletter) {
$existing_notification_history = Newsletter::table_alias('newsletters') $existing_notification_history = Newsletter::tableAlias('newsletters')
->where('newsletters.parent_id', $newsletter->id) ->where('newsletters.parent_id', $newsletter->id)
->where('newsletters.type', Newsletter::TYPE_NOTIFICATION_HISTORY) ->where('newsletters.type', Newsletter::TYPE_NOTIFICATION_HISTORY)
->where('newsletters.status', Newsletter::STATUS_SENDING) ->where('newsletters.status', Newsletter::STATUS_SENDING)
@ -194,9 +194,6 @@ class Scheduler {
$newsletter->nthWeekDay : $newsletter->nthWeekDay :
'#' . $newsletter->nthWeekDay; '#' . $newsletter->nthWeekDay;
switch($interval_type) { switch($interval_type) {
case self::INTERVAL_IMMEDIATELY:
$schedule = '* * * * *';
break;
case self::INTERVAL_IMMEDIATE: case self::INTERVAL_IMMEDIATE:
case self::INTERVAL_DAILY: case self::INTERVAL_DAILY:
$schedule = sprintf('0 %s * * *', $hour); $schedule = sprintf('0 %s * * *', $hour);
@ -210,6 +207,10 @@ class Scheduler {
case self::INTERVAL_MONTHLY: case self::INTERVAL_MONTHLY:
$schedule = sprintf('0 %s %s * *', $hour, $month_day); $schedule = sprintf('0 %s %s * *', $hour, $month_day);
break; break;
case self::INTERVAL_IMMEDIATELY:
default:
$schedule = '* * * * *';
break;
} }
$option_field = NewsletterOptionField::where('name', 'schedule')->findOne(); $option_field = NewsletterOptionField::where('name', 'schedule')->findOne();
$relation = NewsletterOption::where('newsletter_id', $newsletter->id) $relation = NewsletterOption::where('newsletter_id', $newsletter->id)

View File

@ -194,6 +194,7 @@ class Import {
} }
function transformSubscribersData($subscribers, $columns) { function transformSubscribersData($subscribers, $columns) {
$transformed_subscribers = [];
foreach($columns as $column => $data) { foreach($columns as $column => $data) {
$transformed_subscribers[$column] = array_column($subscribers, $data['index']); $transformed_subscribers[$column] = array_column($subscribers, $data['index']);
} }
@ -227,6 +228,7 @@ class Import {
$wp_users = array_filter(array_column($temp_existing_subscribers, 'wp_user_id')); $wp_users = array_filter(array_column($temp_existing_subscribers, 'wp_user_id'));
// create a new two-dimensional associative array with existing subscribers ($existing_subscribers) // create a new two-dimensional associative array with existing subscribers ($existing_subscribers)
// and reduce $subscribers_data to only new subscribers by removing existing subscribers // and reduce $subscribers_data to only new subscribers by removing existing subscribers
$existing_subscribers = [];
$subscribers_emails = array_flip($subscribers_data['email']); $subscribers_emails = array_flip($subscribers_data['email']);
foreach($temp_existing_subscribers as $temp_existing_subscriber) { foreach($temp_existing_subscribers as $temp_existing_subscriber) {
$existing_subscriber_key = $subscribers_emails[$temp_existing_subscriber['email']]; $existing_subscriber_key = $subscribers_emails[$temp_existing_subscriber['email']];

View File

@ -45,6 +45,7 @@ class MailChimp {
return $this->throwException('API'); return $this->throwException('API');
} }
$lists = [];
foreach($response->data as $list) { foreach($response->data as $list) {
$lists[] = array( $lists[] = array(
'id' => $list->id, 'id' => $list->id,
@ -65,6 +66,8 @@ class MailChimp {
} }
$bytes_fetched = 0; $bytes_fetched = 0;
$subscribers = [];
$header = [];
foreach($lists as $list) { foreach($lists as $list) {
$url = sprintf($this->export_url, $this->data_center, $this->api_key, $list); $url = sprintf($this->export_url, $this->data_center, $this->api_key, $list);
$connection = @fopen($url, 'r'); $connection = @fopen($url, 'r');
@ -72,7 +75,6 @@ class MailChimp {
return $this->throwException('connection'); return $this->throwException('connection');
} }
$i = 0; $i = 0;
$header = array();
while(!feof($connection)) { while(!feof($connection)) {
$buffer = fgets($connection, 4096); $buffer = fgets($connection, 4096);
if(trim($buffer) !== '') { if(trim($buffer) !== '') {
@ -124,6 +126,7 @@ class MailChimp {
} }
function throwException($error) { function throwException($error) {
$errorMessage = __('Unknown MailChimp error message.', 'mailpoet');
switch($error) { switch($error) {
case 'API': case 'API':
$errorMessage = __('Invalid API Key.', 'mailpoet'); $errorMessage = __('Invalid API Key.', 'mailpoet');