diff --git a/mailpoet/lib/Config/MP2Migrator.php b/mailpoet/lib/Config/MP2Migrator.php deleted file mode 100644 index 134bab91df..0000000000 --- a/mailpoet/lib/Config/MP2Migrator.php +++ /dev/null @@ -1,1197 +0,0 @@ -defineMP2Tables(); - $logFilename = 'mp2migration.log'; - $this->logFile = Env::$tempPath . '/' . $logFilename; - $this->logFileUrl = Env::$tempUrl . '/' . $logFilename; - $this->progressbar = new ProgressBar('mp2migration'); - $this->settings = $settings; - $this->activator = $activator; - $this->formsRepository = $formsRepository; - } - - private function defineMP2Tables() { - global $wpdb; - - $this->mp2CampaignTable = defined('MP2_CAMPAIGN_TABLE') - ? MP2_CAMPAIGN_TABLE - : $wpdb->prefix . 'wysija_campaign'; - - $this->mp2CustomFieldTable = defined('MP2_CUSTOM_FIELD_TABLE') - ? MP2_CUSTOM_FIELD_TABLE - : $wpdb->prefix . 'wysija_custom_field'; - - $this->mp2EmailTable = defined('MP2_EMAIL_TABLE') - ? MP2_EMAIL_TABLE - : $wpdb->prefix . 'wysija_email'; - - $this->mp2FormTable = defined('MP2_FORM_TABLE') - ? MP2_FORM_TABLE - : $wpdb->prefix . 'wysija_form'; - - $this->mp2ListTable = defined('MP2_LIST_TABLE') - ? MP2_LIST_TABLE - : $wpdb->prefix . 'wysija_list'; - - $this->mp2UserTable = defined('MP2_USER_TABLE') - ? MP2_USER_TABLE - : $wpdb->prefix . 'wysija_user'; - - $this->mp2UserListTable = defined('MP2_USER_LIST_TABLE') - ? MP2_USER_LIST_TABLE - : $wpdb->prefix . 'wysija_user_list'; - } - - /** - * Test if the migration is already started but is not completed - * - * @return bool - */ - public function isMigrationStartedAndNotCompleted() { - return $this->settings->get(self::MIGRATION_STARTED_SETTING_KEY, false) - && !$this->settings->get(self::MIGRATION_COMPLETE_SETTING_KEY, false); - } - - /** - * Test if the migration is needed - * - * @return bool - */ - public function isMigrationNeeded() { - if ($this->settings->get(self::MIGRATION_COMPLETE_SETTING_KEY)) { - return false; - } else { - return $this->tableExists($this->mp2CampaignTable); // Check if the MailPoet 2 tables exist - } - } - - /** - * Store the "Skip import" choice - * - */ - public function skipImport() { - $this->settings->set(self::MIGRATION_COMPLETE_SETTING_KEY, true); - } - - /** - * Test if a table exists - * - * @param string $table Table name - * @return bool - */ - private function tableExists($table) { - global $wpdb; - - try { - $sql = $wpdb->prepare("SHOW TABLES LIKE %s", $table); - $result = $wpdb->query($sql); - return !empty($result); - } catch (\Exception $e) { - // Do nothing - } - - return false; - } - - /** - * Initialize the migration page - * - */ - public function init() { - if (!$this->settings->get(self::MIGRATION_STARTED_SETTING_KEY, false)) { - $this->emptyLog(); - $this->progressbar->setTotalCount(0); - } - $this->enqueueScripts(); - } - - /** - * Register the JavaScript for the admin area. - * - */ - private function enqueueScripts() { - WPFunctions::get()->wpEnqueueScript('jquery-ui-progressbar'); - } - - /** - * Write a message in the log file - * - * @param string $message - */ - private function log($message) { - file_put_contents($this->logFile, "$message\n", FILE_APPEND); - } - - /** - * Import the data from MailPoet 2 - * - * @return string Result - */ - public function import() { - if (strpos((string)@ini_get('disable_functions'), 'set_time_limit') === false) { - @set_time_limit(3600); - } - ob_start(); - $datetime = new \MailPoet\WP\DateTime(); - $this->log(sprintf('=== ' . mb_strtoupper(__('Start import', 'mailpoet'), 'UTF-8') . ' %s ===', $datetime->formatTime(time(), \MailPoet\WP\DateTime::DEFAULT_DATE_TIME_FORMAT))); - $this->settings->set('import_stopped', false); // Reset the stop import action - - if (!$this->settings->get(self::MIGRATION_STARTED_SETTING_KEY, false)) { - $this->eraseMP3Data(); - $this->settings->set(self::MIGRATION_STARTED_SETTING_KEY, true); - $this->displayDataToMigrate(); - } - - $this->loadDoubleOptinSettings(); - - $this->importSegments(); - $this->importCustomFields(); - $this->importSubscribers(); - $this->importForms(); - $this->importSettings(); - - if (!$this->importStopped()) { - $this->settings->set(self::MIGRATION_COMPLETE_SETTING_KEY, true); - $this->log(mb_strtoupper(__('Import complete', 'mailpoet'), 'UTF-8')); - $afterMigrationNotice = new AfterMigrationNotice(); - $afterMigrationNotice->enable(); - } - - $this->log(sprintf('=== ' . mb_strtoupper(__('End import', 'mailpoet'), 'UTF-8') . ' %s ===', $datetime->formatTime(time(), \MailPoet\WP\DateTime::DEFAULT_DATE_TIME_FORMAT))); - $result = ob_get_contents(); - ob_clean(); - return (string)$result; - } - - /** - * Empty the log file - * - */ - private function emptyLog() { - file_put_contents($this->logFile, ''); - } - - /** - * Erase all the MailPoet 3 data - * - */ - private function eraseMP3Data() { - $this->activator->deactivate(); - $this->activator->activate(); - - $this->deleteSegments(); - $this->resetMigrationCounters(); - $this->log(__("MailPoet data erased", 'mailpoet')); - } - - /** - * Reset the migration counters - * - */ - private function resetMigrationCounters() { - $this->settings->set('last_imported_user_id', 0); - $this->settings->set('last_imported_list_id', 0); - $this->settings->set('last_imported_form_id', 0); - } - - private function loadDoubleOptinSettings() { - $encodedOption = WPFunctions::get()->getOption('wysija'); - $values = unserialize(base64_decode($encodedOption)); - if (isset($values['confirm_dbleoptin']) && $values['confirm_dbleoptin'] === '0') { - $this->doubleOptinEnabled = false; - } - } - - /** - * Delete the existing segments except the wp_users and woocommerce_users segments - * - */ - private function deleteSegments() { - global $wpdb; - - $table = MP_SEGMENTS_TABLE; - $wpdb->query("DELETE FROM {$table} WHERE type != '" . Segment::TYPE_WP_USERS . "' AND type != '" . Segment::TYPE_WC_USERS . "'"); - } - - /** - * Stop the import - * - */ - public function stopImport() { - $this->settings->set('import_stopped', true); - $this->log(mb_strtoupper(__('Import stopped by user', 'mailpoet'), 'UTF-8')); - } - - /** - * Test if the import must stop - * - * @return bool Import must stop or not - */ - private function importStopped() { - return $this->settings->get('import_stopped', false); - } - - /** - * Display the number of data to migrate - * - */ - private function displayDataToMigrate() { - $data = $this->getDataToMigrateAndResetProgressBar(); - $this->log($data); - } - - /** - * Get the data to migrate - * - * @return string Data to migrate - */ - private function getDataToMigrateAndResetProgressBar() { - $result = ''; - $totalCount = 0; - - $this->progressbar->setTotalCount(0); - - $result .= __('MailPoet 2 data found:', 'mailpoet') . "\n"; - - // User Lists - $usersListsCount = ORM::for_table($this->mp2ListTable)->count(); - $totalCount += $usersListsCount; - // translators: %d is the number of lists. - $result .= sprintf(_n('%d subscribers list', '%d subscribers lists', $usersListsCount, 'mailpoet'), $usersListsCount) . "\n"; - - // Users - $usersCount = ORM::for_table($this->mp2UserTable)->count(); - $totalCount += $usersCount; - // translators: %d is the number of subscribers. - $result .= sprintf(_n('%d subscriber', '%d subscribers', $usersCount, 'mailpoet'), $usersCount) . "\n"; - - // Forms - $formsCount = ORM::for_table($this->mp2FormTable)->count(); - $totalCount += $formsCount; - // translators: %d is the number of forms. - $result .= sprintf(_n('%d form', '%d forms', $formsCount, 'mailpoet'), $formsCount) . "\n"; - - $this->progressbar->setTotalCount($totalCount); - - return $result; - } - - /** - * Import the subscribers segments - * - */ - private function importSegments() { - $importedSegmentsCount = 0; - if ($this->importStopped()) { - $this->segmentsMapping = $this->getImportedMapping('segments'); - return; - } - $this->log(__("Importing segments...", 'mailpoet')); - do { - if ($this->importStopped()) { - break; - } - $lists = $this->getLists(self::CHUNK_SIZE); - $listsCount = count($lists); - - if (is_array($lists)) { - foreach ($lists as $list) { - $segment = $this->importSegment($list); - if (!empty($segment)) { - $importedSegmentsCount++; - } - } - } - $this->progressbar->incrementCurrentCount($listsCount); - } while (($lists != null) && ($listsCount > 0)); - - $this->segmentsMapping = $this->getImportedMapping('segments'); - - // translators: %d is the number of segments imported. - $this->log(sprintf(_n("%d segment imported", "%d segments imported", $importedSegmentsCount, 'mailpoet'), $importedSegmentsCount)); - } - - /** - * Get the Mailpoet 2 users lists - * - * @global object $wpdb - * @param int $limit Number of users max - * @return array Users Lists - */ - private function getLists($limit) { - global $wpdb; - - $lastId = intval($this->settings->get('last_imported_list_id', 0)); - $table = esc_sql($this->mp2ListTable); - $sql = $wpdb->prepare(" - SELECT l.list_id, l.name, l.description, l.is_enabled, l.created_at - FROM `$table` l - WHERE l.list_id > %s - ORDER BY l.list_id - LIMIT %d - ", $lastId, $limit); - $lists = $wpdb->get_results($sql, ARRAY_A); - - return $lists; - } - - /** - * Import a segment - * - * @param array $listData List data - * @return Segment - */ - private function importSegment($listData) { - $datetime = new \MailPoet\WP\DateTime(); - if ($listData['is_enabled']) { - $segment = Segment::createOrUpdate([ - 'name' => $listData['name'], - 'type' => 'default', - 'description' => !empty($listData['description']) ? $listData['description'] : '', - 'created_at' => $datetime->formatTime($listData['created_at'], \MailPoet\WP\DateTime::DEFAULT_DATE_TIME_FORMAT), - ]); - } else { - $segment = Segment::getWPSegment(); - } - if (!empty($segment)) { - // Map the segment with its old ID - $mapping = new MappingToExternalEntities(); - $mapping->create([ - 'old_id' => $listData['list_id'], - 'type' => 'segments', - 'new_id' => $segment->id, - 'created_at' => $datetime->formatTime(time(), \MailPoet\WP\DateTime::DEFAULT_DATE_TIME_FORMAT), - ]); - } - $this->settings->set('last_imported_list_id', $listData['list_id']); - return $segment; - } - - /** - * Import the custom fields - * - */ - private function importCustomFields() { - $importedCustomFieldsCount = 0; - if ($this->importStopped()) { - return; - } - $this->log(__("Importing custom fields...", 'mailpoet')); - $customFields = $this->getCustomFields(); - - foreach ($customFields as $customField) { - $result = $this->importCustomField($customField); - if (!empty($result)) { - $importedCustomFieldsCount++; - } - } - - // translators: %d is the number of custom fields imported. - $this->log(sprintf(_n("%d custom field imported", "%d custom fields imported", $importedCustomFieldsCount, 'mailpoet'), $importedCustomFieldsCount)); - } - - /** - * Get the Mailpoet 2 custom fields - * - * @global object $wpdb - * @return array Custom fields - */ - private function getCustomFields() { - global $wpdb; - $customFields = []; - - $table = esc_sql($this->mp2CustomFieldTable); - $sql = " - SELECT cf.id, cf.name, cf.type, cf.required, cf.settings - FROM `$table` cf - "; - $customFields = $wpdb->get_results($sql, ARRAY_A); - - return $customFields; - } - - /** - * Import a custom field - * - * @param array $customField MP2 custom field - * @return CustomField - */ - private function importCustomField($customField) { - $data = [ - 'id' => $customField['id'], - 'name' => $customField['name'], - 'type' => $this->mapCustomFieldType($customField['type']), - 'params' => $this->mapCustomFieldParams($customField['name'], unserialize($customField['settings'])), - ]; - $customField = new CustomField(); - $customField->createOrUpdate($data); - return $customField; - } - - /** - * Map the MailPoet 2 custom field type with the MailPoet custom field type - * - * @param string $mp2Type MP2 custom field type - * @return string MP3 custom field type - */ - private function mapCustomFieldType($mp2Type) { - $type = ''; - switch ($mp2Type) { - case 'input': - $type = 'text'; - break; - case 'list': - $type = 'segment'; - break; - default: - $type = $mp2Type; - } - return $type; - } - - /** - * Map the MailPoet 2 custom field settings with the MailPoet custom field params - * - * @param string $name Parameter name - * @param array $params MP2 parameters - * @return array serialized MP3 custom field params - */ - private function mapCustomFieldParams($name, $params) { - if (!isset($params['label'])) { - $params['label'] = $name; - } - if (isset($params['required'])) { - $params['required'] = (bool)$params['required']; - } - if (isset($params['validate'])) { - $params['validate'] = $this->mapCustomFieldValidateValue($params['validate']); - } - if (isset($params['date_order'])) { // Convert the date_order field - switch ($params['date_type']) { - - case 'year_month': - if (preg_match('/y$/i', $params['date_order'])) { - $params['date_format'] = 'MM/YYYY'; - } else { - $params['date_format'] = 'YYYY/MM'; - } - break; - - case 'month'; - $params['date_format'] = 'MM'; - break; - - case 'year'; - $params['date_format'] = 'YYYY'; - break; - - default: - $params['date_format'] = mb_strtoupper($params['date_order'], 'UTF-8'); - } - unset($params['date_order']); - } - return $params; - } - - /** - * Map the validate value - * - * @param string $mp2Value MP2 value - * @return string MP3 value - */ - private function mapCustomFieldValidateValue($mp2Value) { - $value = ''; - switch ($mp2Value) { - case 'onlyLetterSp': - case 'onlyLetterNumber': - $value = 'alphanum'; - break; - case 'onlyNumberSp': - $value = 'number'; - break; - case 'phone': - $value = 'phone'; - break; - } - return $value; - } - - /** - * Import the subscribers - * - */ - private function importSubscribers() { - $importedSubscribersCount = 0; - if ($this->importStopped()) { - return; - } - $this->log(__("Importing subscribers...", 'mailpoet')); - $this->wpUsersSegment = Segment::getWPSegment(); - do { - if ($this->importStopped()) { - break; - } - $users = $this->getUsers(self::CHUNK_SIZE); - $usersCount = count($users); - - if (is_array($users)) { - foreach ($users as $user) { - $subscriber = $this->importSubscriber($user); - if (!empty($subscriber)) { - $importedSubscribersCount++; - $this->importSubscriberSegments($subscriber, $user['user_id']); - $this->importSubscriberCustomFields($subscriber, $user); - } - } - } - $this->progressbar->incrementCurrentCount($usersCount); - } while (($users != null) && ($usersCount > 0)); - - // translators: %d is the number of subscribers imported. - $this->log(sprintf(_n("%d subscriber imported", "%d subscribers imported", $importedSubscribersCount, 'mailpoet'), $importedSubscribersCount)); - } - - /** - * Get the Mailpoet 2 users - * - * @global object $wpdb - * @param int $limit Number of users max - * @return array Users - */ - private function getUsers($limit) { - global $wpdb; - $lastId = intval($this->settings->get('last_imported_user_id', 0)); - $table = esc_sql($this->mp2UserTable); - $sql = $wpdb->prepare(" - SELECT u.* - FROM `$table` u - WHERE u.user_id > %s - ORDER BY u.user_id - LIMIT %d - ", $lastId, $limit); - $users = $wpdb->get_results($sql, ARRAY_A); - - return $users; - } - - /** - * Import a subscriber - * - * @param array $userData User data - * @return Subscriber - */ - private function importSubscriber($userData) { - $datetime = new \MailPoet\WP\DateTime(); - $subscriber = Subscriber::createOrUpdate([ - 'wp_user_id' => !empty($userData['wpuser_id']) ? $userData['wpuser_id'] : null, - 'email' => $userData['email'], - 'first_name' => $userData['firstname'], - 'last_name' => $userData['lastname'], - 'status' => $this->mapUserStatus($userData['status']), - 'created_at' => $datetime->formatTime($userData['created_at'], \MailPoet\WP\DateTime::DEFAULT_DATE_TIME_FORMAT), - 'subscribed_ip' => !empty($userData['ip']) ? $userData['ip'] : null, - 'confirmed_ip' => !empty($userData['confirmed_ip']) ? $userData['confirmed_ip'] : null, - 'confirmed_at' => !empty($userData['confirmed_at']) ? $datetime->formatTime($userData['confirmed_at'], \MailPoet\WP\DateTime::DEFAULT_DATE_TIME_FORMAT) : null, - ]); - $this->settings->set('last_imported_user_id', $userData['user_id']); - if (!empty($subscriber)) { - // Map the subscriber with its old ID - $mapping = new MappingToExternalEntities(); - $mapping->create([ - 'old_id' => $userData['user_id'], - 'type' => 'subscribers', - 'new_id' => $subscriber->id, - 'created_at' => $datetime->formatTime(time(), \MailPoet\WP\DateTime::DEFAULT_DATE_TIME_FORMAT), - ]); - } - return $subscriber; - } - - /** - * Map the MailPoet 2 user status with MailPoet 3 - * - * @param int $mp2UserStatus MP2 user status - * @return string MP3 user status - */ - private function mapUserStatus($mp2UserStatus) { - - - switch ($mp2UserStatus) { - case 1: - $status = 'subscribed'; - break; - case -1: - $status = 'unsubscribed'; - break; - case 0: - default: - //if MP2 double-optin is disabled, we change "unconfirmed" status in MP2 to "confirmed" status in MP3. - if (!$this->doubleOptinEnabled) { - $status = 'subscribed'; - } else { - $status = 'unconfirmed'; - } - } - return $status; - } - - /** - * Import the segments for a subscriber - * - * @param Subscriber $subscriber MP3 subscriber - * @param int $userId MP2 user ID - */ - private function importSubscriberSegments($subscriber, $userId) { - $userLists = $this->getUserLists($userId); - foreach ($userLists as $userList) { - $this->importSubscriberSegment($subscriber->id, $userList); - } - } - - /** - * Get the lists for a user - * - * @global object $wpdb - * @param int $userId User ID - * @return array Users Lists - */ - private function getUserLists($userId) { - global $wpdb; - - $table = esc_sql($this->mp2UserListTable); - $sql = $wpdb->prepare(" - SELECT ul.list_id, ul.sub_date, ul.unsub_date - FROM `$table` ul - WHERE ul.user_id = %s - ", $userId); - $userLists = $wpdb->get_results($sql, ARRAY_A); - - return $userLists; - } - - /** - * Import a subscriber segment - * - * @param int $subscriberId - * @param array $userList - * @return SubscriberSegment|null - */ - private function importSubscriberSegment($subscriberId, $userList) { - $subscriberSegment = null; - $datetime = new \MailPoet\WP\DateTime(); - if (isset($this->segmentsMapping[$userList['list_id']])) { - $segmentId = $this->segmentsMapping[$userList['list_id']]; - $status = (($segmentId == $this->wpUsersSegment->id) || empty($userList['unsub_date'])) ? 'subscribed' : 'unsubscribed'; // the users belonging to the wp_users segment are always subscribed - $data = [ - 'subscriber_id' => $subscriberId, - 'segment_id' => $segmentId, - 'status' => $status, - 'created_at' => $datetime->formatTime($userList['sub_date'], \MailPoet\WP\DateTime::DEFAULT_DATE_TIME_FORMAT), - ]; - $data['updated_at'] = !empty($userList['unsub_date']) ? $datetime->formatTime($userList['unsub_date'], \MailPoet\WP\DateTime::DEFAULT_DATE_TIME_FORMAT) : $data['created_at']; - $subscriberSegment = new SubscriberSegment(); - $subscriberSegment->createOrUpdate($data); - } - return $subscriberSegment; - } - - /** - * Import the custom fields values for a subscriber - * - * @param Subscriber $subscriber MP3 subscriber - * @param array $user MP2 user - */ - private function importSubscriberCustomFields($subscriber, $user) { - $importedCustomFields = $this->getImportedCustomFields(); - foreach ($importedCustomFields as $customField) { - $customFieldColumn = 'cf_' . $customField['id']; - $this->importSubscriberCustomField($subscriber->id, $customField, $user[$customFieldColumn]); - } - } - - /** - * Get the imported custom fields - * - * @global object $wpdb - * @return array Imported custom fields - * - */ - private function getImportedCustomFields() { - global $wpdb; - $table = MP_CUSTOM_FIELDS_TABLE; - $sql = " - SELECT cf.id, cf.name, cf.type - FROM `$table` cf - "; - $customFields = $wpdb->get_results($sql, ARRAY_A); - return $customFields; - } - - /** - * Import a subscriber custom field - * - * @param int $subscriberId Subscriber ID - * @param array $customField Custom field - * @param string $customFieldValue Custom field value - * @return SubscriberCustomField - */ - private function importSubscriberCustomField($subscriberId, $customField, $customFieldValue) { - if ($customField['type'] == 'date') { - $datetime = new \MailPoet\WP\DateTime(); - $value = $datetime->formatTime($customFieldValue, \MailPoet\WP\DateTime::DEFAULT_DATE_TIME_FORMAT); // Convert the date field - } else { - $value = $customFieldValue; - } - $data = [ - 'subscriber_id' => $subscriberId, - 'custom_field_id' => $customField['id'], - 'value' => isset($value) ? $value : '', - ]; - $subscriberCustomField = new SubscriberCustomField(); - $subscriberCustomField->createOrUpdate($data); - return $subscriberCustomField; - } - - /** - * Get the mapping between the MP2 and the imported MP3 IDs - * - * @param string $model Model (segment,...) - * @return array Mapping - */ - public function getImportedMapping($model) { - $mappings = []; - $mappingRelations = MappingToExternalEntities::where('type', $model)->findArray(); - foreach ($mappingRelations as $relation) { - $mappings[$relation['old_id']] = $relation['new_id']; - } - return $mappings; - } - - /** - * Import the forms - * - */ - private function importForms() { - $importedFormsCount = 0; - if ($this->importStopped()) { - return; - } - $this->log(__("Importing forms...", 'mailpoet')); - do { - if ($this->importStopped()) { - break; - } - $forms = $this->getForms(self::CHUNK_SIZE); - $formsCount = count($forms); - - if (is_array($forms)) { - foreach ($forms as $form) { - $this->importForm($form); - $importedFormsCount++; - } - } - $this->formsRepository->flush(); - $this->progressbar->incrementCurrentCount($formsCount); - } while (($forms != null) && ($formsCount > 0)); - - // translators: %d is the number of forms imported. - $this->log(sprintf(_n("%d form imported", "%d forms imported", $importedFormsCount, 'mailpoet'), $importedFormsCount)); - } - - /** - * Get the Mailpoet 2 forms - * - * @global object $wpdb - * @param int $limit Number of forms max - * @return array Forms - */ - private function getForms($limit) { - global $wpdb; - - $lastId = intval($this->settings->get('last_imported_form_id', 0)); - $table = esc_sql($this->mp2FormTable); - $sql = $wpdb->prepare(" - SELECT f.* - FROM `$table` f - WHERE f.form_id > %s - ORDER BY f.form_id - LIMIT %d - ", $lastId, $limit); - $forms = $wpdb->get_results($sql, ARRAY_A); - - return $forms; - } - - /** - * Import a form - * - * @param array $formData Form data - */ - private function importForm($formData) { - $serializedData = base64_decode($formData['data']); - $data = unserialize($serializedData); - $settings = $data['settings']; - $body = $data['body']; - $segments = $this->getMappedSegmentIds($settings['lists']); - $mp3FormSettings = [ - 'on_success' => $settings['on_success'], - 'success_message' => $settings['success_message'], - 'segments_selected_by' => $settings['lists_selected_by'], - 'segments' => $segments, - ]; - - $mp3FormBody = []; - foreach ($body as $field) { - $type = $this->mapCustomFieldType($field['type']); - if ($type == 'segment') { - $fieldId = 'segments'; - } else { - switch ($field['field']) { - case 'firstname': - $fieldId = 'first_name'; - break; - case 'lastname': - $fieldId = 'last_name'; - break; - default: - $fieldId = $field['field']; - } - } - $fieldId = preg_replace('/^cf_(\d+)$/', '$1', $fieldId); - $params = $this->mapCustomFieldParams($field['name'], $field['params']); - if (isset($params['text'])) { - $params['text'] = $this->replaceMP2Shortcodes(html_entity_decode($params['text'])); - } - if (isset($params['values'])) { - $params['values'] = $this->replaceListIds($params['values']); - } - $mp3FormBody[] = [ - 'type' => $type, - 'name' => $field['name'], - 'id' => $fieldId, - 'unique' => !in_array($field['type'], ['html', 'divider', 'email', 'submit']) ? "1" : "0", - 'static' => in_array($fieldId, ['email', 'submit']) ? "1" : "0", - 'params' => $params, - 'position' => isset($field['position']) ? $field['position'] : '', - ]; - } - - $form = new FormEntity($formData['name']); - $form->setBody($mp3FormBody); - $form->setSettings($mp3FormSettings); - - $this->formsRepository->persist($form); - - $this->settings->set('last_imported_form_id', $formData['form_id']); - } - - /** - * Get the MP3 segments IDs of the MP2 lists IDs - * - * @param array $mp2ListIds - */ - private function getMappedSegmentIds($mp2ListIds) { - $mp3SegmentIds = []; - foreach ($mp2ListIds as $listId) { - if (isset($this->segmentsMapping[$listId])) { - $mp3SegmentIds[] = $this->segmentsMapping[$listId]; - } - } - return $mp3SegmentIds; - } - - /** - * Replace the MP2 shortcodes used in the textarea fields - * - * @param string $text Text - * @return string|null Text - */ - private function replaceMP2Shortcodes($text) { - $text = str_replace('[total_subscribers]', '[mailpoet_subscribers_count]', $text); - $text = preg_replace_callback( - '/\[wysija_subscribers_count list_id="(.*)" \]/', - function ($matches) { - return $this->replaceMP2ShortcodesCallback($matches); - }, - $text - ); - return $text; - } - - /** - * Callback function for MP2 shortcodes replacement - * - * @param array $matches PREG matches - * @return string Replacement - */ - private function replaceMP2ShortcodesCallback($matches) { - if (!empty($matches)) { - $mp2Lists = explode(',', $matches[1]); - $segments = $this->getMappedSegmentIds($mp2Lists); - $segmentsIds = implode(',', $segments); - return '[mailpoet_subscribers_count segments=' . $segmentsIds . ']'; - } - return ''; - } - - /** - * Replace the MP2 list IDs by MP3 segment IDs - * - * @param array $values Field values - * @return array Field values - */ - private function replaceListIds($values) { - $mp3Values = []; - foreach ($values as $value) { - $mp3Value = []; - foreach ($value as $item => $itemValue) { - if (($item == 'list_id') && isset($this->segmentsMapping[$itemValue])) { - $segmentId = $this->segmentsMapping[$itemValue]; - $mp3Value['id'] = $segmentId; - $segment = Segment::findOne($segmentId); - if ($segment instanceof Segment) { - $mp3Value['name'] = $segment->get('name'); - } - } else { - $mp3Value[$item] = $itemValue; - } - } - if (!empty($mp3Value)) { - $mp3Values[] = $mp3Value; - } - } - return $mp3Values; - } - - /** - * Import the settings - * - */ - private function importSettings() { - $encodedOptions = WPFunctions::get()->getOption('wysija'); - $options = unserialize(base64_decode($encodedOptions)); - - // Sender - $sender = $this->settings->get('sender'); - $sender['name'] = isset($options['from_name']) ? $options['from_name'] : ''; - $sender['address'] = isset($options['from_email']) ? $options['from_email'] : ''; - $this->settings->set('sender', $sender); - - // Reply To - $replyTo = $this->settings->get('reply_to'); - $replyTo['name'] = isset($options['replyto_name']) ? $options['replyto_name'] : ''; - $replyTo['address'] = isset($options['replyto_email']) ? $options['replyto_email'] : ''; - $this->settings->set('reply_to', $replyTo); - - // Bounce - $bounce = $this->settings->get('bounce'); - $bounce['address'] = isset($options['bounce_email']) && WPFunctions::get()->isEmail($options['bounce_email']) ? $options['bounce_email'] : ''; - $this->settings->set('bounce', $bounce); - - // Notification - $notification = $this->settings->get('notification'); - $notification['address'] = isset($options['emails_notified']) ? $options['emails_notified'] : ''; - $this->settings->set('notification', $notification); - - // Subscribe - $subscribe = $this->settings->get('subscribe'); - $subscribe['on_comment']['enabled'] = isset($options['commentform']) ? $options['commentform'] : '0'; - $subscribe['on_comment']['label'] = isset($options['commentform_linkname']) ? $options['commentform_linkname'] : ''; - $subscribe['on_comment']['segments'] = isset($options['commentform_lists']) ? $this->getMappedSegmentIds($options['commentform_lists']) : []; - $subscribe['on_register']['enabled'] = isset($options['registerform']) ? $options['registerform'] : '0'; - $subscribe['on_register']['label'] = isset($options['registerform_linkname']) ? $options['registerform_linkname'] : ''; - $subscribe['on_register']['segments'] = isset($options['registerform_lists']) ? $this->getMappedSegmentIds($options['registerform_lists']) : []; - $this->settings->set('subscribe', $subscribe); - - // Subscription - $subscription = $this->settings->get('subscription'); - $subscription['pages']['unsubscribe'] = isset($options['unsubscribe_page']) ? $options['unsubscribe_page'] : ''; - $subscription['pages']['confirmation'] = isset($options['confirmation_page']) ? $options['confirmation_page'] : ''; - $subscription['pages']['manage'] = isset($options['subscriptions_page']) ? $options['subscriptions_page'] : ''; - $subscription['segments'] = isset($options['manage_subscriptions_lists']) ? $this->getMappedSegmentIds($options['manage_subscriptions_lists']) : []; - $this->settings->set('subscription', $subscription); - - // Confirmation email - $signupConfirmation = $this->settings->get('signup_confirmation'); - $signupConfirmation['enabled'] = isset($options['confirm_dbleoptin']) && ($options['confirm_dbleoptin'] == 0) ? 0 : 1; - if (isset($options['confirm_email_id'])) { - $confirmEmailId = $options['confirm_email_id']; - $confirmEmail = $this->getEmail($confirmEmailId); - if (!empty($confirmEmail)) { - $signupConfirmation['subject'] = isset($confirmEmail['subject']) ? $confirmEmail['subject'] : ''; - $signupConfirmation['body'] = isset($confirmEmail['body']) ? $confirmEmail['body'] : ''; - } - } - $this->settings->set('signup_confirmation', $signupConfirmation); - - // Analytics - $analytics = $this->settings->get('analytics'); - $analytics['enabled'] = isset($options['analytics']) ? $options['analytics'] : ''; - $this->settings->set('analytics', $analytics); - - // MTA - $mtaGroup = isset($options['sending_method']) && ($options['sending_method'] == 'smtp') ? 'smtp' : 'website'; - $this->settings->set('mta_group', $mtaGroup); - - $mta = $this->settings->get('mta'); - $mta['method'] = (isset($options['smtp_host']) && ($options['smtp_host'] == 'smtp.sendgrid.net')) ? 'SendGrid' : (isset($options['sending_method']) && ($options['sending_method'] == 'smtp') ? 'SMTP' : 'PHPMail'); - $sendingEmailsNumber = isset($options['sending_emails_number']) ? $options['sending_emails_number'] : ''; - $sendingEmailsEach = isset($options['sending_emails_each']) ? $options['sending_emails_each'] : ''; - $mta['frequency']['emails'] = $this->mapFrequencyEmails($sendingEmailsNumber, $sendingEmailsEach); - $mta['frequency']['interval'] = $this->mapFrequencyInterval($sendingEmailsEach); - $mta['host'] = isset($options['smtp_host']) ? $options['smtp_host'] : ''; - $mta['port'] = isset($options['smtp_port']) ? $options['smtp_port'] : ''; - $mta['login'] = isset($options['smtp_login']) ? $options['smtp_login'] : ''; - $mta['password'] = isset($options['smtp_password']) ? $options['smtp_password'] : ''; - $mta['encryption'] = isset($options['smtp_secure']) ? $options['smtp_secure'] : ''; - $mta['authentication'] = !isset($options['smtp_auth']) ? '1' : '-1'; - $this->settings->set('mta', $mta); - - // SMTP Provider - if ($mta['method'] == 'SendGrid') { - $this->settings->set('smtp_provider', 'SendGrid'); - } - - // Installation date - if (isset($options['installed_time'])) { - $datetime = new \MailPoet\WP\DateTime(); - $installedAt = $datetime->formatTime($options['installed_time'], \MailPoet\WP\DateTime::DEFAULT_DATE_TIME_FORMAT); - $this->settings->set('installed_at', $installedAt); - } - - $this->log(__("Settings imported", 'mailpoet')); - } - - /** - * Get an email - * - * @global object $wpdb - * @param int $emailId - * @return array Email - */ - private function getEmail($emailId) { - global $wpdb; - $email = []; - - $table = esc_sql($this->mp2EmailTable); - $sql = $wpdb->prepare(" - SELECT e.* - FROM `$table` e - WHERE e.email_id = %s - ", $emailId); - $email = $wpdb->get_row($sql, ARRAY_A); - - return $email; - } - - /** - * Map the Email frequency interval - * - * @param string $intervalStr Interval - * @return string Interval - */ - private function mapFrequencyInterval($intervalStr) { - switch ($intervalStr) { - case 'one_min': - $interval = 1; - break; - - case 'two_min': - $interval = 2; - break; - - case 'five_min': - $interval = 5; - break; - - case 'ten_min': - $interval = 10; - break; - - default: - $interval = 15; - } - return (string)$interval; - } - - /** - * Map the Email frequency number - * - * @param int $emailsNumber Emails number - * @param string $intervalStr Interval - * @return int Emails number - */ - private function mapFrequencyEmails($emailsNumber, $intervalStr) { - if (empty($emailsNumber)) { - $emailsNumber = 70; - } else { - switch ($intervalStr) { - case 'thirty_min': - $emailsNumber /= 2; - break; - - case 'hourly': - case '': - $emailsNumber /= 4; - break; - - case 'two_hours': - $emailsNumber /= 8; - break; - } - $emailsNumber = (int)round($emailsNumber); - } - return $emailsNumber; - } -} diff --git a/mailpoet/lib/DI/ContainerConfigurator.php b/mailpoet/lib/DI/ContainerConfigurator.php index 410448ec42..0f95ab5cf0 100644 --- a/mailpoet/lib/DI/ContainerConfigurator.php +++ b/mailpoet/lib/DI/ContainerConfigurator.php @@ -152,7 +152,6 @@ class ContainerConfigurator implements IContainerConfigurator { $container->autowire(\MailPoet\Config\Localizer::class); $container->autowire(\MailPoet\Config\Menu::class)->setPublic(true); $container->autowire(\MailPoet\Config\Migrator::class)->setPublic(true); - $container->autowire(\MailPoet\Config\MP2Migrator::class); $container->autowire(\MailPoet\Config\RendererFactory::class)->setPublic(true); $container->autowire(\MailPoet\Config\ServicesChecker::class)->setPublic(true); $container->autowire(\MailPoet\Config\Router::class)->setPublic(true); diff --git a/mailpoet/tasks/phpstan/phpstan-7-baseline.neon b/mailpoet/tasks/phpstan/phpstan-7-baseline.neon index c480439282..c74afda2c4 100644 --- a/mailpoet/tasks/phpstan/phpstan-7-baseline.neon +++ b/mailpoet/tasks/phpstan/phpstan-7-baseline.neon @@ -146,276 +146,6 @@ parameters: count: 1 path: ../../lib/Config/Hooks.php - - - message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'analytics' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'body' on mixed\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'bounce_email' on mixed\\.$#" - count: 3 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'commentform' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'commentform_linkname' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'commentform_lists' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'confirm_dbleoptin' on mixed\\.$#" - count: 4 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'confirm_email_id' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'confirmation_page' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'emails_notified' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'field' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'from_email' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'from_name' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'installed_time' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'lists' on mixed\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'lists_selected_by' on mixed\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'manage…' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'name' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'on_success' on mixed\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'params' on mixed\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'position' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'registerform' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'registerform_lists' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'registerform…' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'replyto_email' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'replyto_name' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'sending_emails_each' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'sending_emails…' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'sending_method' on mixed\\.$#" - count: 4 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'settings' on mixed\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'smtp_auth' on mixed\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'smtp_host' on mixed\\.$#" - count: 4 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'smtp_login' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'smtp_password' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'smtp_port' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'smtp_secure' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'subscriptions_page' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'success_message' on mixed\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'type' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'unsubscribe_page' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^If condition is always false\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#1 \\$emailId of method MailPoet\\\\Config\\\\MP2Migrator\\:\\:getEmail\\(\\) expects int, mixed given\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#1 \\$emailsNumber of method MailPoet\\\\Config\\\\MP2Migrator\\:\\:mapFrequencyEmails\\(\\) expects int, mixed given\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#1 \\$intervalStr of method MailPoet\\\\Config\\\\MP2Migrator\\:\\:mapFrequencyInterval\\(\\) expects string, mixed given\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#1 \\$mp2ListIds of method MailPoet\\\\Config\\\\MP2Migrator\\:\\:getMappedSegmentIds\\(\\) expects array, mixed given\\.$#" - count: 4 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#1 \\$mp2Type of method MailPoet\\\\Config\\\\MP2Migrator\\:\\:mapCustomFieldType\\(\\) expects string, mixed given\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#1 \\$name of method MailPoet\\\\Config\\\\MP2Migrator\\:\\:mapCustomFieldParams\\(\\) expects string, mixed given\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#2 \\$intervalStr of method MailPoet\\\\Config\\\\MP2Migrator\\:\\:mapFrequencyEmails\\(\\) expects string, mixed given\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#2 \\$params of method MailPoet\\\\Config\\\\MP2Migrator\\:\\:mapCustomFieldParams\\(\\) expects array, mixed given\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#3 \\$subject of function preg_replace expects array\\|string, mixed given\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Variable \\$result in empty\\(\\) always exists and is not falsy\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Variable \\$segment in empty\\(\\) always exists and is not falsy\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Variable \\$subscriber in empty\\(\\) always exists and is not falsy\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - message: "#^Cannot access an offset on mixed\\.$#" count: 3 @@ -1461,56 +1191,6 @@ parameters: count: 4 path: ../../tests/integration/API/JSON/v1/ServicesTest.php - - - message: "#^Cannot access offset 'label' on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 'name' on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 'on_success' on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 'required' on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 'segments' on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 'success_message' on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 'type' on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 'validate' on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 0 on mixed\\.$#" - count: 3 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 999 on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - message: "#^Property MailPoet\\\\Test\\\\Doctrine\\\\EventListeners\\\\TimestampEntity\\:\\:\\$id is never written, only read\\.$#" count: 1 diff --git a/mailpoet/tasks/phpstan/phpstan-8-baseline.neon b/mailpoet/tasks/phpstan/phpstan-8-baseline.neon index e1727742b7..34cb9279a0 100644 --- a/mailpoet/tasks/phpstan/phpstan-8-baseline.neon +++ b/mailpoet/tasks/phpstan/phpstan-8-baseline.neon @@ -146,276 +146,6 @@ parameters: count: 1 path: ../../lib/Config/Hooks.php - - - message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'analytics' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'body' on mixed\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'bounce_email' on mixed\\.$#" - count: 3 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'commentform' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'commentform_linkname' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'commentform_lists' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'confirm_dbleoptin' on mixed\\.$#" - count: 4 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'confirm_email_id' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'confirmation_page' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'emails_notified' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'field' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'from_email' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'from_name' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'installed_time' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'lists' on mixed\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'lists_selected_by' on mixed\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'manage…' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'name' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'on_success' on mixed\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'params' on mixed\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'position' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'registerform' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'registerform_lists' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'registerform…' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'replyto_email' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'replyto_name' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'sending_emails_each' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'sending_emails…' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'sending_method' on mixed\\.$#" - count: 4 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'settings' on mixed\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'smtp_auth' on mixed\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'smtp_host' on mixed\\.$#" - count: 4 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'smtp_login' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'smtp_password' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'smtp_port' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'smtp_secure' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'subscriptions_page' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'success_message' on mixed\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'type' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'unsubscribe_page' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^If condition is always false\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#1 \\$emailId of method MailPoet\\\\Config\\\\MP2Migrator\\:\\:getEmail\\(\\) expects int, mixed given\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#1 \\$emailsNumber of method MailPoet\\\\Config\\\\MP2Migrator\\:\\:mapFrequencyEmails\\(\\) expects int, mixed given\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#1 \\$intervalStr of method MailPoet\\\\Config\\\\MP2Migrator\\:\\:mapFrequencyInterval\\(\\) expects string, mixed given\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#1 \\$mp2ListIds of method MailPoet\\\\Config\\\\MP2Migrator\\:\\:getMappedSegmentIds\\(\\) expects array, mixed given\\.$#" - count: 4 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#1 \\$mp2Type of method MailPoet\\\\Config\\\\MP2Migrator\\:\\:mapCustomFieldType\\(\\) expects string, mixed given\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#1 \\$name of method MailPoet\\\\Config\\\\MP2Migrator\\:\\:mapCustomFieldParams\\(\\) expects string, mixed given\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#2 \\$intervalStr of method MailPoet\\\\Config\\\\MP2Migrator\\:\\:mapFrequencyEmails\\(\\) expects string, mixed given\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#2 \\$params of method MailPoet\\\\Config\\\\MP2Migrator\\:\\:mapCustomFieldParams\\(\\) expects array, mixed given\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#3 \\$subject of function preg_replace expects array\\|string, mixed given\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Variable \\$result in empty\\(\\) always exists and is not falsy\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Variable \\$segment in empty\\(\\) always exists and is not falsy\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Variable \\$subscriber in empty\\(\\) always exists and is not falsy\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - message: "#^Cannot access an offset on mixed\\.$#" count: 3 @@ -1466,56 +1196,6 @@ parameters: count: 4 path: ../../tests/integration/API/JSON/v1/ServicesTest.php - - - message: "#^Cannot access offset 'label' on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 'name' on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 'on_success' on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 'required' on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 'segments' on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 'success_message' on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 'type' on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 'validate' on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 0 on mixed\\.$#" - count: 3 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 999 on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - message: "#^Property MailPoet\\\\Test\\\\Doctrine\\\\EventListeners\\\\TimestampEntity\\:\\:\\$id is never written, only read\\.$#" count: 1 diff --git a/mailpoet/tasks/phpstan/phpstan-8.1-baseline.neon b/mailpoet/tasks/phpstan/phpstan-8.1-baseline.neon index 93c9900baf..9e4e40b2ff 100644 --- a/mailpoet/tasks/phpstan/phpstan-8.1-baseline.neon +++ b/mailpoet/tasks/phpstan/phpstan-8.1-baseline.neon @@ -155,276 +155,6 @@ parameters: count: 1 path: ../../lib/Config/Hooks.php - - - message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'analytics' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'body' on mixed\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'bounce_email' on mixed\\.$#" - count: 3 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'commentform' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'commentform_linkname' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'commentform_lists' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'confirm_dbleoptin' on mixed\\.$#" - count: 4 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'confirm_email_id' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'confirmation_page' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'emails_notified' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'field' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'from_email' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'from_name' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'installed_time' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'lists' on mixed\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'lists_selected_by' on mixed\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'manage…' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'name' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'on_success' on mixed\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'params' on mixed\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'position' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'registerform' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'registerform_lists' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'registerform…' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'replyto_email' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'replyto_name' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'sending_emails_each' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'sending_emails…' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'sending_method' on mixed\\.$#" - count: 4 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'settings' on mixed\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'smtp_auth' on mixed\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'smtp_host' on mixed\\.$#" - count: 4 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'smtp_login' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'smtp_password' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'smtp_port' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'smtp_secure' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'subscriptions_page' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'success_message' on mixed\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'type' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Cannot access offset 'unsubscribe_page' on mixed\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^If condition is always false\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#1 \\$emailId of method MailPoet\\\\Config\\\\MP2Migrator\\:\\:getEmail\\(\\) expects int, mixed given\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#1 \\$emailsNumber of method MailPoet\\\\Config\\\\MP2Migrator\\:\\:mapFrequencyEmails\\(\\) expects int, mixed given\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#1 \\$intervalStr of method MailPoet\\\\Config\\\\MP2Migrator\\:\\:mapFrequencyInterval\\(\\) expects string, mixed given\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#1 \\$mp2ListIds of method MailPoet\\\\Config\\\\MP2Migrator\\:\\:getMappedSegmentIds\\(\\) expects array, mixed given\\.$#" - count: 4 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#1 \\$mp2Type of method MailPoet\\\\Config\\\\MP2Migrator\\:\\:mapCustomFieldType\\(\\) expects string, mixed given\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#1 \\$name of method MailPoet\\\\Config\\\\MP2Migrator\\:\\:mapCustomFieldParams\\(\\) expects string, mixed given\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#2 \\$intervalStr of method MailPoet\\\\Config\\\\MP2Migrator\\:\\:mapFrequencyEmails\\(\\) expects string, mixed given\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#2 \\$params of method MailPoet\\\\Config\\\\MP2Migrator\\:\\:mapCustomFieldParams\\(\\) expects array, mixed given\\.$#" - count: 2 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Parameter \\#3 \\$subject of function preg_replace expects array\\|string, mixed given\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Variable \\$result in empty\\(\\) always exists and is not falsy\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Variable \\$segment in empty\\(\\) always exists and is not falsy\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - - - message: "#^Variable \\$subscriber in empty\\(\\) always exists and is not falsy\\.$#" - count: 1 - path: ../../lib/Config/MP2Migrator.php - - message: "#^Cannot access an offset on mixed\\.$#" count: 3 @@ -1495,56 +1225,6 @@ parameters: count: 4 path: ../../tests/integration/API/JSON/v1/ServicesTest.php - - - message: "#^Cannot access offset 'label' on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 'name' on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 'on_success' on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 'required' on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 'segments' on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 'success_message' on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 'type' on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 'validate' on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 0 on mixed\\.$#" - count: 3 - path: ../../tests/integration/Config/MP2MigratorTest.php - - - - message: "#^Cannot access offset 999 on mixed\\.$#" - count: 1 - path: ../../tests/integration/Config/MP2MigratorTest.php - - message: "#^Property MailPoet\\\\Test\\\\Doctrine\\\\EventListeners\\\\TimestampEntity\\:\\:\\$id is never written, only read\\.$#" count: 1 diff --git a/mailpoet/tests/_data/createMP2Tables.sql b/mailpoet/tests/_data/createMP2Tables.sql deleted file mode 100644 index 5cb314dec6..0000000000 --- a/mailpoet/tests/_data/createMP2Tables.sql +++ /dev/null @@ -1,431 +0,0 @@ --- phpMyAdmin SQL Dump --- version 4.4.10 --- http://www.phpmyadmin.net --- --- Client : localhost:3306 --- Généré le : Mer 26 Avril 2017 à 17:52 --- Version du serveur : 5.5.42 --- Version de PHP : 7.0.0 - -SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; -SET time_zone = "+00:00"; - --- --- Base de données : `mailpoet` --- - --- -------------------------------------------------------- - --- --- Structure de la table `wp_wysija_campaign` --- - -DROP TABLE IF EXISTS `wp_wysija_campaign`; -CREATE TABLE `wp_wysija_campaign` ( - `campaign_id` int(10) unsigned NOT NULL, - `name` varchar(250) DEFAULT NULL, - `description` text -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- -------------------------------------------------------- - --- --- Structure de la table `wp_wysija_campaign_list` --- - -DROP TABLE IF EXISTS `wp_wysija_campaign_list`; -CREATE TABLE `wp_wysija_campaign_list` ( - `list_id` int(10) unsigned NOT NULL, - `campaign_id` int(10) unsigned NOT NULL, - `filter` text -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- -------------------------------------------------------- - --- --- Structure de la table `wp_wysija_custom_field` --- - -DROP TABLE IF EXISTS `wp_wysija_custom_field`; -CREATE TABLE `wp_wysija_custom_field` ( - `id` mediumint(9) NOT NULL, - `name` tinytext NOT NULL, - `type` tinytext NOT NULL, - `required` tinyint(1) NOT NULL DEFAULT '0', - `settings` text -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- -------------------------------------------------------- - --- --- Structure de la table `wp_wysija_email` --- - -DROP TABLE IF EXISTS `wp_wysija_email`; -CREATE TABLE `wp_wysija_email` ( - `email_id` int(10) unsigned NOT NULL, - `campaign_id` int(10) unsigned NOT NULL DEFAULT '0', - `subject` varchar(250) NOT NULL DEFAULT '', - `body` longtext, - `created_at` int(10) unsigned DEFAULT NULL, - `modified_at` int(10) unsigned DEFAULT NULL, - `sent_at` int(10) unsigned DEFAULT NULL, - `from_email` varchar(250) DEFAULT NULL, - `from_name` varchar(250) DEFAULT NULL, - `replyto_email` varchar(250) DEFAULT NULL, - `replyto_name` varchar(250) DEFAULT NULL, - `attachments` text, - `status` tinyint(4) NOT NULL DEFAULT '0', - `type` tinyint(4) NOT NULL DEFAULT '1', - `number_sent` int(10) unsigned NOT NULL DEFAULT '0', - `number_opened` int(10) unsigned NOT NULL DEFAULT '0', - `number_clicked` int(10) unsigned NOT NULL DEFAULT '0', - `number_unsub` int(10) unsigned NOT NULL DEFAULT '0', - `number_bounce` int(10) unsigned NOT NULL DEFAULT '0', - `number_forward` int(10) unsigned NOT NULL DEFAULT '0', - `params` text, - `wj_data` longtext, - `wj_styles` longtext -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- -------------------------------------------------------- - --- --- Structure de la table `wp_wysija_email_user_stat` --- - -DROP TABLE IF EXISTS `wp_wysija_email_user_stat`; -CREATE TABLE `wp_wysija_email_user_stat` ( - `user_id` int(10) unsigned NOT NULL, - `email_id` int(10) unsigned NOT NULL, - `sent_at` int(10) unsigned NOT NULL, - `opened_at` int(10) unsigned DEFAULT NULL, - `status` tinyint(4) NOT NULL DEFAULT '0' -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- -------------------------------------------------------- - --- --- Structure de la table `wp_wysija_email_user_url` --- - -DROP TABLE IF EXISTS `wp_wysija_email_user_url`; -CREATE TABLE `wp_wysija_email_user_url` ( - `email_id` int(10) unsigned NOT NULL, - `user_id` int(10) unsigned NOT NULL, - `url_id` int(10) unsigned NOT NULL, - `clicked_at` int(10) unsigned DEFAULT NULL, - `number_clicked` int(10) unsigned NOT NULL DEFAULT '0' -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- -------------------------------------------------------- - --- --- Structure de la table `wp_wysija_form` --- - -DROP TABLE IF EXISTS `wp_wysija_form`; -CREATE TABLE `wp_wysija_form` ( - `form_id` int(10) unsigned NOT NULL, - `name` tinytext CHARACTER SET utf8 COLLATE utf8_bin, - `data` longtext CHARACTER SET utf8 COLLATE utf8_bin, - `styles` longtext CHARACTER SET utf8 COLLATE utf8_bin, - `subscribed` int(10) unsigned NOT NULL DEFAULT '0' -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- -------------------------------------------------------- - --- --- Structure de la table `wp_wysija_list` --- - -DROP TABLE IF EXISTS `wp_wysija_list`; -CREATE TABLE `wp_wysija_list` ( - `list_id` int(10) unsigned NOT NULL, - `name` varchar(250) DEFAULT NULL, - `namekey` varchar(255) DEFAULT NULL, - `description` text, - `unsub_mail_id` int(10) unsigned NOT NULL DEFAULT '0', - `welcome_mail_id` int(10) unsigned NOT NULL DEFAULT '0', - `is_enabled` tinyint(3) unsigned NOT NULL DEFAULT '0', - `is_public` tinyint(3) unsigned NOT NULL DEFAULT '0', - `created_at` int(10) unsigned DEFAULT NULL, - `ordering` int(10) unsigned NOT NULL DEFAULT '0' -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- -------------------------------------------------------- - --- --- Structure de la table `wp_wysija_queue` --- - -DROP TABLE IF EXISTS `wp_wysija_queue`; -CREATE TABLE `wp_wysija_queue` ( - `user_id` int(10) unsigned NOT NULL, - `email_id` int(10) unsigned NOT NULL, - `send_at` int(10) unsigned NOT NULL DEFAULT '0', - `priority` tinyint(4) NOT NULL DEFAULT '0', - `number_try` tinyint(3) unsigned NOT NULL DEFAULT '0' -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- -------------------------------------------------------- - --- --- Structure de la table `wp_wysija_url` --- - -DROP TABLE IF EXISTS `wp_wysija_url`; -CREATE TABLE `wp_wysija_url` ( - `url_id` int(10) unsigned NOT NULL, - `name` varchar(250) DEFAULT NULL, - `url` text -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- -------------------------------------------------------- - --- --- Structure de la table `wp_wysija_url_mail` --- - -DROP TABLE IF EXISTS `wp_wysija_url_mail`; -CREATE TABLE `wp_wysija_url_mail` ( - `email_id` int(11) NOT NULL, - `url_id` int(10) unsigned NOT NULL, - `unique_clicked` int(10) unsigned NOT NULL DEFAULT '0', - `total_clicked` int(10) unsigned NOT NULL DEFAULT '0' -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- -------------------------------------------------------- - --- --- Structure de la table `wp_wysija_user` --- - -DROP TABLE IF EXISTS `wp_wysija_user`; -CREATE TABLE `wp_wysija_user` ( - `user_id` int(10) unsigned NOT NULL, - `wpuser_id` int(10) unsigned NOT NULL DEFAULT '0', - `email` varchar(255) NOT NULL, - `firstname` varchar(255) NOT NULL DEFAULT '', - `lastname` varchar(255) NOT NULL DEFAULT '', - `ip` varchar(100) NOT NULL, - `confirmed_ip` varchar(100) NOT NULL DEFAULT '0', - `confirmed_at` int(10) unsigned DEFAULT NULL, - `last_opened` int(10) unsigned DEFAULT NULL, - `last_clicked` int(10) unsigned DEFAULT NULL, - `keyuser` varchar(255) NOT NULL DEFAULT '', - `created_at` int(10) unsigned DEFAULT NULL, - `status` tinyint(4) NOT NULL DEFAULT '0', - `domain` varchar(255) DEFAULT '', - `cf_1` varchar(100) DEFAULT NULL, - `cf_3` varchar(255) DEFAULT NULL, - `cf_4` varchar(255) DEFAULT NULL, - `cf_5` tinyint(1) DEFAULT NULL, - `cf_6` varchar(255) DEFAULT NULL, - `cf_7` int(20) DEFAULT NULL, - `cf_8` varchar(100) DEFAULT NULL, - `cf_9` varchar(100) DEFAULT NULL, - `cf_10` varchar(100) DEFAULT NULL, - `cf_11` varchar(100) DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- -------------------------------------------------------- - --- --- Structure de la table `wp_wysija_user_field` --- - -DROP TABLE IF EXISTS `wp_wysija_user_field`; -CREATE TABLE `wp_wysija_user_field` ( - `field_id` int(10) unsigned NOT NULL, - `name` varchar(250) DEFAULT NULL, - `column_name` varchar(250) NOT NULL DEFAULT '', - `type` tinyint(3) unsigned DEFAULT '0', - `values` text, - `default` varchar(250) NOT NULL DEFAULT '', - `is_required` tinyint(3) unsigned NOT NULL DEFAULT '0', - `error_message` varchar(250) NOT NULL DEFAULT '' -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- -------------------------------------------------------- - --- --- Structure de la table `wp_wysija_user_history` --- - -DROP TABLE IF EXISTS `wp_wysija_user_history`; -CREATE TABLE `wp_wysija_user_history` ( - `history_id` int(10) unsigned NOT NULL, - `user_id` int(10) unsigned NOT NULL, - `email_id` int(10) unsigned DEFAULT '0', - `type` varchar(250) NOT NULL DEFAULT '', - `details` text, - `executed_at` int(10) unsigned DEFAULT NULL, - `executed_by` int(10) unsigned DEFAULT NULL, - `source` text -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- -------------------------------------------------------- - --- --- Structure de la table `wp_wysija_user_list` --- - -DROP TABLE IF EXISTS `wp_wysija_user_list`; -CREATE TABLE `wp_wysija_user_list` ( - `list_id` int(10) unsigned NOT NULL, - `user_id` int(10) unsigned NOT NULL, - `sub_date` int(10) unsigned DEFAULT '0', - `unsub_date` int(10) unsigned DEFAULT '0' -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- --- Index pour les tables exportées --- - --- --- Index pour la table `wp_wysija_campaign` --- -ALTER TABLE `wp_wysija_campaign` - ADD PRIMARY KEY (`campaign_id`); - --- --- Index pour la table `wp_wysija_campaign_list` --- -ALTER TABLE `wp_wysija_campaign_list` - ADD PRIMARY KEY (`list_id`,`campaign_id`); - --- --- Index pour la table `wp_wysija_custom_field` --- -ALTER TABLE `wp_wysija_custom_field` - ADD PRIMARY KEY (`id`); - --- --- Index pour la table `wp_wysija_email` --- -ALTER TABLE `wp_wysija_email` - ADD PRIMARY KEY (`email_id`); - --- --- Index pour la table `wp_wysija_email_user_stat` --- -ALTER TABLE `wp_wysija_email_user_stat` - ADD PRIMARY KEY (`user_id`,`email_id`); - --- --- Index pour la table `wp_wysija_email_user_url` --- -ALTER TABLE `wp_wysija_email_user_url` - ADD PRIMARY KEY (`user_id`,`email_id`,`url_id`); - --- --- Index pour la table `wp_wysija_form` --- -ALTER TABLE `wp_wysija_form` - ADD PRIMARY KEY (`form_id`); - --- --- Index pour la table `wp_wysija_list` --- -ALTER TABLE `wp_wysija_list` - ADD PRIMARY KEY (`list_id`); - --- --- Index pour la table `wp_wysija_queue` --- -ALTER TABLE `wp_wysija_queue` - ADD PRIMARY KEY (`user_id`,`email_id`), - ADD KEY `SENT_AT_INDEX` (`send_at`); - --- --- Index pour la table `wp_wysija_url` --- -ALTER TABLE `wp_wysija_url` - ADD PRIMARY KEY (`url_id`); - --- --- Index pour la table `wp_wysija_url_mail` --- -ALTER TABLE `wp_wysija_url_mail` - ADD PRIMARY KEY (`email_id`,`url_id`); - --- --- Index pour la table `wp_wysija_user` --- -ALTER TABLE `wp_wysija_user` - ADD PRIMARY KEY (`user_id`), - ADD UNIQUE KEY `EMAIL_UNIQUE` (`email`); - --- --- Index pour la table `wp_wysija_user_field` --- -ALTER TABLE `wp_wysija_user_field` - ADD PRIMARY KEY (`field_id`); - --- --- Index pour la table `wp_wysija_user_history` --- -ALTER TABLE `wp_wysija_user_history` - ADD PRIMARY KEY (`history_id`); - --- --- Index pour la table `wp_wysija_user_list` --- -ALTER TABLE `wp_wysija_user_list` - ADD PRIMARY KEY (`list_id`,`user_id`); - --- --- AUTO_INCREMENT pour les tables exportées --- - --- --- AUTO_INCREMENT pour la table `wp_wysija_campaign` --- -ALTER TABLE `wp_wysija_campaign` - MODIFY `campaign_id` int(10) unsigned NOT NULL AUTO_INCREMENT; --- --- AUTO_INCREMENT pour la table `wp_wysija_custom_field` --- -ALTER TABLE `wp_wysija_custom_field` - MODIFY `id` mediumint(9) NOT NULL AUTO_INCREMENT; --- --- AUTO_INCREMENT pour la table `wp_wysija_email` --- -ALTER TABLE `wp_wysija_email` - MODIFY `email_id` int(10) unsigned NOT NULL AUTO_INCREMENT; --- --- AUTO_INCREMENT pour la table `wp_wysija_form` --- -ALTER TABLE `wp_wysija_form` - MODIFY `form_id` int(10) unsigned NOT NULL AUTO_INCREMENT; --- --- AUTO_INCREMENT pour la table `wp_wysija_list` --- -ALTER TABLE `wp_wysija_list` - MODIFY `list_id` int(10) unsigned NOT NULL AUTO_INCREMENT; --- --- AUTO_INCREMENT pour la table `wp_wysija_url` --- -ALTER TABLE `wp_wysija_url` - MODIFY `url_id` int(10) unsigned NOT NULL AUTO_INCREMENT; --- --- AUTO_INCREMENT pour la table `wp_wysija_url_mail` --- -ALTER TABLE `wp_wysija_url_mail` - MODIFY `email_id` int(11) NOT NULL AUTO_INCREMENT; --- --- AUTO_INCREMENT pour la table `wp_wysija_user` --- -ALTER TABLE `wp_wysija_user` - MODIFY `user_id` int(10) unsigned NOT NULL AUTO_INCREMENT; --- --- AUTO_INCREMENT pour la table `wp_wysija_user_field` --- -ALTER TABLE `wp_wysija_user_field` - MODIFY `field_id` int(10) unsigned NOT NULL AUTO_INCREMENT; --- --- AUTO_INCREMENT pour la table `wp_wysija_user_history` --- -ALTER TABLE `wp_wysija_user_history` - MODIFY `history_id` int(10) unsigned NOT NULL AUTO_INCREMENT; \ No newline at end of file diff --git a/mailpoet/tests/_data/dropMP2Tables.sql b/mailpoet/tests/_data/dropMP2Tables.sql deleted file mode 100644 index 8ca6cb6239..0000000000 --- a/mailpoet/tests/_data/dropMP2Tables.sql +++ /dev/null @@ -1,15 +0,0 @@ -DROP TABLE IF EXISTS `wp_wysija_campaign`; -DROP TABLE IF EXISTS `wp_wysija_campaign_list`; -DROP TABLE IF EXISTS `wp_wysija_custom_field`; -DROP TABLE IF EXISTS `wp_wysija_email`; -DROP TABLE IF EXISTS `wp_wysija_email_user_stat`; -DROP TABLE IF EXISTS `wp_wysija_email_user_url`; -DROP TABLE IF EXISTS `wp_wysija_form`; -DROP TABLE IF EXISTS `wp_wysija_list`; -DROP TABLE IF EXISTS `wp_wysija_queue`; -DROP TABLE IF EXISTS `wp_wysija_url`; -DROP TABLE IF EXISTS `wp_wysija_url_mail`; -DROP TABLE IF EXISTS `wp_wysija_user`; -DROP TABLE IF EXISTS `wp_wysija_user_field`; -DROP TABLE IF EXISTS `wp_wysija_user_history`; -DROP TABLE IF EXISTS `wp_wysija_user_list`; diff --git a/mailpoet/tests/integration/Config/MP2MigratorTest.php b/mailpoet/tests/integration/Config/MP2MigratorTest.php deleted file mode 100644 index fc22c9bf84..0000000000 --- a/mailpoet/tests/integration/Config/MP2MigratorTest.php +++ /dev/null @@ -1,822 +0,0 @@ -settings = SettingsController::getInstance(); - $this->MP2Migrator = new MP2Migrator( - $this->settings, - ContainerWrapper::getInstance()->get(FormsRepository::class), - ContainerWrapper::getInstance()->get(Activator::class) - ); - } - - public function _after() { - $this->MP2Migrator->progressbar->setTotalCount(0); - } - - /** - * Test the isMigrationNeeded function - * - */ - public function testIsMigrationNeeded() { - Database::loadSQL('dropMP2Tables'); - $result = $this->MP2Migrator->isMigrationNeeded(); - expect($result)->false(); - - Database::loadSQL('createMP2Tables'); - $result = $this->MP2Migrator->isMigrationNeeded(); - expect($result)->true(); - } - - /** - * Test the init function - * - */ - public function testInit() { - // Nothing to test - } - - /** - * Test the eraseMP3Data function - * - */ - public function testEraseMP3Data() { - global $wpdb; - - $this->invokeMethod($this->MP2Migrator, 'eraseMP3Data'); - - // Check if the subscribers number is equal to the WordPress users number - // On multisite environment, there's only 1 users table that's shared by subsites - $WPUsersCount = ORM::for_table($wpdb->base_prefix . 'users')->count(); // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps - expect(Subscriber::count())->equals($WPUsersCount); - - // Check if the custom fields number is 0 - expect(CustomField::count())->equals(0); - - // Check if the subscribers custom fields number is 0 - expect(SubscriberCustomField::count())->equals(0); - } - - /** - * Test the resetMigrationCounters function - * - */ - public function testResetMigrationCounters() { - $this->invokeMethod($this->MP2Migrator, 'resetMigrationCounters'); - - // Check if the last imported user ID is 0 - $lastImportedUserID = $this->settings->get('last_imported_user_id', 0); - expect($lastImportedUserID)->equals(0); - - // Check if the last imported list ID is 0 - $lastImportedListID = $this->settings->get('last_imported_list_id', 0); - expect($lastImportedListID)->equals(0); - } - - /** - * Test the stopImport function - * - */ - public function testStopImport() { - delete_option('mailpoet_stopImport'); - $this->MP2Migrator->stopImport(); - $value = $this->settings->get('import_stopped', false); - $stopImport = !empty($value); - expect($stopImport)->true(); - } - - /** - * Create the MP2 tables and erase the MP3 data - * - */ - private function initImport() { - Database::loadSQL('createMP2Tables'); - $this->invokeMethod($this->MP2Migrator, 'eraseMP3Data'); - } - - /** - * Populate the MP2 tables with some samples data - * - */ - private function loadMP2Fixtures() { - Database::loadSQL('populateMP2Tables'); - } - - /** - * Test the importSegments function - * - * @global object $wpdb - */ - public function testImportSegments() { - global $wpdb; - - // Check the segments number - $this->initImport(); - $this->loadMP2Fixtures(); - $this->invokeMethod($this->MP2Migrator, 'importSegments'); - expect(Segment::count())->equals(4); // two regular lists, WP users list, WooCommerce customers list (not imported) - - // Check a segment data - $this->initImport(); - $id = 999; - $name = 'Test list'; - $description = 'Description of the test list'; - $timestamp = 1486319877; - $wpdb->insert($wpdb->prefix . 'wysija_list', [ - 'list_id' => $id, - 'name' => $name, - 'description' => $description, - 'is_enabled' => 1, - 'is_public' => 1, - 'created_at' => $timestamp, - ]); - $this->invokeMethod($this->MP2Migrator, 'importSegments'); - $importedSegmentsMapping = $this->MP2Migrator->getImportedMapping('segments'); - $table = MP_SEGMENTS_TABLE; - $segment = $wpdb->get_row("SELECT * FROM $table WHERE id=" . $importedSegmentsMapping[$id]); - expect($segment->name)->equals($name); - expect($segment->description)->equals($description); - } - - /** - * Test the importCustomFields function - * - * @global object $wpdb - */ - public function testImportCustomFields() { - global $wpdb; - - // Check the custom fields number - $this->initImport(); - $this->loadMP2Fixtures(); - $this->invokeMethod($this->MP2Migrator, 'importCustomFields'); - expect(CustomField::count())->equals(10); - - // Check a custom field data - $this->initImport(); - $id = 999; - $name = 'Test field'; - $type = 'input'; - $required = 1; - $settings = [ - 'required' => '1', - 'validate' => 'onlyLetterSp', - ]; - $wpdb->insert($wpdb->prefix . 'wysija_custom_field', [ - 'id' => $id, - 'name' => $name, - 'type' => $type, - 'required' => $required, - 'settings' => serialize($settings), - ]); - $this->invokeMethod($this->MP2Migrator, 'importCustomFields'); - $table = MP_CUSTOM_FIELDS_TABLE; - $customField = $wpdb->get_row("SELECT * FROM $table WHERE id=$id"); - expect($customField->id)->equals($id); - expect($customField->name)->equals($name); - expect($customField->type)->equals('text'); - $customFieldParams = unserialize($customField->params); - expect($customFieldParams['required'])->equals($settings['required']); - expect($customFieldParams['validate'])->equals('alphanum'); - expect($customFieldParams['label'])->equals($name); - } - - public function testImportSubscribers() { - global $wpdb; - - // Check a subscriber data - $this->initImport(); - $id = 999; - $wpId = 1; - $email = 'test@test.com'; - $firstname = 'Test firstname'; - $lastname = 'Test lastname'; - $ip = '127.0.0.1'; - $confirmedIp = $ip; - $wpdb->insert($wpdb->prefix . 'wysija_user', [ - 'user_id' => $id, - 'wpuser_id' => $wpId, - 'email' => $email, - 'firstname' => $firstname, - 'lastname' => $lastname, - 'ip' => $ip, - 'confirmed_ip' => $confirmedIp, - 'status' => '1', - ]); - $wpdb->insert($wpdb->prefix . 'wysija_user', [ - 'user_id' => $id + 1, - 'wpuser_id' => $wpId, - 'email' => '1' . $email, - 'firstname' => $firstname, - 'lastname' => $lastname, - 'ip' => $ip, - 'confirmed_ip' => $confirmedIp, - 'status' => '0', - ]); - $this->invokeMethod($this->MP2Migrator, 'importSubscribers'); - $table = MP_SUBSCRIBERS_TABLE; - $subscribers = $wpdb->get_results("SELECT * FROM $table WHERE email LIKE '%$email' ORDER BY id"); - expect($subscribers[0]->status)->equals('subscribed'); - expect($subscribers[1]->status)->equals('unconfirmed'); - } - - public function testImportSubscribersWithDblOptinDisabled() { - global $wpdb; - - $this->initImport(); - $values = ['confirm_dbleoptin' => '0']; - $encodedOption = base64_encode(serialize($values)); - update_option('wysija', $encodedOption); - - $id = 999; - $wpId = 1; - $email = 'test@test.com'; - $firstname = 'Test firstname'; - $lastname = 'Test lastname'; - $ip = '127.0.0.1'; - $confirmedIp = $ip; - $wpdb->insert($wpdb->prefix . 'wysija_user', [ - 'user_id' => $id, - 'wpuser_id' => $wpId, - 'email' => $email, - 'firstname' => $firstname, - 'lastname' => $lastname, - 'ip' => $ip, - 'confirmed_ip' => $confirmedIp, - 'status' => '1', - ]); - $wpdb->insert($wpdb->prefix . 'wysija_user', [ - 'user_id' => $id + 1, - 'wpuser_id' => $wpId, - 'email' => '1' . $email, - 'firstname' => $firstname, - 'lastname' => $lastname, - 'ip' => $ip, - 'confirmed_ip' => $confirmedIp, - 'status' => '0', - ]); - $this->invokeMethod($this->MP2Migrator, 'loadDoubleOptinSettings'); - $this->invokeMethod($this->MP2Migrator, 'importSubscribers'); - $table = MP_SUBSCRIBERS_TABLE; - $subscribers = $wpdb->get_results("SELECT * FROM $table WHERE email LIKE '%$email' ORDER BY id"); - expect($subscribers[0]->status)->equals('subscribed'); - expect($subscribers[1]->status)->equals('subscribed'); - } - - /** - * Test the importSubscribers function - * - * @global object $wpdb - */ - public function testSubscribersStatus() { - global $wpdb; - - $this->initImport(); - $id = 999; - $wpId = 1; - $email = 'test@test.com'; - $firstname = 'Test firstname'; - $lastname = 'Test lastname'; - $ip = '127.0.0.1'; - $confirmedIp = $ip; - $wpdb->insert($wpdb->prefix . 'wysija_user', [ - 'user_id' => $id, - 'wpuser_id' => $wpId, - 'email' => $email, - 'firstname' => $firstname, - 'lastname' => $lastname, - 'ip' => $ip, - 'confirmed_ip' => $confirmedIp, - 'status' => '1', - ]); - $this->invokeMethod($this->MP2Migrator, 'importSubscribers'); - $table = MP_SUBSCRIBERS_TABLE; - $subscriber = $wpdb->get_row("SELECT * FROM $table WHERE email='$email'"); - expect($subscriber->email)->equals($email); - expect($subscriber->first_name)->equals($firstname); // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps - expect($subscriber->last_name)->equals($lastname); // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps - expect($subscriber->subscribed_ip)->equals($ip); // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps - expect($subscriber->confirmed_ip)->equals($confirmedIp); // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps - expect($subscriber->status)->equals('subscribed'); - } - - /** - * Test the importSubscriberSegments function - * - * @global object $wpdb - */ - public function testImportSubscriberSegments() { - global $wpdb; - - // Check a subscriber segment data - - // Insert a list - $this->initImport(); - $listId = 998; - $listName = 'Test list'; - $description = 'Description of the test list'; - $timestamp = 1486319877; - $wpdb->insert($wpdb->prefix . 'wysija_list', [ - 'list_id' => $listId, - 'name' => $listName, - 'description' => $description, - 'is_enabled' => 1, - 'is_public' => 1, - 'created_at' => $timestamp, - ]); - - // Insert a user - $userId = 999; - $wpId = 1; - $email = 'test@test.com'; - $wpdb->insert($wpdb->prefix . 'wysija_user', [ - 'user_id' => $userId, - 'wpuser_id' => $wpId, - 'email' => $email, - ]); - - // Insert a user list - $wpdb->insert($wpdb->prefix . 'wysija_user_list', [ - 'list_id' => $listId, - 'user_id' => $userId, - 'sub_date' => $timestamp, - ]); - - $this->invokeMethod($this->MP2Migrator, 'importSegments'); - $this->invokeMethod($this->MP2Migrator, 'importSubscribers'); - $importedSegmentsMapping = $this->MP2Migrator->getImportedMapping('segments'); - $importedSubscribersMapping = $this->MP2Migrator->getImportedMapping('subscribers'); - $table = MP_SUBSCRIBER_SEGMENT_TABLE; - $segmentId = $importedSegmentsMapping[$listId]; - $subscriberId = $importedSubscribersMapping[$userId]; - $subscriberSegment = $wpdb->get_row("SELECT * FROM $table WHERE subscriber_id='$subscriberId' AND segment_id='$segmentId'"); - expect($subscriberSegment)->notNull(); - } - - /** - * Test the importSubscriberCustomFields function - * - * @global object $wpdb - */ - public function testImportSubscriberCustomFields() { - global $wpdb; - - // Check the subscriber custom fields number - $this->initImport(); - $this->loadMP2Fixtures(); - $this->invokeMethod($this->MP2Migrator, 'importCustomFields'); - $this->invokeMethod($this->MP2Migrator, 'importSubscribers'); - expect(SubscriberCustomField::count())->equals(40); - - // Check a subscriber custom field data - - $this->initImport(); - // Insert a custom field - $cfId = 1; - $cfName = 'Custom field key'; - $cfType = 'input'; - $cfRequired = 1; - $cfSettings = [ - 'required' => '1', - 'validate' => 'onlyLetterSp', - ]; - $wpdb->insert($wpdb->prefix . 'wysija_custom_field', [ - 'id' => $cfId, - 'name' => $cfName, - 'type' => $cfType, - 'required' => $cfRequired, - 'settings' => serialize($cfSettings), - ]); - - // Insert a user - $userId = 999; - $wpId = 1; - $email = 'test@test.com'; - $customFieldValue = 'Test custom field value'; - $wpdb->insert($wpdb->prefix . 'wysija_user', [ - 'user_id' => $userId, - 'wpuser_id' => $wpId, - 'email' => $email, - 'cf_' . $cfId => $customFieldValue, - ]); - - $this->invokeMethod($this->MP2Migrator, 'importCustomFields'); - $this->invokeMethod($this->MP2Migrator, 'importSubscribers'); - $importedSubscribersMapping = $this->MP2Migrator->getImportedMapping('subscribers'); - $table = MP_SUBSCRIBER_CUSTOM_FIELD_TABLE; - $subscriberId = $importedSubscribersMapping[$userId]; - $subscriberCustomField = $wpdb->get_row("SELECT * FROM $table WHERE subscriber_id='$subscriberId' AND custom_field_id='$cfId'"); - expect($subscriberCustomField->value)->equals($customFieldValue); - } - - /** - * Test the getImportedMapping function - * - */ - public function testGetImportedMapping() { - $this->initImport(); - $mapping = new MappingToExternalEntities(); - $oldId = 999; - $newId = 500; - $type = 'testMapping'; - $mapping->create([ - 'old_id' => $oldId, - 'type' => $type, - 'new_id' => $newId, - ]); - $result = $this->invokeMethod($this->MP2Migrator, 'getImportedMapping', ['testMapping']); - expect($result[$oldId])->equals($newId); - } - - /** - * Test the importForms function - * - * @global object $wpdb - */ - public function testImportForms() { - global $wpdb; - $formRepository = ContainerWrapper::getInstance()->get(FormsRepository::class); - - // Check the forms number - $this->initImport(); - $this->loadMP2Fixtures(); - $this->invokeMethod($this->MP2Migrator, 'importForms'); - expect($formRepository->countBy([]))->equals(2); - - // Check a form data - $this->initImport(); - $id = 999; - $name = 'Test form'; - $listId = 2; - - // Insert a MP2 list - $wpdb->insert($wpdb->prefix . 'wysija_list', [ - 'list_id' => $listId, - 'name' => 'Test list', - 'description' => 'Test list description', - 'is_enabled' => 1, - 'is_public' => 1, - 'created_at' => 1486319877, - ]); - $this->invokeMethod($this->MP2Migrator, 'importSegments'); - $importedSegmentsMapping = $this->MP2Migrator->getImportedMapping('segments'); - - // Insert a MP2 form - $data = [ - 'version' => 0.4, - 'settings' => [ - 'on_success' => 'message', - 'success_message' => 'Test message', - 'lists' => [$listId], - 'lists_selected_by' => 'admin', - ], - 'body' => [ - [ - 'name' => 'E-mail', - 'type' => 'input', - 'field' => 'email', - 'params' => [ - 'label' => 'E-mail', - 'required' => 1, - ], - ], - ], - ]; - $wpdb->insert($wpdb->prefix . 'wysija_form', [ - 'form_id' => $id, - 'name' => $name, - 'data' => base64_encode(serialize($data)), - ]); - $this->invokeMethod($this->MP2Migrator, 'importForms'); - $table = MP_FORMS_TABLE; - $form = $wpdb->get_row("SELECT * FROM $table WHERE id=" . 1); - expect($form->name)->equals($name); - $settings = unserialize(($form->settings)); - expect($settings['on_success'])->equals('message'); - expect($settings['success_message'])->equals('Test message'); - expect($settings['segments'][0])->equals($importedSegmentsMapping[$listId]); - $body = unserialize(($form->body)); - expect($body[0]['name'])->equals('E-mail'); - expect($body[0]['type'])->equals('text'); - } - - /** - * Test the replaceMP2Shortcodes function - * - */ - public function testReplaceMP2Shortcodes() { - $this->initImport(); - - $result = $this->invokeMethod($this->MP2Migrator, 'replaceMP2Shortcodes', ['[total_subscribers]']); - expect($result)->equals('[mailpoet_subscribers_count]'); - - $result = $this->invokeMethod($this->MP2Migrator, 'replaceMP2Shortcodes', ['Total: [total_subscribers]']); - expect($result)->equals('Total: [mailpoet_subscribers_count]'); - - $result = $this->invokeMethod($this->MP2Migrator, 'replaceMP2Shortcodes', ['Total: [total_subscribers] found']); - expect($result)->equals('Total: [mailpoet_subscribers_count] found'); - - $result = $this->invokeMethod($this->MP2Migrator, 'replaceMP2Shortcodes', ['[wysija_subscribers_count list_id="1,2" ]']); - expect($result)->notEquals('mailpoet_subscribers_count segments=1,2'); - - $this->loadMP2Fixtures(); - $this->invokeMethod($this->MP2Migrator, 'importSegments'); - $result = $this->invokeMethod($this->MP2Migrator, 'replaceMP2Shortcodes', ['[wysija_subscribers_count list_id="1,2" ]']); - $importedSegmentsMapping = $this->MP2Migrator->getImportedMapping('segments'); - expect($result)->equals(sprintf('[mailpoet_subscribers_count segments=%d,%d]', $importedSegmentsMapping[1], $importedSegmentsMapping[2])); - } - - /** - * Test the getMappedSegmentIds function - * - */ - public function testGetMappedSegmentIds() { - $this->initImport(); - - $lists = [1, 2]; - $this->loadMP2Fixtures(); - $this->invokeMethod($this->MP2Migrator, 'importSegments'); - $importedSegmentsMapping = $this->MP2Migrator->getImportedMapping('segments'); - $result = $this->invokeMethod($this->MP2Migrator, 'getMappedSegmentIds', [$lists]); - $expectedLists = [$importedSegmentsMapping[1],$importedSegmentsMapping[2]]; - expect($result)->equals($expectedLists); - } - - /** - * Test the replaceListIds function - * - */ - public function testReplaceListIds() { - $this->initImport(); - - $lists = [ - [ - 'list_id' => 1, - 'name' => 'List 1', - ], - [ - 'list_id' => 2, - 'name' => 'List 2', - ], - ]; - $this->loadMP2Fixtures(); - $this->invokeMethod($this->MP2Migrator, 'importSegments'); - $importedSegmentsMapping = $this->MP2Migrator->getImportedMapping('segments'); - $result = $this->invokeMethod($this->MP2Migrator, 'replaceListIds', [$lists]); - $expectedLists = [ - [ - 'id' => $importedSegmentsMapping[1], - 'name' => 'List 1', - ], - [ - 'id' => $importedSegmentsMapping[2], - 'name' => 'List 2', - ], - ]; - expect($result)->equals($expectedLists); - } - - /** - * Test the mapFrequencyInterval function - * - */ - public function testMapFrequencyInterval() { - $result = $this->invokeMethod($this->MP2Migrator, 'mapFrequencyInterval', ['one_min']); - expect($result)->equals(1); - - $result = $this->invokeMethod($this->MP2Migrator, 'mapFrequencyInterval', ['two_min']); - expect($result)->equals(2); - - $result = $this->invokeMethod($this->MP2Migrator, 'mapFrequencyInterval', ['five_min']); - expect($result)->equals(5); - - $result = $this->invokeMethod($this->MP2Migrator, 'mapFrequencyInterval', ['ten_min']); - expect($result)->equals(10); - - $result = $this->invokeMethod($this->MP2Migrator, 'mapFrequencyInterval', ['fifteen_min']); - expect($result)->equals(15); - - $result = $this->invokeMethod($this->MP2Migrator, 'mapFrequencyInterval', ['thirty_min']); - expect($result)->equals(15); - - $result = $this->invokeMethod($this->MP2Migrator, 'mapFrequencyInterval', ['hourly']); - expect($result)->equals(15); - - $result = $this->invokeMethod($this->MP2Migrator, 'mapFrequencyInterval', ['two_hours']); - expect($result)->equals(15); - } - - /** - * Test the importSettings function - * - */ - public function testImportSettings() { - $this->loadMP2OptionsFixtures(); - - $this->invokeMethod($this->MP2Migrator, 'importSettings'); - - $sender = $this->settings->get('sender'); - expect($sender['name'])->equals('Sender'); - expect($sender['address'])->equals('sender@email.com'); - - $replyTo = $this->settings->get('reply_to'); - expect($replyTo['name'])->equals('Reply'); - expect($replyTo['address'])->equals('reply@email.com'); - - $bounce = $this->settings->get('bounce'); - expect($bounce['address'])->equals('bounce@email.com'); - - $notification = $this->settings->get('notification'); - expect($notification['address'])->equals('notification@email.com'); - - $subscribe = $this->settings->get('subscribe'); - expect($subscribe['on_comment']['enabled'])->equals(1); - expect($subscribe['on_comment']['label'])->equals('Oui, ajoutez moi à votre liste de diffusion !!!'); - expect($subscribe['on_register']['enabled'])->equals(1); - expect($subscribe['on_register']['label'])->equals('Oui, ajoutez moi à votre liste de diffusion 2'); - - $subscription = $this->settings->get('subscription'); - expect($subscription['pages']['unsubscribe'])->equals(2); - expect($subscription['pages']['confirmation'])->equals(4); - expect($subscription['pages']['manage'])->equals(4); - - $signupConfirmation = $this->settings->get('signup_confirmation'); - expect($signupConfirmation['enabled'])->equals(1); - - $analytics = $this->settings->get('analytics'); - expect($analytics['enabled'])->equals(1); - - $mtaGroup = $this->settings->get('mta_group'); - expect($mtaGroup)->equals('smtp'); - - $mta = $this->settings->get('mta'); - expect($mta['method'])->equals('SMTP'); - expect($mta['frequency']['emails'])->equals(25); - expect($mta['frequency']['interval'])->equals(5); - expect($mta['host'])->equals('smtp.mondomaine.com'); - expect($mta['port'])->equals(25); - expect($mta['login'])->equals('login'); - expect($mta['password'])->equals('password'); - expect($mta['encryption'])->equals('ssl'); - expect($mta['authentication'])->equals(1); - } - - public function testIgnoresInvalidBounceAddress() { - $this->loadMP2OptionsFixtures([ - 'bounce_email' => 'invalid', - ]); - - $this->invokeMethod($this->MP2Migrator, 'importSettings'); - - $bounce = $this->settings->get('bounce'); - expect($bounce['address'])->equals(''); - } - - /** - * Load some MP2 fixtures - * - */ - private function loadMP2OptionsFixtures($options = []) { - $wysijaOptions = [ - 'from_name' => 'Sender', - 'replyto_name' => 'Reply', - 'emails_notified' => 'notification@email.com', - 'from_email' => 'sender@email.com', - 'replyto_email' => 'reply@email.com', - 'default_list_id' => 1, - 'total_subscribers' => '1262', - 'importwp_list_id' => 2, - 'confirm_email_link' => 4, - 'uploadfolder' => '', - 'uploadurl' => '', - 'confirm_email_id' => 2, - 'installed' => true, - 'manage_subscriptions' => 1, - 'installed_time' => 1486319877, - 'wysija_db_version' => '2.7.7', - 'dkim_domain' => 'localhost', - 'wysija_whats_new' => '2.7.10', - 'ignore_msgs' => - [ - 'ctaupdate' => 1, - ], - 'queue_sends_slow' => 1, - 'emails_notified_when_sub' => 1, - 'emails_notified_when_bounce' => false, - 'emails_notified_when_dailysummary' => 1, - 'bounce_process_auto' => false, - 'ms_bounce_process_auto' => false, - 'sharedata' => false, - 'dkim_active' => false, - 'commentform' => 1, - 'smtp_rest' => false, - 'ms_smtp_rest' => false, - 'debug_log_cron' => false, - 'debug_log_post_notif' => false, - 'debug_log_query_errors' => false, - 'debug_log_queue_process' => false, - 'debug_log_manual' => false, - 'company_address' => 'mon adresse postale', - 'commentform_lists' => - [ - 0 => '15', - 1 => '3', - ], - 'unsubscribe_page' => '2', - 'confirmation_page' => '4', - 'smtp_host' => 'smtp.mondomaine.com', - 'smtp_login' => 'login', - 'smtp_password' => 'password', - 'smtp_port' => '25', - 'smtp_secure' => 'ssl', - 'test_mails' => 'test@email.com', - 'bounce_email' => 'bounce@email.com', - 'subscriptions_page' => '4', - 'html_source' => '1', - 'industry' => 'e-commerce', - 'archive_linkname' => '[wysija_archive]', - 'subscribers_count_linkname' => '[wysija_subscribers_count]', - 'archive_lists' => - [ - 0 => '15', - ], - 'commentform_linkname' => 'Oui, ajoutez moi à votre liste de diffusion !!!', - 'registerform' => 1, - 'registerform_linkname' => 'Oui, ajoutez moi à votre liste de diffusion 2', - 'registerform_lists' => - [ - 0 => '12', - 1 => '11', - 2 => '8', - ], - 'viewinbrowser_linkname' => 'Problèmes d\'affichage ?? [link]Affichez cette newsletter dans votre navigateur.[/link]', - 'unsubscribe_linkname' => 'Se désabonner...', - 'analytics' => '1', - 'subscribers_count_lists' => - [ - 0 => '15', - ], - 'premium_key' => '', - 'premium_val' => '', - 'last_save' => 1498810541, - 'sending_emails_each' => 'five_min', - 'sending_emails_number' => '25', - 'sending_method' => 'smtp', - 'manage_subscriptions_lists' => - [ - 0 => '3', - 1 => '12', - 2 => '11', - ], - 'rolescap---administrator---newsletters' => false, - 'rolescap---editor---newsletters' => false, - 'rolescap---author---newsletters' => false, - 'rolescap---contributor---newsletters' => false, - 'rolescap---subscriber---newsletters' => false, - 'rolescap---administrator---subscribers' => false, - 'rolescap---editor---subscribers' => false, - 'rolescap---author---subscribers' => false, - 'rolescap---contributor---subscribers' => false, - 'rolescap---subscriber---subscribers' => false, - 'rolescap---administrator---config' => false, - 'rolescap---editor---config' => false, - 'rolescap---author---config' => false, - 'rolescap---contributor---config' => false, - 'rolescap---subscriber---config' => false, - 'rolescap---administrator---theme_tab' => false, - 'rolescap---editor---theme_tab' => false, - 'rolescap---author---theme_tab' => false, - 'rolescap---contributor---theme_tab' => false, - 'rolescap---subscriber---theme_tab' => false, - 'rolescap---administrator---style_tab' => false, - 'rolescap---editor---style_tab' => false, - 'rolescap---author---style_tab' => false, - 'rolescap---contributor---style_tab' => false, - 'rolescap---subscriber---style_tab' => false, - ]; - - $wysijaOptions = array_merge($wysijaOptions, $options); - update_option('wysija', base64_encode(serialize($wysijaOptions))); - } -} diff --git a/mailpoet/tests/integration/Models/SubscriberSegmentTest.php b/mailpoet/tests/integration/Models/SubscriberSegmentTest.php index b327bc9e03..0bf7cab599 100644 --- a/mailpoet/tests/integration/Models/SubscriberSegmentTest.php +++ b/mailpoet/tests/integration/Models/SubscriberSegmentTest.php @@ -5,6 +5,7 @@ namespace MailPoet\Test\Models; use MailPoet\Models\Segment; use MailPoet\Models\Subscriber; use MailPoet\Models\SubscriberSegment; +use MailPoetVendor\Idiorm\ORM; class SubscriberSegmentTest extends \MailPoetTest { public $wcSegment; @@ -15,6 +16,7 @@ class SubscriberSegmentTest extends \MailPoetTest { public function _before() { parent::_before(); + ORM::raw_execute('SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"'); $this->subscriber = Subscriber::createOrUpdate([ 'email' => 'john.doe@mailpoet.com', 'first_name' => 'John',