As with other tables we have done this to, knowing when we added a record to the
DB is useful (and differs from the relationship start_date).
I'm not sure yet if I will try to expose in the UI or whether search-kit
is all we need
*
* Generated from xml/schema/CRM/Contact/Relationship.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:4d689d3ccc5aa155c858aac2f24ddfab)
+ * (GenCodeChecksum:31dfa249bbf980b8094bce3ff7f70fc9)
*/
/**
*/
public $case_id;
+ /**
+ * Relationship created date.
+ *
+ * @var timestamp
+ */
+ public $created_date;
+
+ /**
+ * Relationship last modified.
+ *
+ * @var timestamp
+ */
+ public $modified_date;
+
/**
* Class constructor.
*/
],
'add' => '2.2',
],
+ 'created_date' => [
+ 'name' => 'created_date',
+ 'type' => CRM_Utils_Type::T_TIMESTAMP,
+ 'title' => ts('Created Date'),
+ 'description' => ts('Relationship created date.'),
+ 'required' => TRUE,
+ 'where' => 'civicrm_relationship.created_date',
+ 'default' => 'CURRENT_TIMESTAMP',
+ 'table_name' => 'civicrm_relationship',
+ 'entity' => 'Relationship',
+ 'bao' => 'CRM_Contact_BAO_Relationship',
+ 'localizable' => 0,
+ 'add' => '5.47',
+ ],
+ 'modified_date' => [
+ 'name' => 'modified_date',
+ 'type' => CRM_Utils_Type::T_TIMESTAMP,
+ 'title' => ts('Relationship Modified Date'),
+ 'description' => ts('Relationship last modified.'),
+ 'required' => TRUE,
+ 'where' => 'civicrm_relationship.modified_date',
+ 'default' => 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
+ 'table_name' => 'civicrm_relationship',
+ 'entity' => 'Relationship',
+ 'bao' => 'CRM_Contact_BAO_Relationship',
+ 'localizable' => 0,
+ 'readonly' => TRUE,
+ 'add' => '5.47',
+ ],
];
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
}
public function upgrade_5_47_alpha1($rev): void {
$this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
$this->addTask('Migrate CiviGrant component to an extension', 'migrateCiviGrant');
+ $this->addTask('Add created_date to civicrm_relationship', 'addColumn', 'civicrm_relationship', 'created_date',
+ "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Relationship created date'"
+ );
+ $this->addTask('Add modified_date column to civicrm_relationship', 'addColumn',
+ 'civicrm_relationship', 'modified_date',
+ "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Relationship last modified.'"
+ );
+ $this->addTask('Set initial value for relationship created_date and modified_date to start_date', 'updateRelationshipDates');
}
/**
* @param \CRM_Queue_TaskContext $ctx
+ *
+ * @return bool
+ */
+ public static function updateRelationshipDates(CRM_Queue_TaskContext $ctx): bool {
+ CRM_Core_DAO::executeQuery('
+ UPDATE civicrm_relationship SET created_date = start_date, modified_date = start_date
+ WHERE start_date IS NOT NULL AND start_date > "1970-01-01"
+ ');
+ return TRUE;
+ }
+
+ /**
+ * @param \CRM_Queue_TaskContext $ctx
+ *
* @return bool
+ * @throws \API_Exception
+ * @throws \CRM_Core_Exception
+ * @throws \Civi\API\Exception\NotImplementedException
*/
public static function migrateCiviGrant(CRM_Queue_TaskContext $ctx): bool {
$civiGrantEnabled = in_array('CiviGrant', Civi::settings()->get('enable_components'), TRUE);
</html>
<add>2.2</add>
</field>
+ <field>
+ <name>created_date</name>
+ <type>timestamp</type>
+ <comment>Relationship created date.</comment>
+ <required>true</required>
+ <default>CURRENT_TIMESTAMP</default>
+ <add>5.47</add>
+ </field>
+ <field>
+ <name>modified_date</name>
+ <title>Relationship Modified Date</title>
+ <type>timestamp</type>
+ <required>true</required>
+ <comment>Relationship last modified.</comment>
+ <default>CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP</default>
+ <add>5.47</add>
+ <readonly>true</readonly>
+ </field>
<foreignKey>
<name>case_id</name>
<table>civicrm_case</table>