* @throws \CRM_Core_Exception
*/
public static function writeRecord(array $record): CRM_Core_DAO {
- $hook = empty($record['id']) ? 'create' : 'edit';
+ $op = empty($record['id']) ? 'create' : 'edit';
$className = CRM_Core_DAO_AllCoreTables::getCanonicalClassName(static::class);
if ($className === 'CRM_Core_DAO') {
throw new CRM_Core_Exception('Function writeRecord must be called on a subclass of CRM_Core_DAO');
}
$entityName = CRM_Core_DAO_AllCoreTables::getBriefName($className);
- \CRM_Utils_Hook::pre($hook, $entityName, $record['id'] ?? NULL, $record);
+ \CRM_Utils_Hook::pre($op, $entityName, $record['id'] ?? NULL, $record);
$instance = new $className();
// Ensure fields exist before attempting to write to them
$values = array_intersect_key($record, self::getSupportedFields());
$instance->copyValues($values);
$instance->save();
- \CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance);
+
+ if (!empty($record['custom']) && is_array($record['custom'])) {
+ CRM_Core_BAO_CustomValueTable::store($record['custom'], static::$_tableName, $instance->id, $op);
+ }
+
+ \CRM_Utils_Hook::post($op, $entityName, $instance->id, $instance);
return $instance;
}
}
$paymentParams['status_id'] = $params['status_id'] ?? NULL;
- CRM_Utils_Hook::pre($action, 'Pledge', $params['id'] ?? NULL, $params);
- $pledge = new CRM_Pledge_DAO_Pledge();
-
- // if pledge is complete update end date as current date
- if ($pledge->status_id == 1) {
- $pledge->end_date = date('Ymd');
- }
-
- $pledge->copyValues($params);
- $pledge->save();
- CRM_Utils_Hook::post($action, 'Pledge', $pledge->id, $pledge);
-
- // handle custom data.
- if (!empty($params['custom']) &&
- is_array($params['custom'])
- ) {
- CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_pledge', $pledge->id);
- }
+ $pledge = self::writeRecord($params);
// skip payment stuff in edit mode
if (empty($params['id']) || $isRecalculatePledgePayment) {