From ebff28171ce1ea68d41d8d31ea8f945ad3db1f09 Mon Sep 17 00:00:00 2001 From: Prashant Tholia <65695939+prashanttholia@users.noreply.github.com> Date: Thu, 21 Jan 2021 23:58:49 +0530 Subject: [PATCH] Fix #16463 - 'REFERENCES' privilege checkbox's title Set different title messages depending on database and database version for 'REFERENCES' field in user 'Edit Preferences' form. Co-Authored-By: William Desportes Signed-off-by: Prashant Tholia --- libraries/classes/DatabaseInterface.php | 2 ++ libraries/classes/Query/Compatibility.php | 17 +++++++++++++++++ libraries/classes/Server/Privileges.php | 3 +++ .../server/privileges/privileges_table.twig | 3 ++- 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/libraries/classes/DatabaseInterface.php b/libraries/classes/DatabaseInterface.php index 82d397b955..378863cc2f 100644 --- a/libraries/classes/DatabaseInterface.php +++ b/libraries/classes/DatabaseInterface.php @@ -2407,6 +2407,8 @@ class DatabaseInterface implements DbalInterface /** * Server version as number + * + * @example 80011 */ public function getVersion(): int { diff --git a/libraries/classes/Query/Compatibility.php b/libraries/classes/Query/Compatibility.php index 16c8658071..6e6accace4 100644 --- a/libraries/classes/Query/Compatibility.php +++ b/libraries/classes/Query/Compatibility.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Query; +use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Util; use function is_string; use function strlen; @@ -185,4 +186,20 @@ class Compatibility return false; } + + public static function supportsReferencesPrivilege(DatabaseInterface $dbi): bool + { + // See: https://mariadb.com/kb/en/grant/#table-privileges + // Unused + if ($dbi->isMariaDB()) { + return false; + } + + // https://dev.mysql.com/doc/refman/5.6/en/privileges-provided.html#priv_references + // This privilege is unused before MySQL 5.6.22. + // As of 5.6.22, creation of a foreign key constraint + // requires at least one of the SELECT, INSERT, UPDATE, DELETE, + // or REFERENCES privileges for the parent table. + return $dbi->getVersion() >= 50622; + } } diff --git a/libraries/classes/Server/Privileges.php b/libraries/classes/Server/Privileges.php index cd4f4b4755..0b4d32e313 100644 --- a/libraries/classes/Server/Privileges.php +++ b/libraries/classes/Server/Privileges.php @@ -12,6 +12,7 @@ use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Html\Generator; use PhpMyAdmin\Html\MySQLDocumentation; use PhpMyAdmin\Message; +use PhpMyAdmin\Query\Compatibility; use PhpMyAdmin\Relation; use PhpMyAdmin\RelationCleanup; use PhpMyAdmin\Response; @@ -736,6 +737,8 @@ class Privileges 'row' => $row, 'columns' => $columns ?? [], 'has_submit' => $submit, + 'supports_references_privilege' => Compatibility::supportsReferencesPrivilege($this->dbi), + 'is_mariadb' => $this->dbi->isMariaDB(), ]); } diff --git a/templates/server/privileges/privileges_table.twig b/templates/server/privileges/privileges_table.twig index 3e3f8eadeb..721ca01e64 100644 --- a/templates/server/privileges/privileges_table.twig +++ b/templates/server/privileges/privileges_table.twig @@ -642,7 +642,8 @@ {%- trans 'Has no effect in this MySQL version.' %}"{{ row['References_priv'] == 'Y' ? ' checked' }}>