Only display two table names

[MAILPOET-6184]
This commit is contained in:
Pavel Dohnal
2024-08-12 10:18:44 +02:00
committed by Aschepikov
parent 12cdba005c
commit e9969b64ae
2 changed files with 44 additions and 3 deletions

View File

@@ -11,6 +11,7 @@ use MailPoetVendor\Doctrine\ORM\EntityManager;
class DatabaseEngineNotice {
const OPTION_NAME = 'database-engine-notice';
const DISMISS_NOTICE_TIMEOUT_SECONDS = 15_552_000; // 6 months
const MAX_TABLES_TO_DISPLAY = 2;
private WPFunctions $wp;
@@ -25,7 +26,6 @@ class DatabaseEngineNotice {
}
//TODO: check only once a day
//TODO: display better list of table names (“wp_mailpoet_settings”, “wp_mailpoet_feature_flags”, and 7 more)
public function init($shouldDisplay): ?Notice {
if (!$shouldDisplay || $this->wp->getTransient(self::OPTION_NAME)) {
return null;
@@ -61,8 +61,8 @@ class DatabaseEngineNotice {
private function display(array $tablesWithIncorrectEngine): ?Notice {
// translators: %s is the list of the table names
$errorString = __('Some of the MailPoet plugins tables are not using the InnoDB engine (%s). This may cause performance and compatibility issues. Please ensure all MailPoet tables are converted to use the InnoDB engine. For more information, check out [link]this guide[/link].', 'mailpoet');
$tables = implode(", ", $tablesWithIncorrectEngine);
$errorString = __('Some of the MailPoet plugins tables are not using the InnoDB engine (%s). This may cause performance and compatibility issues. Please ensure all MailPoet tables are converted to use the InnoDB engine. For more information, check out [link]this guide[/link].', 'mailpoet');
$tables = $this->formatTableNames($tablesWithIncorrectEngine);
$errorString = sprintf($errorString, $tables);
$error = Helpers::replaceLinkTags($errorString, 'https://kb.mailpoet.com/article/200-solving-database-connection-issues#database-configuration', [
'target' => '_blank',
@@ -73,6 +73,23 @@ class DatabaseEngineNotice {
return Notice::displayWarning($error, $extraClasses, self::OPTION_NAME);
}
private function formatTableNames(array $tablesWithIncorrectEngine): string {
sort($tablesWithIncorrectEngine);
$tables = array_map(
fn($table) => "${table}",
array_slice($tablesWithIncorrectEngine, 0, self::MAX_TABLES_TO_DISPLAY)
);
$remainingTablesCount = count($tablesWithIncorrectEngine) - count($tables);
if ($remainingTablesCount > 0) {
// translators: %d is the number of remaining tables, the whole string will be: "table1, table2 and 3 more"
$tables[] = sprintf(__('and %d more', 'mailpoet'), $remainingTablesCount);
}
return implode(', ', $tables);
}
public function disable() {
$this->wp->setTransient(self::OPTION_NAME, true, self::DISMISS_NOTICE_TIMEOUT_SECONDS);
}