From 44bc27df9009b6ee9dfbd92461c19c271ebce76a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tautvidas=20Sipavi=C4=8Dius?= Date: Wed, 23 Jan 2019 21:29:46 +0200 Subject: [PATCH] Define default variable values in cases when they can be undefined --- lib/API/JSON/v1/Forms.php | 1 + lib/Cron/Workers/SendingQueue/Migration.php | 3 +++ lib/Form/Block/Html.php | 1 + lib/Newsletter/Scheduler/Scheduler.php | 9 +++++---- lib/Subscribers/ImportExport/Import/Import.php | 2 ++ lib/Subscribers/ImportExport/Import/MailChimp.php | 5 ++++- 6 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/API/JSON/v1/Forms.php b/lib/API/JSON/v1/Forms.php index e420f19638..3c74d77a4b 100644 --- a/lib/API/JSON/v1/Forms.php +++ b/lib/API/JSON/v1/Forms.php @@ -172,6 +172,7 @@ class Forms extends APIEndpoint { // check if the user gets to pick his own lists // or if it's selected by the admin $has_segment_selection = false; + $list_selection = []; foreach($body as $i => $block) { if($block['type'] === 'segment') { $has_segment_selection = true; diff --git a/lib/Cron/Workers/SendingQueue/Migration.php b/lib/Cron/Workers/SendingQueue/Migration.php index 657debea80..38fda2a5dc 100644 --- a/lib/Cron/Workers/SendingQueue/Migration.php +++ b/lib/Cron/Workers/SendingQueue/Migration.php @@ -24,6 +24,9 @@ class Migration extends SimpleWorker { function prepareTask(ScheduledTask $task) { $unmigrated_columns = self::checkUnmigratedColumnsExist(); + $unmigrated_queues_count = 0; + $unmigrated_queue_subscribers = []; + if($unmigrated_columns) { $unmigrated_queues_count = $this->getUnmigratedQueues()->count(); $unmigrated_queue_subscribers = $this->getTaskIdsForUnmigratedSubscribers(); diff --git a/lib/Form/Block/Html.php b/lib/Form/Block/Html.php index 3fc2b75eac..c13b892d6c 100644 --- a/lib/Form/Block/Html.php +++ b/lib/Form/Block/Html.php @@ -5,6 +5,7 @@ class Html { static function render($block) { $html = ''; + $text = ''; if(isset($block['params']['text']) && $block['params']['text']) { $text = html_entity_decode($block['params']['text'], ENT_QUOTES); diff --git a/lib/Newsletter/Scheduler/Scheduler.php b/lib/Newsletter/Scheduler/Scheduler.php index 81b72a5b93..5be6366c1d 100644 --- a/lib/Newsletter/Scheduler/Scheduler.php +++ b/lib/Newsletter/Scheduler/Scheduler.php @@ -147,7 +147,7 @@ class Scheduler { } 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.type', Newsletter::TYPE_NOTIFICATION_HISTORY) ->where('newsletters.status', Newsletter::STATUS_SENDING) @@ -194,9 +194,6 @@ class Scheduler { $newsletter->nthWeekDay : '#' . $newsletter->nthWeekDay; switch($interval_type) { - case self::INTERVAL_IMMEDIATELY: - $schedule = '* * * * *'; - break; case self::INTERVAL_IMMEDIATE: case self::INTERVAL_DAILY: $schedule = sprintf('0 %s * * *', $hour); @@ -210,6 +207,10 @@ class Scheduler { case self::INTERVAL_MONTHLY: $schedule = sprintf('0 %s %s * *', $hour, $month_day); break; + case self::INTERVAL_IMMEDIATELY: + default: + $schedule = '* * * * *'; + break; } $option_field = NewsletterOptionField::where('name', 'schedule')->findOne(); $relation = NewsletterOption::where('newsletter_id', $newsletter->id) diff --git a/lib/Subscribers/ImportExport/Import/Import.php b/lib/Subscribers/ImportExport/Import/Import.php index c531d894af..27ebbdeec0 100644 --- a/lib/Subscribers/ImportExport/Import/Import.php +++ b/lib/Subscribers/ImportExport/Import/Import.php @@ -194,6 +194,7 @@ class Import { } function transformSubscribersData($subscribers, $columns) { + $transformed_subscribers = []; foreach($columns as $column => $data) { $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')); // create a new two-dimensional associative array with existing subscribers ($existing_subscribers) // and reduce $subscribers_data to only new subscribers by removing existing subscribers + $existing_subscribers = []; $subscribers_emails = array_flip($subscribers_data['email']); foreach($temp_existing_subscribers as $temp_existing_subscriber) { $existing_subscriber_key = $subscribers_emails[$temp_existing_subscriber['email']]; diff --git a/lib/Subscribers/ImportExport/Import/MailChimp.php b/lib/Subscribers/ImportExport/Import/MailChimp.php index 389d588a14..c917fd4223 100644 --- a/lib/Subscribers/ImportExport/Import/MailChimp.php +++ b/lib/Subscribers/ImportExport/Import/MailChimp.php @@ -45,6 +45,7 @@ class MailChimp { return $this->throwException('API'); } + $lists = []; foreach($response->data as $list) { $lists[] = array( 'id' => $list->id, @@ -65,6 +66,8 @@ class MailChimp { } $bytes_fetched = 0; + $subscribers = []; + $header = []; foreach($lists as $list) { $url = sprintf($this->export_url, $this->data_center, $this->api_key, $list); $connection = @fopen($url, 'r'); @@ -72,7 +75,6 @@ class MailChimp { return $this->throwException('connection'); } $i = 0; - $header = array(); while(!feof($connection)) { $buffer = fgets($connection, 4096); if(trim($buffer) !== '') { @@ -124,6 +126,7 @@ class MailChimp { } function throwException($error) { + $errorMessage = __('Unknown MailChimp error message.', 'mailpoet'); switch($error) { case 'API': $errorMessage = __('Invalid API Key.', 'mailpoet');