*/
private static function _addWhereAdd(&$customGroupDAO, $entityType, $entityID = NULL, $allSubtypes = FALSE) {
$addSubtypeClause = FALSE;
+ // This function isn't really accessible with user data but since the string
+ // is not passed as a param to the query CRM_Core_DAO::escapeString seems like a harmless
+ // precaution.
+ $entityType = CRM_Core_DAO::escapeString($entityType);
switch ($entityType) {
case 'Contact':
}
break;
- case 'Case':
- case 'Location':
- case 'Address':
- case 'Activity':
- case 'Contribution':
- case 'Membership':
- case 'Participant':
+ default:
$customGroupDAO->whereAdd("extends IN ('$entityType')");
break;
}
}
}
+ /**
+ * Test correct creation of modified date triggers.
+ *
+ * Specifically we are testing that the contact table modified date and
+ * ONLY the contact table modified date is updated when the custom field is updated.
+ *
+ * (At point of writing this the modification was leaking to the mailing table).
+ */
+ public function testTriggers() {
+ $customGroup = $this->entityCustomGroupWithSingleFieldCreate('Contact', 'ContactTest....');
+ Civi::service('sql_triggers')->rebuild();
+ $log_table = CRM_Core_DAO::executeQuery("SHOW TRIGGERS WHERE `Trigger` LIKE 'civicrm_value_contact_{$customGroup['custom_group_id']}_after_insert%'");
+
+ while ($log_table->fetch()) {
+ $this->assertContains('UPDATE civicrm_contact SET modified_date = CURRENT_TIMESTAMP WHERE id = NEW.entity_id;', $log_table->Statement, "Contact modification update should be in the trigger :\n" . $log_table->Statement);
+ $this->assertNotContains('civicrm_mailing', $log_table->Statement, 'Contact field should not update mailing table');
+ $this->assertEquals(1, substr_count($log_table->Statement, 'SET modified_date'), 'Modified date should only be updated on one table (here it is contact)');
+ }
+ }
+
public function testAutoIncrementNonIdColumn() {
CRM_Core_DAO::executeQuery("CREATE TABLE `civicrm_test_table` (
test_id int(10) unsigned NOT NULL AUTO_INCREMENT,