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

Ensure that civicrm_dashboard has a foreign key to civicrm_domain #15119

Merged
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
4 changes: 2 additions & 2 deletions CRM/Core/BAO/SchemaHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ public static function checkFKExists($table_name, $constraint_name) {
2 => [$table_name, 'String'],
3 => [$constraint_name, 'String'],
];
$dao = CRM_Core_DAO::executeQuery($query, $params);
$dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, NULL, FALSE, FALSE);

if ($dao->fetch()) {
return TRUE;
Expand All @@ -644,7 +644,7 @@ public static function checkFKExists($table_name, $constraint_name) {
*/
public static function safeRemoveFK($table_name, $constraint_name) {
if (self::checkFKExists($table_name, $constraint_name)) {
CRM_Core_DAO::executeQuery("ALTER TABLE {$table_name} DROP FOREIGN KEY {$constraint_name}", []);
CRM_Core_DAO::executeQuery("ALTER TABLE {$table_name} DROP FOREIGN KEY {$constraint_name}", [], TRUE, NULL, FALSE, FALSE);
return TRUE;
}
return FALSE;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/DAO/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Core/Dashboard.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:2b085baa3414de05ee5c52a4d7d4f81f)
* (GenCodeChecksum:6fd1bfbecace855a159025ad31e37fb0)
*/

/**
Expand Down
19 changes: 19 additions & 0 deletions CRM/Upgrade/Incremental/php/FiveEighteen.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,25 @@ public function upgrade_5_18_alpha1($rev) {
['old' => 'is_override', 'new' => 'member_is_override'],
],
]);
$this->addTask('Remove Foreign Key from civicrm_dashboard on domain_id if exists', 'removeDomainIDFK');
$this->addTask('Remove Index on domain_id that might have been randomly added in the same format as FK', 'dropIndex', 'civicrm_dashboard', 'FK_civicrm_dashboard_domain_id');
$this->addTask('Re-Create Foreign key between civicrm_dashboard and civicrm_domain correctly', 'recreateDashboardFK');
}

public static function removeDomainIDFK() {
CRM_Core_BAO_SchemaHandler::safeRemoveFK('civicrm_dashboard', 'FK_civicrm_dashboard_domain_id');
return TRUE;
}

public static function recreateDashboardFK() {
$sql = CRM_Core_BAO_SchemaHandler::buildForeignKeySQL([
'fk_table_name' => 'civicrm_domain',
'fk_field_name' => 'id',
'name' => 'domain_id',
'fk_attributes' => ' ON DELETE CASCADE',
], "\n", " ADD ", 'civicrm_dashboard');
CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_dashboard " . $sql, [], TRUE, NULL, FALSE, FALSE);
return TRUE;
}

// public static function taskFoo(CRM_Queue_TaskContext $ctx, ...) {
Expand Down
1 change: 1 addition & 0 deletions xml/schema/Core/Dashboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<table>civicrm_domain</table>
<key>id</key>
<add>3.1</add>
<onDelete>CASCADE</onDelete>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well the column def is a NOT NULL column so its the only one that seemed to make sense to me

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

</foreignKey>
<field>
<name>name</name>
Expand Down