From 6ef58b186b8b59702afb0f2b03ef21bf140d665a Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Mon, 11 Nov 2019 06:52:10 +1100 Subject: [PATCH] dev/core#183 Use CRM_Utils_SQL_TempTable for generating temp table name for testing install requirements Handle for the fact D8 does not add in the class loader before doing the check requirements and also convert in the legacy installer as well --- Civi/Install/Requirements.php | 9 ++++++--- install/index.php | 16 +++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Civi/Install/Requirements.php b/Civi/Install/Requirements.php index 63b6cb0552..acaa62f832 100644 --- a/Civi/Install/Requirements.php +++ b/Civi/Install/Requirements.php @@ -58,6 +58,9 @@ class Requirements { * An array of check summaries. Each array contains the keys 'title', 'severity', and 'details'. */ public function checkAll(array $config) { + if (!class_exists('\CRM_Utils_SQL_TempTable')) { + require_once dirname(__FILE__) . '/../../CRM/Utils/SQL/TempTable.php'; + } return array_merge($this->checkSystem($config['file_paths']), $this->checkDatabase($config['db_config'])); } @@ -373,15 +376,15 @@ class Requirements { $results['details'] = "Could not select the database"; return $results; } - - $r = mysqli_query($conn, 'CREATE TEMPORARY TABLE civicrm_install_temp_table_test (test text)'); + $temporaryTableName = \CRM_Utils_SQL_TempTable::build()->setCategory('install')->getName(); + $r = mysqli_query($conn, 'CREATE TEMPORARY TABLE ' . $temporaryTableName . ' (test text)'); if (!$r) { $results['severity'] = $this::REQUIREMENT_ERROR; $results['details'] = "Database does not support creation of temporary tables"; return $results; } - mysqli_query($conn, 'DROP TEMPORARY TABLE civicrm_install_temp_table_test'); + mysqli_query($conn, 'DROP TEMPORARY TABLE ' . $temporaryTableName); return $results; } diff --git a/install/index.php b/install/index.php index 585cea24ac..53719f19a2 100644 --- a/install/index.php +++ b/install/index.php @@ -1127,12 +1127,13 @@ class InstallRequirements { return; } - $result = mysqli_query($conn, 'CREATE TEMPORARY TABLE civicrm_install_temp_table_test (test text)'); + $tempTableName = CRM_Utils_SQL_TempTable::build()->setCategory('install')->getName(); + $result = mysqli_query($conn, 'CREATE TEMPORARY TABLE ' . $tempTableName . ' (test text)'); if (!$result) { $testDetails[2] = ts('Could not create a temp table.'); $this->error($testDetails); } - $result = mysqli_query($conn, 'DROP TEMPORARY TABLE civicrm_install_temp_table_test'); + $result = mysqli_query($conn, 'DROP TEMPORARY TABLE ' . $tempTableName); } /** @@ -1196,18 +1197,19 @@ class InstallRequirements { return; } - $result = mysqli_query($conn, 'CREATE TEMPORARY TABLE civicrm_install_temp_table_test (test text)'); + $tempTableName = CRM_Utils_SQL_TempTable::build()->setCategory('install')->getName(); + $result = mysqli_query($conn, 'CREATE TEMPORARY TABLE ' . $tempTableName . ' (test text)'); if (!$result) { $testDetails[2] = ts('Could not create a table in the database.'); $this->error($testDetails); return; } - $result = mysqli_query($conn, 'LOCK TABLES civicrm_install_temp_table_test WRITE'); + $result = mysqli_query($conn, 'LOCK TABLES ' . $tempTableName . ' WRITE'); if (!$result) { $testDetails[2] = ts('Could not obtain a write lock for the database table.'); $this->error($testDetails); - $result = mysqli_query($conn, 'DROP TEMPORARY TABLE civicrm_install_temp_table_test'); + $result = mysqli_query($conn, 'DROP TEMPORARY TABLE ' . $tempTableName); return; } @@ -1215,11 +1217,11 @@ class InstallRequirements { if (!$result) { $testDetails[2] = ts('Could not release the lock for the database table.'); $this->error($testDetails); - $result = mysqli_query($conn, 'DROP TEMPORARY TABLE civicrm_install_temp_table_test'); + $result = mysqli_query($conn, 'DROP TEMPORARY TABLE ' . $tempTableName); return; } - $result = mysqli_query($conn, 'DROP TEMPORARY TABLE civicrm_install_temp_table_test'); + $result = mysqli_query($conn, 'DROP TEMPORARY TABLE ' . $tempTableName); } /** -- 2.25.1