Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NFC - Deprecate duplicate function #12602

Merged
merged 2 commits into from
Jul 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CRM/Core/BAO/ConfigSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static function retrieve(&$defaults) {
$urlVar = 'task';
}

if ($isUpgrade && CRM_Core_DAO::checkFieldExists('civicrm_domain', 'config_backend')) {
if ($isUpgrade && CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_domain', 'config_backend')) {
$domain->selectAdd('config_backend');
}
else {
Expand Down
17 changes: 8 additions & 9 deletions CRM/Core/BAO/SchemaHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -627,18 +627,17 @@ public static function checkIfIndexExists($tableName, $indexName) {
*
* @param string $tableName
* @param string $columnName
* @param bool $i18nRewrite
* Whether to rewrite the query on multilingual setups.
*
* @return bool
*/
public static function checkIfFieldExists($tableName, $columnName) {
$result = CRM_Core_DAO::executeQuery(
"SHOW COLUMNS FROM $tableName LIKE %1",
array(1 => array($columnName, 'String'))
);
if ($result->fetch()) {
return TRUE;
}
return FALSE;
public static function checkIfFieldExists($tableName, $columnName, $i18nRewrite = TRUE) {
$query = "SHOW COLUMNS FROM $tableName LIKE '%1'";
$dao = CRM_Core_DAO::executeQuery($query, [1 => [$columnName, 'Alphanumeric']], TRUE, NULL, FALSE, $i18nRewrite);
$result = $dao->fetch() ? TRUE : FALSE;
$dao->free();
return $result;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions CRM/Core/BAO/UFGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -1673,12 +1673,12 @@ public static function getWeight($ufGroupId = NULL) {
public static function getModuleUFGroup($moduleName = NULL, $count = 0, $skipPermission = TRUE, $op = CRM_Core_Permission::VIEW, $returnFields = NULL) {
$selectFields = array('id', 'title', 'created_id', 'is_active', 'is_reserved', 'group_type');

if (CRM_Core_DAO::checkFieldExists('civicrm_uf_group', 'description')) {
if (CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_uf_group', 'description')) {
// CRM-13555, since description field was added later (4.4), and to avoid any problems with upgrade
$selectFields[] = 'description';
}

if (CRM_Core_DAO::checkFieldExists('civicrm_uf_group', 'frontend_title')) {
if (CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_uf_group', 'frontend_title')) {
$selectFields[] = 'frontend_title';
}

Expand Down
14 changes: 4 additions & 10 deletions CRM/Core/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,9 @@ public static function objectExists($value, $daoName, $daoID, $fieldName = 'name
/**
* Check if there is a given column in a specific table.
*
* @deprecated
* @see CRM_Core_BAO_SchemaHandler::checkIfFieldExists
*
* @param string $tableName
* @param string $columnName
* @param bool $i18nRewrite
Expand All @@ -858,16 +861,7 @@ public static function objectExists($value, $daoName, $daoID, $fieldName = 'name
* true if exists, else false
*/
public static function checkFieldExists($tableName, $columnName, $i18nRewrite = TRUE) {
$query = "
SHOW COLUMNS
FROM $tableName
LIKE %1
";
$params = array(1 => array($columnName, 'String'));
$dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, NULL, FALSE, $i18nRewrite);
$result = $dao->fetch() ? TRUE : FALSE;
$dao->free();
return $result;
return CRM_Core_BAO_SchemaHandler::checkIfFieldExists($tableName, $columnName, $i18nRewrite);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/I18n/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public static function addLocale($locale, $source) {
// add new columns
foreach ($hash as $column => $type) {
// CRM-7854: skip existing columns
if (CRM_Core_DAO::checkFieldExists($table, "{$column}_{$locale}", FALSE)) {
if (CRM_Core_BAO_SchemaHandler::checkIfFieldExists($table, "{$column}_{$locale}", FALSE)) {
continue;
}
$queries[] = "ALTER TABLE {$table} ADD {$column}_{$locale} {$type}";
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public static function store($truncate = TRUE) {
$menu->find(TRUE);

if (!CRM_Core_Config::isUpgradeMode() ||
CRM_Core_DAO::checkFieldExists('civicrm_menu', 'module_data', FALSE)
CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_menu', 'module_data', FALSE)
) {
// Move unrecognized fields to $module_data.
$module_data = array();
Expand Down
2 changes: 1 addition & 1 deletion CRM/Upgrade/Incremental/php/FourSeven.php
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ public static function alterIndexAndTypeForImageURL() {
* @return bool
*/
public static function addMailingTemplateType() {
if (!CRM_Core_DAO::checkFieldExists('civicrm_mailing', 'template_type', FALSE)) {
if (!CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_mailing', 'template_type', FALSE)) {
CRM_Core_DAO::executeQuery('
ALTER TABLE civicrm_mailing
ADD COLUMN `template_type` varchar(64) NOT NULL DEFAULT \'traditional\' COMMENT \'The language/processing system used for email templates.\',
Expand Down
10 changes: 5 additions & 5 deletions CRM/Upgrade/Incremental/php/FourThree.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public function upgrade_4_3_alpha1($rev) {
*/
public function upgrade_4_3_alpha2($rev) {
//CRM-11847
$isColumnPresent = CRM_Core_DAO::checkFieldExists('civicrm_dedupe_rule_group', 'is_default');
$isColumnPresent = CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_dedupe_rule_group', 'is_default');
if ($isColumnPresent) {
CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_dedupe_rule_group DROP COLUMN is_default');
}
Expand All @@ -300,7 +300,7 @@ public function upgrade_4_3_beta2($rev) {
// CRM-12002
if (
CRM_Core_DAO::checkTableExists('log_civicrm_line_item') &&
CRM_Core_DAO::checkFieldExists('log_civicrm_line_item', 'label')
CRM_Core_BAO_SchemaHandler::checkIfFieldExists('log_civicrm_line_item', 'label')
) {
CRM_Core_DAO::executeQuery('ALTER TABLE `log_civicrm_line_item` CHANGE `label` `label` VARCHAR(255) NULL DEFAULT NULL');
}
Expand Down Expand Up @@ -335,15 +335,15 @@ public function upgrade_4_3_beta5($rev) {
// CRM-12205
if (
CRM_Core_DAO::checkTableExists('log_civicrm_financial_trxn') &&
CRM_Core_DAO::checkFieldExists('log_civicrm_financial_trxn', 'trxn_id')
CRM_Core_BAO_SchemaHandler::checkIfFieldExists('log_civicrm_financial_trxn', 'trxn_id')
) {
CRM_Core_DAO::executeQuery('ALTER TABLE `log_civicrm_financial_trxn` CHANGE `trxn_id` `trxn_id` VARCHAR(255) NULL DEFAULT NULL');
}
// CRM-12142 - some sites didn't get this column added yet, and sites which installed 4.3 from scratch will already have it
// CRM-12367 - add this column to single lingual sites only
$upgrade = new CRM_Upgrade_Form();
if (!$upgrade->multilingual &&
!CRM_Core_DAO::checkFieldExists('civicrm_premiums', 'premiums_nothankyou_label')
!CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_premiums', 'premiums_nothankyou_label')
) {
$query = "
ALTER TABLE civicrm_premiums
Expand Down Expand Up @@ -925,7 +925,7 @@ public function task_4_3_alpha1_checkDBConstraints() {
}
}
// check if column contact_id is present or not in civicrm_financial_account
$fieldExists = CRM_Core_DAO::checkFieldExists('civicrm_financial_account', 'contact_id', FALSE);
$fieldExists = CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_financial_account', 'contact_id', FALSE);
if (!$fieldExists) {
$query = "
ALTER TABLE civicrm_financial_account
Expand Down
4 changes: 2 additions & 2 deletions Civi/Core/SettingsBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function loadValues() {

$isUpgradeMode = \CRM_Core_Config::isUpgradeMode();

if ($isUpgradeMode && empty($this->contactId) && \CRM_Core_DAO::checkFieldExists('civicrm_domain', 'config_backend', FALSE)) {
if ($isUpgradeMode && empty($this->contactId) && \CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_domain', 'config_backend', FALSE)) {
$config_backend = \CRM_Core_DAO::singleValueQuery('SELECT config_backend FROM civicrm_domain WHERE id = %1',
array(1 => array($this->domainId, 'Positive')));
$oldSettings = \CRM_Upgrade_Incremental_php_FourSeven::convertBackendToSettings($this->domainId, $config_backend);
Expand Down Expand Up @@ -373,7 +373,7 @@ protected function setDb($name, $value) {
if (!isset(\Civi::$statics[__CLASS__]['upgradeMode'])) {
\Civi::$statics[__CLASS__]['upgradeMode'] = \CRM_Core_Config::isUpgradeMode();
}
if (\Civi::$statics[__CLASS__]['upgradeMode'] && \CRM_Core_DAO::checkFieldExists('civicrm_setting', 'group_name')) {
if (\Civi::$statics[__CLASS__]['upgradeMode'] && \CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_setting', 'group_name')) {
$dao->group_name = 'placeholder';
}

Expand Down
2 changes: 1 addition & 1 deletion Civi/Core/SqlTrigger/StaticTriggers.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function alterTriggerInfo(&$info, $tableFilter = NULL) {

if (\CRM_Core_Config::isUpgradeMode() && isset($trigger['upgrade_check'])) {
$uc = $trigger['upgrade_check'];
if (!\CRM_Core_DAO::checkFieldExists($uc['table'], $uc['column'])
if (!\CRM_Core_BAO_SchemaHandler::checkIfFieldExists($uc['table'], $uc['column'])
) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion Civi/Core/SqlTrigger/TimestampTriggers.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function alterTriggerInfo(&$info, $tableFilter = NULL) {
// In the past, this was a version-based check, but checkFieldExists()
// seems more robust.
if (\CRM_Core_Config::isUpgradeMode()) {
if (!\CRM_Core_DAO::checkFieldExists($this->getTableName(),
if (!\CRM_Core_BAO_SchemaHandler::checkIfFieldExists($this->getTableName(),
$this->getCreatedDate())
) {
return;
Expand Down