Remove no longer needed populator logic
This commit is contained in:
@@ -35,14 +35,12 @@ use MailPoet\Subscribers\NewSubscriberNotificationMailer;
|
|||||||
use MailPoet\Subscribers\Source;
|
use MailPoet\Subscribers\Source;
|
||||||
use MailPoet\Subscription\Captcha\CaptchaConstants;
|
use MailPoet\Subscription\Captcha\CaptchaConstants;
|
||||||
use MailPoet\Subscription\Captcha\CaptchaRenderer;
|
use MailPoet\Subscription\Captcha\CaptchaRenderer;
|
||||||
use MailPoet\Util\Helpers;
|
|
||||||
use MailPoet\WP\Functions as WPFunctions;
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
use MailPoetVendor\Carbon\Carbon;
|
use MailPoetVendor\Carbon\Carbon;
|
||||||
use MailPoetVendor\Doctrine\ORM\EntityManager;
|
use MailPoetVendor\Doctrine\ORM\EntityManager;
|
||||||
|
|
||||||
class Populator {
|
class Populator {
|
||||||
public $prefix;
|
public $prefix;
|
||||||
public $models;
|
|
||||||
public $templates;
|
public $templates;
|
||||||
/** @var SettingsController */
|
/** @var SettingsController */
|
||||||
private $settings;
|
private $settings;
|
||||||
@@ -78,7 +76,6 @@ class Populator {
|
|||||||
$this->wpSegment = $wpSegment;
|
$this->wpSegment = $wpSegment;
|
||||||
$this->referralDetector = $referralDetector;
|
$this->referralDetector = $referralDetector;
|
||||||
$this->prefix = Env::$dbPrefix;
|
$this->prefix = Env::$dbPrefix;
|
||||||
$this->models = [];
|
|
||||||
$this->templates = [
|
$this->templates = [
|
||||||
'WelcomeBlank1Column',
|
'WelcomeBlank1Column',
|
||||||
'WelcomeBlank12Column',
|
'WelcomeBlank12Column',
|
||||||
@@ -166,7 +163,6 @@ class Populator {
|
|||||||
$localizer = new Localizer();
|
$localizer = new Localizer();
|
||||||
$localizer->forceLoadWebsiteLocaleText();
|
$localizer->forceLoadWebsiteLocaleText();
|
||||||
|
|
||||||
array_map([$this, 'populate'], $this->models);
|
|
||||||
$this->populateNewsletterOptionFields();
|
$this->populateNewsletterOptionFields();
|
||||||
$this->populateNewsletterTemplates();
|
$this->populateNewsletterTemplates();
|
||||||
|
|
||||||
@@ -621,67 +617,6 @@ class Populator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function populate($model) {
|
|
||||||
$modelMethod = Helpers::underscoreToCamelCase($model);
|
|
||||||
$table = $this->prefix . $model;
|
|
||||||
$dataDescriptor = $this->$modelMethod();
|
|
||||||
$rows = $dataDescriptor['rows'];
|
|
||||||
$identificationColumns = array_fill_keys(
|
|
||||||
$dataDescriptor['identification_columns'],
|
|
||||||
''
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($rows as $row) {
|
|
||||||
$existenceComparisonFields = array_intersect_key(
|
|
||||||
$row,
|
|
||||||
$identificationColumns
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!$this->rowExists($table, $existenceComparisonFields)) {
|
|
||||||
$this->insertRow($table, $row);
|
|
||||||
} else {
|
|
||||||
$this->updateRow($table, $row, $existenceComparisonFields);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function rowExists(string $tableName, array $columns): bool {
|
|
||||||
$qb = $this->entityManager->getConnection()->createQueryBuilder();
|
|
||||||
$qb->select('COUNT(*)')
|
|
||||||
->from($tableName, 't')
|
|
||||||
->where(
|
|
||||||
$qb->expr()->and(
|
|
||||||
...array_map(
|
|
||||||
function ($column, $value) use ($qb) {
|
|
||||||
return $qb->expr()->eq('t.' . $column, $qb->createNamedParameter($value));
|
|
||||||
},
|
|
||||||
array_keys($columns),
|
|
||||||
$columns
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
return $qb->executeQuery()->fetchOne() > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function insertRow($table, $row) {
|
|
||||||
global $wpdb;
|
|
||||||
|
|
||||||
return $wpdb->insert(
|
|
||||||
$table,
|
|
||||||
$row
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function updateRow($table, $row, $where) {
|
|
||||||
global $wpdb;
|
|
||||||
|
|
||||||
return $wpdb->update(
|
|
||||||
$table,
|
|
||||||
$row,
|
|
||||||
$where
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createSourceForSubscribers() {
|
private function createSourceForSubscribers() {
|
||||||
$statisticsFormTable = $this->entityManager->getClassMetadata(StatisticsFormEntity::class)->getTableName();
|
$statisticsFormTable = $this->entityManager->getClassMetadata(StatisticsFormEntity::class)->getTableName();
|
||||||
$subscriberTable = $this->entityManager->getClassMetadata(SubscriberEntity::class)->getTableName();
|
$subscriberTable = $this->entityManager->getClassMetadata(SubscriberEntity::class)->getTableName();
|
||||||
|
Reference in New Issue
Block a user