Skip to content
Open
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
3 changes: 0 additions & 3 deletions CRM/Core/BAO/OptionValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ public static function getDefaultWeight($params) {
public static function getDefaultValue($params) {
$bao = new CRM_Core_BAO_OptionValue();
$bao->option_group_id = $params['option_group_id'];
if (isset($params['domain_id'])) {
$bao->domain_id = $params['domain_id'];
}
$bao->selectAdd();
$bao->whereAdd("value REGEXP '^[0-9]+$'");
$bao->selectAdd('(ROUND(COALESCE(MAX(CONVERT(value, UNSIGNED)),0)) +1) as nextvalue');
Expand Down
2 changes: 0 additions & 2 deletions CRM/Core/CodeGen/OptionGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class CRM_Core_CodeGen_OptionGroup extends CRM_Core_CodeGen_AbstractSqlData {
'color' => NULL,
'component_id' => NULL,
'description' => NULL,
'domain_id' => NULL,
'filter' => 0,
'grouping' => NULL,
'icon' => NULL,
Expand Down Expand Up @@ -90,7 +89,6 @@ public function toSQL(): string {

$result .= CRM_Utils_SQL_Insert::into('civicrm_option_value')
->allowLiterals()
// ->columns(['option_group_id', 'label', 'value', 'name', 'grouping', 'filter', 'is_default', 'weight', 'description', 'is_optgroup', 'is_reserved', 'is_active', 'component_id', 'visibility_id'])
->rows($rows)
->toSQL() . ";\n";
}
Expand Down
2 changes: 2 additions & 0 deletions CRM/Upgrade/Incremental/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ public static function alterSchemaField($ctx, string $entityName, string $fieldN
else {
self::addColumn($ctx, $tableName, $fieldName, $fieldSql, !empty($fieldSpec['localizable']), $version, $triggerRebuild);
}
Civi::schemaHelper()->dropForeignKeysForColumn($tableName, $fieldName);
Civi::schemaHelper()->createForeignKey($tableName, $fieldName, $fieldSpec);
return TRUE;
}
Expand Down Expand Up @@ -640,6 +641,7 @@ public static function updateCurrencyName($ctx, string $old_name, string $new_na
*/
public static function dropColumn($ctx, $table, $column) {
if (CRM_Core_BAO_SchemaHandler::checkIfFieldExists($table, $column)) {
Civi::schemaHelper()->dropForeignKeysForColumn($table, $column);
CRM_Core_DAO::executeQuery("ALTER TABLE `$table` DROP COLUMN `$column`",
[], TRUE, NULL, FALSE, FALSE);
}
Expand Down
1 change: 1 addition & 0 deletions CRM/Upgrade/Incremental/php/SixNineteen.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class CRM_Upgrade_Incremental_php_SixNineteen extends CRM_Upgrade_Incremental_Ba
*/
public function upgrade_6_19_alpha1($rev): void {
$this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
$this->addTask('Drop OptionValue.domain_id column', 'dropColumn', 'civicrm_option_value', 'domain_id');
}

}
2 changes: 0 additions & 2 deletions ext/civicrm_search_ui/managed/OptionGroup_report_type.mgd.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
'component_id' => NULL,
'icon' => NULL,
'color' => NULL,
'domain_id' => NULL,
'visibility_id' => NULL,
],
'match' => ['name'],
Expand Down Expand Up @@ -75,7 +74,6 @@
'component_id' => NULL,
'icon' => NULL,
'color' => NULL,
'domain_id' => NULL,
'visibility_id' => NULL,
],
'match' => ['name'],
Expand Down
1 change: 0 additions & 1 deletion ext/civigrant/CRM/Grant/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public function upgrade_1002(): bool {
AND dup_ov.option_group_id = %1';
if ($optionGroupId) {
CRM_Core_DAO::executeQuery($deleteDuplicates, [1 => [$optionGroupId, 'Integer']]);
CRM_Core_DAO::executeQuery("UPDATE civicrm_option_value SET domain_id = NULL WHERE option_group_id = %1", [1 => [$optionGroupId, 'Integer']]);
}

return TRUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
'icon' => NULL,
'color' => NULL,
'component_id' => NULL,
'domain_id' => NULL,
'visibility_id' => NULL,
],
'match' => ['option_group_id', 'name'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
'icon' => NULL,
'color' => NULL,
'component_id' => NULL,
'domain_id' => NULL,
'visibility_id' => NULL,
],
'match' => ['option_group_id', 'name'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
'component_id' => NULL,
'icon' => NULL,
'color' => NULL,
'domain_id' => NULL,
'visibility_id' => NULL,
],
'match' => ['name'],
Expand Down Expand Up @@ -54,7 +53,6 @@
'component_id' => NULL,
'icon' => NULL,
'color' => NULL,
'domain_id' => NULL,
'visibility_id' => NULL,
],
'match' => ['option_group_id', 'name'],
Expand Down
24 changes: 24 additions & 0 deletions mixin/lib/civimix-schema@5/src/SchemaHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public function alterSchemaField(string $entityName, string $fieldName, array $f
\CRM_Core_DAO::executeQuery($query, i18nRewrite: FALSE);

// Add FK constraint if needed.
$this->dropForeignKeysForColumn($tableName, $fieldName);
$this->createForeignKey($tableName, $fieldName, $fieldSpec);

return TRUE;
Expand All @@ -170,6 +171,7 @@ public function alterSchemaField(string $entityName, string $fieldName, array $f
public function dropSchemaField(string $entityName, string $fieldName): bool {
if ($this->schemaFieldExists($entityName, $fieldName)) {
$tableName = $this->getTableName($entityName);
$this->dropForeignKeysForColumn($tableName, $fieldName);
\CRM_Core_DAO::executeQuery("ALTER TABLE `$tableName` DROP COLUMN `$fieldName`", i18nRewrite: FALSE);
}
return TRUE;
Expand Down Expand Up @@ -232,6 +234,28 @@ public function dropForeignKey(string $tableName, string $foreignKeyName): bool
return \CRM_Core_BAO_SchemaHandler::safeRemoveFK($tableName, $foreignKeyName);
}

/**
* @internal
*/
public function dropForeignKeysForColumn(string $tableName, string $fieldName): void {
$dao = \CRM_Core_DAO::executeQuery(
"SELECT CONSTRAINT_NAME AS constraint_name
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = %1
AND COLUMN_NAME = %2
AND REFERENCED_TABLE_NAME IS NOT NULL",
[
1 => [$tableName, 'String'],
2 => [$fieldName, 'String'],
],
i18nRewrite: FALSE
);
while ($dao->fetch()) {
$this->dropForeignKey($tableName, $dao->constraint_name);
}
}

/**
* @param array $sqls
* List of SQL scripts.
Expand Down
20 changes: 0 additions & 20 deletions schema/Core/OptionValue.entityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,26 +204,6 @@
'key' => 'id',
],
],
'domain_id' => [
'title' => ts('Domain ID'),
'sql_type' => 'int unsigned',
'input_type' => 'EntityRef',
'deprecated' => TRUE,
'description' => ts('Unused deprecated column.'),
'add' => '3.1',
'input_attrs' => [
'label' => ts('Domain'),
],
'pseudoconstant' => [
'table' => 'civicrm_domain',
'key_column' => 'id',
'label_column' => 'name',
],
'entity_reference' => [
'entity' => 'Domain',
'key' => 'id',
],
],
'visibility_id' => [
'title' => ts('Option Visibility'),
'sql_type' => 'int unsigned',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,19 @@
'is_default' => 1,
'is_reserved' => 1,
'component_id' => 4,
'domain_id' => 1,
],
[
'label' => ts('Rejected'),
'value' => 2,
'name' => 'Rejected',
'is_reserved' => 1,
'component_id' => 4,
'domain_id' => 1,
],
[
'label' => ts('None'),
'value' => 3,
'name' => 'None',
'is_reserved' => 1,
'component_id' => 4,
'domain_id' => 1,
],
]);
Loading