Skip to content

Commit

Permalink
Ensure that civicrm_dashboard has a foreign key to civicrm_domain
Browse files Browse the repository at this point in the history
  • Loading branch information
seamuslee001 committed Aug 23, 2019
1 parent 5c6fd6e commit 9e9b81d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
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);
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>
</foreignKey>
<field>
<name>name</name>
Expand Down

0 comments on commit 9e9b81d

Please sign in to comment.