* @param array $records
* @return CRM_Core_DAO_CustomField[]
* @throws CRM_Core_Exception
- * @throws CiviCRM_API3_Exception
*/
- public static function writeRecords(array $records) {
+ public static function writeRecords(array $records): array {
$addedColumns = $sql = $customFields = $pre = $post = [];
foreach ($records as $index => $params) {
CRM_Utils_Hook::pre(empty($params['id']) ? 'create' : 'edit', 'CustomField', $params['id'] ?? NULL, $params);
* @return static[]
* @throws CRM_Core_Exception
*/
- public static function writeRecords(array $records) {
+ public static function writeRecords(array $records): array {
$results = [];
foreach ($records as $record) {
$results[] = static::writeRecord($record);
* name of the relevant table.
* @param array $cols
* Mixed array of columns to add or null (to check for the missing columns).
- *
- * @return bool
*/
- public function fixSchemaDifferencesFor($table, $cols = []) {
- if (empty($table)) {
- return FALSE;
+ public function fixSchemaDifferencesFor(string $table, array $cols = []): void {
+ if (!in_array($table, $this->tables, TRUE)) {
+ // Create the table if the log table does not exist and
+ // the table is in 'this->tables'. This latter array
+ // could have been altered by a hook if the site does not
+ // want to log a specific table.
+ return;
}
if (empty($this->logs[$table])) {
$this->createLogTableFor($table);
- return TRUE;
+ return;
}
if (empty($cols)) {
}
$this->resetSchemaCacheForTable("log_$table");
-
- return TRUE;
}
/**
$this->assertNotEmpty(CRM_Core_DAO::singleValueQuery("SHOW tables LIKE 'log_abcd'"));
}
+ /**
+ * Test that hooks removing tables from logging are respected during custom field add.
+ *
+ * During custom field save logging is only handled for the affected table.
+ * We need to make sure this respects hooks to remove from the logging set.
+ */
+ public function testLoggingHookIgnore(): void {
+ $this->hookClass->setHook('civicrm_alterLogTables', [$this, 'ignoreSillyName']);
+ Civi::settings()->set('logging', TRUE);
+ $this->createCustomGroupWithFieldOfType(['table_name' => 'silly_name']);
+ $this->assertEmpty(CRM_Core_DAO::singleValueQuery("SHOW tables LIKE 'log_silly_name'"));
+ }
+
+ /**
+ * Implement hook to cause our log table to be ignored.
+ *
+ * @param array $logTableSpec
+ */
+ public function ignoreSillyName(array &$logTableSpec): void {
+ unset($logTableSpec['silly_name']);
+ }
+
/**
* Test creating logging schema when database is in multilingual mode.
*/