<?php declare(strict_types = 1); namespace MailPoet\Util; if (!defined('ABSPATH')) exit; use MailPoetVendor\Doctrine\ORM\EntityManager; class DBCollationChecker { /** @var EntityManager */ private $entityManager; public function __construct( EntityManager $entityManager ) { $this->entityManager = $entityManager; } /** * If two columns have a different collations returns MySQL's COLLATE command to be used with the target table column. * e.g. WHERE source_table.column = target_table.column COLLATE xyz */ public function getCollateIfNeeded(string $sourceTable, string $sourceColumn, string $targetTable, string $targetColumn): string { $connection = $this->entityManager->getConnection(); $sourceColumnData = $connection->executeQuery("SHOW FULL COLUMNS FROM $sourceTable WHERE Field = '$sourceColumn';")->fetchAllAssociative(); $sourceCollation = $sourceColumnData[0]['Collation'] ?? ''; $targetColumnData = $connection->executeQuery("SHOW FULL COLUMNS FROM $targetTable WHERE Field = '$targetColumn';")->fetchAllAssociative(); $targetCollation = $targetColumnData[0]['Collation'] ?? ''; if ($sourceCollation !== $targetCollation) { return "COLLATE $sourceCollation"; } return ''; } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
License | Folder | 0755 |
|
|
Notices | Folder | 0755 |
|
|
pQuery | Folder | 0755 |
|
|
CdnAssetUrl.php | File | 482 B | 0644 |
|
ConflictResolver.php | File | 7.57 KB | 0644 |
|
Cookies.php | File | 1.15 KB | 0644 |
|
DBCollationChecker.php | File | 1.24 KB | 0644 |
|
DOM.php | File | 1.42 KB | 0644 |
|
DateConverter.php | File | 2.78 KB | 0644 |
|
FreeDomains.php | File | 2.82 KB | 0644 |
|
Helpers.php | File | 2.85 KB | 0644 |
|
Installation.php | File | 903 B | 0644 |
|
ProgressBar.php | File | 2.23 KB | 0644 |
|
SecondLevelDomainNames.php | File | 262 B | 0644 |
|
Security.php | File | 2.89 KB | 0644 |
|
Url.php | File | 1.5 KB | 0644 |
|
index.php | File | 0 B | 0644 |
|