? Pending

User tests: Successful: Unsuccessful:

avatar richard67
richard67
9 Aug 2021

Pull Request for Issue #35071 .

Summary of Changes

Add the attachments column to the mail template object when creating a new record with $db->insertObject in Joomla\CMS\Mail\MailTemplate::createTemplate.

As a column with data type TEXT, the attachments column of the #__mail_templates doesn't have a default value, see PR #27937 and PR #17860 and also https://stackoverflow.com/questions/3466872/why-cant-a-text-column-have-a-default-value-in-mysql for the reasons.

Therefore a property for that column has to exist in the object when creating a new record with $db->insertObject.

This pull request (PR) only fixes the SQL error reported by the issue. It does not add the ability to specify attachments when using Joomla\CMS\Mail\MailTemplate::createTemplate or Joomla\CMS\Mail\MailTemplate::updateTemplate.

This could and in my opinion should be done with a future PR with a suitable milestone, e.g. 4.1.

Testing Instructions

  1. On a clean, current 4.0-dev branch or latest nightly build or 4.0 RC 5, add the following code to the index.php of the Cassiopeia template as shown in the screenshot below the code:
use Joomla\CMS\Mail\MailTemplate;

$result = MailTemplate::createTemplate(
	'com_config.test_mail_' . date('Ymd_His'),
	'COM_CONFIG_SENDMAIL_SUBJECT',
	'COM_CONFIG_SENDMAIL_BODY',
	["sitename","method"]
);

echo $result ? 'Mail template created.' : 'creating mail template failed.';

j4-test-mail-template-create_1

  1. Go to the site (frontend).

Result: See section "Actual result BEFORE applying this Pull Request" below.

  1. Apply the patch of this PR.

  2. Go again to the site (frontend) or if still there reload the page.

Result: See 1st screenshot in section "Expected result AFTER applying this Pull Request" below.

  1. Check in database if the mail template record template has been created.

Result: See 2nd screenshot in section "Expected result AFTER applying this Pull Request" below.

Hint: The created mail template will not be shown in backend due to the way how mail templates work, as there is no language string for the dynamically created template_id. But this was necessary in order not to violate the primary key uniqueness.

  1. Check if editing other mail templates works as before.

Result: Editing mail templates works.

Actual result BEFORE applying this Pull Request

j4-test-mail-template-create_2

Expected result AFTER applying this Pull Request

Creating mail templates programmatically works:

j4-test-mail-template-create_3

With every page load a new record has been created:

j4-test-mail-template-create_4

Documentation Changes Required

None.

avatar richard67 richard67 - open - 9 Aug 2021
avatar richard67 richard67 - change - 9 Aug 2021
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 9 Aug 2021
Category Libraries
avatar richard67 richard67 - change - 9 Aug 2021
The description was changed
avatar richard67 richard67 - edited - 9 Aug 2021
avatar richard67 richard67 - change - 9 Aug 2021
The description was changed
avatar richard67 richard67 - edited - 9 Aug 2021
avatar richard67 richard67 - change - 9 Aug 2021
The description was changed
avatar richard67 richard67 - edited - 9 Aug 2021
avatar richard67 richard67 - change - 9 Aug 2021
The description was changed
avatar richard67 richard67 - edited - 9 Aug 2021
avatar richard67 richard67 - change - 9 Aug 2021
The description was changed
avatar richard67 richard67 - edited - 9 Aug 2021
avatar wilsonge wilsonge - change - 9 Aug 2021
Status Pending Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2021-08-09 10:39:46
Closed_By wilsonge
Labels Added: ?
avatar wilsonge wilsonge - close - 9 Aug 2021
avatar wilsonge wilsonge - merge - 9 Aug 2021
avatar wilsonge
wilsonge - comment - 9 Aug 2021

Thanks!

avatar richard67
richard67 - comment - 9 Aug 2021

Thanks

avatar N6REJ
N6REJ - comment - 9 Aug 2021

bit late but tested fine.

avatar garkell
garkell - comment - 23 Dec 2022

I know this is closed but shouldn't the createTemplate have the extension element included?


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/35074.

Add a Comment

Login with GitHub to post a comment