Skip to content

Commit

Permalink
dev/core#2073 Fix use of legacy leaky method in tested code
Browse files Browse the repository at this point in the history
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
----------------------------------------
  • Loading branch information
eileenmcnaughton committed Oct 7, 2020
1 parent 97240a7 commit 808ca92
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions CRM/Import/DataSource/CSV.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,9 @@ private static function _CsvToTable(
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";
}
Expand Down Expand Up @@ -188,13 +187,11 @@ private static function _CsvToTable(
}

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);
Expand Down Expand Up @@ -234,8 +231,7 @@ function($string) {
$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;
Expand All @@ -244,8 +240,7 @@ function($string) {
}

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);
Expand Down

0 comments on commit 808ca92

Please sign in to comment.