From 808ca9206839659c3344cfa185c0d126a15d2d67 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 8 Oct 2020 09:37:26 +1300 Subject: [PATCH] dev/core#2073 Fix use of legacy leaky method in tested code Overview ---------------------------------------- Fix use of legacy leaky method in tested code Before ---------------------------------------- dao->query() After ---------------------------------------- CRM_Core_DAO::executeQuery() Technical Details ---------------------------------------- This is too low volume to really leak but it uses the leaky legacy method and has test cover in CRM_Import_DataSource_CsvTest.testToCsv with data set #0 CRM_Import_DataSource_CsvTest.testToCsv with data set #1 ---------------------------------------- --- CRM/Import/DataSource/CSV.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/CRM/Import/DataSource/CSV.php b/CRM/Import/DataSource/CSV.php index 9651e47888..6aa4e7be15 100644 --- a/CRM/Import/DataSource/CSV.php +++ b/CRM/Import/DataSource/CSV.php @@ -129,10 +129,9 @@ class CRM_Import_DataSource_CSV extends CRM_Import_DataSource { throw new CRM_Core_Exception("$file is empty. Please upload a valid file."); } - $config = CRM_Core_Config::singleton(); // support tab separated - if (strtolower($fieldSeparator) == 'tab' || - strtolower($fieldSeparator) == '\t' + if (strtolower($fieldSeparator) === 'tab' || + strtolower($fieldSeparator) === '\t' ) { $fieldSeparator = "\t"; } @@ -188,13 +187,11 @@ class CRM_Import_DataSource_CSV extends CRM_Import_DataSource { } if ($tableName) { - // Drop previous table if passed in and create new one. - $db->query("DROP TABLE IF EXISTS $tableName"); + CRM_Core_DAO::executeQuery("DROP TABLE IF EXISTS $tableName"); } $table = CRM_Utils_SQL_TempTable::build()->setDurable(); $tableName = $table->getName(); - // Do we still need this? - $db->query("DROP TABLE IF EXISTS $tableName"); + CRM_Core_DAO::executeQuery("DROP TABLE IF EXISTS $tableName"); $table->createWithColumns(implode(' text, ', $columns) . ' text'); $numColumns = count($columns); @@ -234,8 +231,7 @@ class CRM_Import_DataSource_CSV extends CRM_Import_DataSource { $count++; if ($count >= self::NUM_ROWS_TO_INSERT && !empty($sql)) { - $sql = "INSERT IGNORE INTO $tableName VALUES $sql"; - $db->query($sql); + CRM_Core_DAO::executeQuery("INSERT IGNORE INTO $tableName VALUES $sql"); $sql = NULL; $first = TRUE; @@ -244,8 +240,7 @@ class CRM_Import_DataSource_CSV extends CRM_Import_DataSource { } if (!empty($sql)) { - $sql = "INSERT IGNORE INTO $tableName VALUES $sql"; - $db->query($sql); + CRM_Core_DAO::executeQuery("INSERT IGNORE INTO $tableName VALUES $sql"); } fclose($fd); -- 2.25.1