'start_date' => 'rel.start_date',
'end_date' => 'rel.end_date',
'is_active' => 'rel.is_active',
+ 'case_id' => 'rel.case_id',
],
'b_a' => [
'relationship_id' => 'rel.id',
'start_date' => 'rel.start_date',
'end_date' => 'rel.end_date',
'is_active' => 'rel.is_active',
+ 'case_id' => 'rel.case_id',
],
];
*
* Generated from xml/schema/CRM/Contact/RelationshipCache.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:0ebd9cc2623ee84848476636cfe86dcb)
+ * (GenCodeChecksum:f70f357cd7e45be254350f45ef41aee2)
*/
/**
*/
public $end_date;
+ /**
+ * FK to civicrm_case
+ *
+ * @var int
+ */
+ public $case_id;
+
/**
* Class constructor.
*/
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'relationship_type_id', 'civicrm_relationship_type', 'id');
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'near_contact_id', 'civicrm_contact', 'id');
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'far_contact_id', 'civicrm_contact', 'id');
+ Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'case_id', 'civicrm_case', 'id');
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
}
return Civi::$statics[__CLASS__]['links'];
'readonly' => TRUE,
'add' => '5.29',
],
+ 'case_id' => [
+ 'name' => 'case_id',
+ 'type' => CRM_Utils_Type::T_INT,
+ 'title' => ts('Case ID'),
+ 'description' => ts('FK to civicrm_case'),
+ 'where' => 'civicrm_relationship_cache.case_id',
+ 'default' => 'NULL',
+ 'table_name' => 'civicrm_relationship_cache',
+ 'entity' => 'RelationshipCache',
+ 'bao' => 'CRM_Contact_BAO_RelationshipCache',
+ 'localizable' => 0,
+ 'FKClassName' => 'CRM_Case_DAO_Case',
+ 'component' => 'CiviCase',
+ 'html' => [
+ 'label' => ts("Case"),
+ ],
+ 'readonly' => TRUE,
+ 'add' => '5.44',
+ ],
];
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
}
// }
}
- /*
- * Important! All upgrade functions MUST add a 'runSql' task.
- * Uncomment and use the following template for a new upgrade version
- * (change the x in the function name):
+ /**
+ * Upgrade function.
+ * @param string $rev
*/
+ public function upgrade_5_44_alpha1($rev) {
+ // The runSql task populates the new column, so this addColumn task runs first
+ $this->addTask('Add case_id column to civicrm_relationship_cache', 'addColumn',
+ 'civicrm_relationship_cache', 'case_id', "int unsigned DEFAULT NULL COMMENT 'FK to civicrm_case'"
+ );
+ $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
+ $this->addTask('Add FK to civicrm_relationship_cache.case_id', 'addRelationshipCacheCaseFK');
+ }
- // /**
- // * Upgrade function.
- // *
- // * @param string $rev
- // */
- // public function upgrade_5_0_x($rev): void {
- // $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
- // $this->addTask('Do the foo change', 'taskFoo', ...);
- // // Additional tasks here...
- // // Note: do not use ts() in the addTask description because it adds unnecessary strings to transifex.
- // // The above is an exception because 'Upgrade DB to %1: SQL' is generic & reusable.
- // }
-
- // public static function taskFoo(CRM_Queue_TaskContext $ctx, ...): bool {
- // return TRUE;
- // }
+ /**
+ * @param \CRM_Queue_TaskContext $ctx
+ * @return bool
+ */
+ public static function addRelationshipCacheCaseFK(CRM_Queue_TaskContext $ctx): bool {
+ if (!self::checkFKExists('civicrm_relationship_cache', 'FK_civicrm_relationship_cache_case_id')) {
+ CRM_Core_DAO::executeQuery("
+ ALTER TABLE `civicrm_relationship_cache`
+ ADD CONSTRAINT `FK_civicrm_relationship_cache_case_id`
+ FOREIGN KEY (`case_id`) REFERENCES `civicrm_case` (`id`)
+ ON DELETE CASCADE;
+ ", [], TRUE, NULL, FALSE, FALSE);
+ }
+ return TRUE;
+ }
}
{* file to handle db changes in 5.44.alpha1 during upgrade *}
+
+{* Polulate RelationshipCache.case_id column *}
+UPDATE `civicrm_relationship_cache` rc, `civicrm_relationship` r SET rc.case_id = r.case_id WHERE r.case_id IS NOT NULL AND r.id = rc.relationship_id;
</html>
<readonly>true</readonly>
</field>
+ <field>
+ <name>case_id</name>
+ <type>int unsigned</type>
+ <component>CiviCase</component>
+ <title>Case ID</title>
+ <default>NULL</default>
+ <comment>FK to civicrm_case</comment>
+ <html>
+ <label>Case</label>
+ </html>
+ <add>5.44</add>
+ <readonly>true</readonly>
+ </field>
+ <foreignKey>
+ <name>case_id</name>
+ <table>civicrm_case</table>
+ <key>id</key>
+ <add>2.2</add>
+ <onDelete>CASCADE</onDelete>
+ </foreignKey>
</table>