MessageTemplate API - Fix saving of templates with workflow_name sans workflow_id
authorTim Otten <totten@civicrm.org>
Fri, 1 Oct 2021 21:56:26 +0000 (14:56 -0700)
committerTim Otten <totten@civicrm.org>
Fri, 1 Oct 2021 21:56:26 +0000 (14:56 -0700)
commitd53da69a685c03a48128cd9eb439caf1ce027870
treeb5be127c73f3939a5af6814baa47c898136b3100
parent9d6c81e202caeb265316de8a3dd4d3d7cd89e158
MessageTemplate API - Fix saving of templates with workflow_name sans workflow_id

Overview
--------

This fixes a bug when saving (updating) a `MessageTemplate` record that
involves a `workflow_name` and no `workflow_id`. It is an alternative to #21674.

Steps to  reproduce
-------------------

Suppose you read a MessagTemplate with values:

```php
$values = ['workflow_name' => 'foo', 'workflow_id' => NULL, ...]
```

Then you save it back:

```php
civicrm_api4('MessageTemplate', 'update', [
  'values' => $values
]);
```

Before
------

The `update` raises an exception.

After
-----

The `update` works.
CRM/Core/BAO/MessageTemplate.php
tests/phpunit/api/v4/Entity/MessageTemplateTest.php [new file with mode: 0644]