| Server IP : 35.236.43.222 / Your IP : 216.73.216.143 Web Server : Apache System : Linux order-form-vm-001 5.10.0-37-cloud-amd64 #1 SMP Debian 5.10.247-1 (2025-12-11) x86_64 User : deploy ( 1002) PHP Version : 8.1.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/mastersystem.app/public/wp-content/plugins/mailpoet/lib/Util/ |
Upload File : |
<?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 incompatible 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
*
* In MySQL, if you have the same charset and collation in joined tables' columns it's perfect;
* if you have different charsets, utf8 and utf8mb4, it works too; but if you have the same charset
* with different collations, e.g. utf8mb4_unicode_ci and utf8mb4_unicode_520_ci, it will fail
* with an 'Illegal mix of collations' error.
*/
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 '';
}
list($sourceCharset) = explode('_', $sourceCollation);
list($targetCharset) = explode('_', $targetCollation);
if ($sourceCharset === $targetCharset) {
return "COLLATE $sourceCollation";
}
return '';
}
}